-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
154 lines (133 loc) · 11.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Datasource Proxy log formatter service</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Ubuntu+Mono:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<style>
body {
font-family: 'Ubuntu Mono', monospace;
font-size: 14px;
}
</style>
</head>
<body>
<a class="github-fork-ribbon" href="https://github.com/polarfish/datasource-proxy-log-formatter"
data-ribbon="Fork me on GitHub"
title="Fork me on GitHub">Fork me on GitHub</a>
<div class="container-fluid d-flex flex-column vh-100 overflow-hidden">
<div class="flex-shrink-0">
<h1>Datasource Proxy log formatter service</h1>
</div>
<div class="row flex-grow-1 overflow-hidden">
<div class="col-4 mh-100 overflow-auto py-2">
<button type="button" id="formatLog" class="btn btn-danger">Format Log</button>
<button type="button" id="loadDemoLog" class="btn btn-info">Demo Log</button>
<button type="button" id="formatSql" class="btn btn-danger">Format SQL</button>
<button type="button" id="loadDemoSql" class="btn btn-info">Demo SQL</button>
<br/>
<br/>
<textarea class="form-control h-75" id="logEntries"
spellcheck="false"
placeholder="Paste one or more SLF4JQueryLoggingListener json log entries"></textarea>
</div>
<div class='col mh-100 overflow-auto'>
<div class='row flex-grow-1'>
<div class="col mh-100 overflow-auto py-2" id="sql" style="font-size: 14px;">
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/sql-formatter.min.js"></script>
<script>
let formatLogButton = document.getElementById("formatLog");
let formatSqlButton = document.getElementById("formatSql");
let loadDemoLog = document.getElementById("loadDemoLog");
let loadDemoSql = document.getElementById("loadDemoSql");
let logEntriesTextarea = document.getElementById("logEntries");
let sqlCodeBlock = document.getElementById("sql");
formatLogButton.addEventListener("click", function (e) {
let input = logEntriesTextarea.value;
if (!input || !input.includes("SLF4JQueryLoggingListener")) {
return;
}
let formattedLogInnerHtml = "";
input.split("\n").forEach(line => {
if (!line.includes("SLF4JQueryLoggingListener")) {
return;
}
let match = line.match("([{]{1}.*[}]{1})");
if (!match) {
alert("Bad input");
return;
}
let logEntriesJson = JSON.parse(match[0]);
let query;
for (let i = 0; i < logEntriesJson.query.length; i++) {
const params = logEntriesJson.params[i];
query = logEntriesJson.query[i];
query = query.replaceAll("?", "===placeholder===")
while (params && params.length > 0) {
let param = params.shift();
query = query.replace("===placeholder===", formatParameter(param));
}
let formattedSql;
try {
formattedSql = sqlFormatter.format(query, {
language: "sql",
uppercase: true
});
} catch (e) {
formattedLogInnerHtml += `<code class="language-sql">-- ERROR: SQL formatting failed ${e}</code><br>`;
return;
}
formattedLogInnerHtml += `<code class="language-sql">
-- connection: ${logEntriesJson.connection}
-- time: ${logEntriesJson.time}
-- success: ${logEntriesJson.success}
-- type: ${logEntriesJson.type}
-- batch: ${logEntriesJson.batch}
-- batchSize: ${logEntriesJson.batchSize} ${createBatchCounter(i, logEntriesJson.batchSize)}
-- querySize: ${logEntriesJson.querySize}
${formattedSql}
</code>
`;
}
});
sqlCodeBlock.innerHTML = "<pre>" + formattedLogInnerHtml + "</pre>";
hljs.highlightAll();
});
formatSqlButton.addEventListener("click", function (e) {
let input = logEntriesTextarea.value;
if (!input || input.includes("SLF4JQueryLoggingListener")) {
return;
}
let formattedSql = sqlFormatter.format(logEntriesTextarea.value, {
language: "sql",
uppercase: true
});
sqlCodeBlock.innerHTML = `<pre><code class="language-sql">${formattedSql}</code></pre>`;
hljs.highlightAll();
});
const createBatchCounter = (index, batchSize) => batchSize > 1 ? ("(" + (index + 1) + "/" + batchSize + ")") : "";
const escapeHtml = (unsafe) => unsafe.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''')
const formatParameter = param => param !== "" && Number.isInteger(Number(param)) ? param : ("'" + escapeHtml(param) + "'")
loadDemoLog.addEventListener('click', function () {
logEntriesTextarea.value =
`2021-10-14 15:29:52.409 DEBUG [employee-service,,,] 90994 --- [ main] n.t.d.l.l.SLF4JQueryLoggingListener : {"name":"dataSource-proxy", "connection":121, "time":2, "success":true, "type":"Prepared", "batch":false, "querySize":1, "batchSize":0, "query":["SELECT * FROM employees employees0_ WHERE employees0_.id = ?"], "params":[["e98a53a5-9ca2-4c8b-8ecd-9bcb076e02c0"]]}
2021-10-14 15:29:53.662 DEBUG [employee-service,,,] 86163 --- [ main] n.t.d.l.l.SLF4JQueryLoggingListener : {"name":"dataSource-proxy", "connection":122, "time":17, "success":true, "type":"Prepared", "batch":false, "querySize":1, "batchSize":0, "query":["select * from employees employees0_ where (employees0_.department=? and (employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream is null or employees0_.stream=? or (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream=?)) or employees0_.department=? and (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream is null or employees0_.stream=? or (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream=?)) or employees0_.department=? and (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream is null or employees0_.stream=? or (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream=?)) or employees0_.department=? and (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream is null or employees0_.stream=? or (employees0_.relation_id=? or employees0_.relation_id=? or employees0_.relation_id=?) and (employees0_.stream=?))) and (employees0_.status=? or employees0_.status=? or employees0_.status=? or employees0_.status=? or employees0_.status=? or employees0_.status=? or employees0_.status=? or employees0_.status=?) order by employees0_.start_date desc, employees0_.created_at desc limit ?"], "params":[["RnD","7c1e621fef6f4756bed27a53e97922b3","381e431f1e2346dda92f13115b4149de","","7c1e621fef6f4756bed27a53e97922b3","d60df6614cc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","Neo","Sales","8w32f6618bc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","d60df6614cc946e594fd084e20ace081","c4rtf6614cc946e594fd084e20ace081","","7c1e621fef6f4756bed27a53e97922b3","d60df6614cc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","Neo","Logistics","980df6618bc946e594fd084e20ace081","800df6618bc946e594fd084e20ace081","8w32f6618bc946e594fd084e20ace081","8w32f6618bc946e594fd084e20ace092","8b1e622fef7f4756ded27a53e98922a4","d60df6614cc946e594fd084e20ace081","c4rtf6614cc946e594fd084e20ace081","u4rtf6er4cc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922b5","","7c1e621fef6f4756bed27a53e97922b3","d60df6614cc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","Neo","Marketing","980df6618bc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","d60df6614cc946e594fd084e20ace081","","7c1e621fef6f4756bed27a53e97922b3","d60df6614cc946e594fd084e20ace081","8b1e622fef7f4756ded27a53e98922a4","Neo","ENTERED","WAITING_ONBOARDING","ONBOARDED","READY","ACKNOWLEDGED","ACTIVE","RESIGNED","TERMINATED","10"]]}`;
});
loadDemoSql.addEventListener('click', function () {
logEntriesTextarea.value =
`SELECT * FROM employees employees0_ WHERE (employees0_.department = 'RnD' AND (employees0_.relation_id = '7c1e621fef6f4756bed27a53e97922b3' OR employees0_.relation_id = '381e431f1e2346dda92f13115b4149de') AND (employees0_.stream IS NULL OR employees0_.stream = '' OR (employees0_.relation_id = '7c1e621fef6f4756bed27a53e97922b3' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4') AND (employees0_.stream = 'Neo')) OR employees0_.department = 'Sales' AND (employees0_.relation_id = '8w32f6618bc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = 'c4rtf6614cc946e594fd084e20ace081') AND (employees0_.stream IS NULL OR employees0_.stream = '' OR (employees0_.relation_id = '7c1e621fef6f4756bed27a53e97922b3' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4') AND (employees0_.stream = 'Neo')) OR employees0_.department = 'Logistics' AND (employees0_.relation_id = '980df6618bc946e594fd084e20ace081' OR employees0_.relation_id = '800df6618bc946e594fd084e20ace081' OR employees0_.relation_id = '8w32f6618bc946e594fd084e20ace081' OR employees0_.relation_id = '8w32f6618bc946e594fd084e20ace092' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = 'c4rtf6614cc946e594fd084e20ace081' OR employees0_.relation_id = 'u4rtf6er4cc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922b5') AND (employees0_.stream IS NULL OR employees0_.stream = '' OR (employees0_.relation_id = '7c1e621fef6f4756bed27a53e97922b3' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4') AND (employees0_.stream = 'Neo')) OR employees0_.department = 'Marketing' AND (employees0_.relation_id = '980df6618bc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081') AND (employees0_.stream IS NULL OR employees0_.stream = '' OR (employees0_.relation_id = '7c1e621fef6f4756bed27a53e97922b3' OR employees0_.relation_id = 'd60df6614cc946e594fd084e20ace081' OR employees0_.relation_id = '8b1e622fef7f4756ded27a53e98922a4') AND (employees0_.stream = 'Neo'))) AND (employees0_.status = 'ENTERED' OR employees0_.status = 'WAITING_ONBOARDING' OR employees0_.status = 'ONBOARDED' OR employees0_.status = 'READY' OR employees0_.status = 'ACKNOWLEDGED' OR employees0_.status = 'ACTIVE' OR employees0_.status = 'RESIGNED' OR employees0_.status = 'TERMINATED') ORDER BY employees0_.start_date desc, employees0_.created_at desc LIMIT 10;`;
});
</script>
</html>