@viplance/nestjs-logger 0.4.3 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/nestjs-logger.heic +0 -0
- package/package.json +1 -1
- package/public/index.html +5 -0
- package/public/scripts/details-popup.js +77 -6
- package/public/scripts/local-storage.js +23 -0
- package/public/scripts/ws.js +11 -6
package/README.md
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@viplance/nestjs-logger)
|
|
5
5
|
[](https://github.com/viplance/nestjs-logger)
|
|
6
6
|
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://raw.githubusercontent.com/viplance/nestjs-logger/refs/heads/main/nestjs-logger.heic" width="100%" title="NestJS logger">
|
|
9
|
+
</p>
|
|
10
|
+
|
|
7
11
|
### Installation
|
|
8
12
|
1. Install the package `npm i @viplance/nestjs-logger`<br />
|
|
9
13
|
2. Import the module in app.module.ts<br />
|
|
Binary file
|
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
+
const popup = document.getElementById('popup');
|
|
2
|
+
|
|
1
3
|
function showLogDetails(log) {
|
|
2
|
-
const popup = document.getElementById(`popup`);
|
|
3
4
|
const context = getObject(log.context);
|
|
4
5
|
const breadcrumbs = getObject(log.breadcrumbs);
|
|
5
6
|
|
|
7
|
+
// Restore position from LocalStorage
|
|
8
|
+
const savedLeft = getLs('popupLeft');
|
|
9
|
+
if (savedLeft) {
|
|
10
|
+
popup.style.left = savedLeft;
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
const timeInfo =
|
|
7
14
|
log.updatedAt === log.createdAt
|
|
8
15
|
? getDate(log.updatedAt)
|
|
9
16
|
: `Updated: ${getDate(
|
|
10
|
-
log.updatedAt
|
|
17
|
+
log.updatedAt,
|
|
11
18
|
)}. First seen: ${getDate(log.createdAt)}`;
|
|
12
19
|
|
|
13
20
|
popup.innerHTML = `
|
|
21
|
+
<div id="drag-handle" style="margin: -2rem -2rem 1rem -2rem; height: 1.5rem; background-color: #f1f1f1; border-bottom: 1px solid #ddd; cursor: grab; display: flex; align-items: center; justify-content: center;" title="Drag to move">
|
|
22
|
+
<div style="width: 50px; height: 5px; background-color: #ccc; border-radius: 5px;"></div>
|
|
23
|
+
</div>
|
|
14
24
|
<div class="content center">
|
|
15
25
|
<div class="container">
|
|
16
26
|
<h2 class="popup-title ${log.type}">${log.type}: ${log.message} (${
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
log.count
|
|
28
|
+
})</h2>
|
|
19
29
|
<div class="mt-05">${timeInfo}</div>
|
|
20
30
|
${
|
|
21
31
|
log.trace
|
|
@@ -48,9 +58,50 @@ function showLogDetails(log) {
|
|
|
48
58
|
}')">Delete</button>
|
|
49
59
|
</div>
|
|
50
60
|
</div>
|
|
51
|
-
|
|
61
|
+
</div>`;
|
|
52
62
|
|
|
53
63
|
popup.style.display = 'block';
|
|
64
|
+
|
|
65
|
+
const left = parseFloat(getLs('popupLeft')) || 0;
|
|
66
|
+
|
|
67
|
+
setPopupLeft(left);
|
|
68
|
+
|
|
69
|
+
// Drag'n'Drop logic
|
|
70
|
+
const handle = document.getElementById('drag-handle');
|
|
71
|
+
|
|
72
|
+
if (handle) {
|
|
73
|
+
handle.onmousedown = function (e) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
|
|
76
|
+
const startX = e.clientX;
|
|
77
|
+
const rect = popup.getBoundingClientRect();
|
|
78
|
+
const startLeft = rect.left;
|
|
79
|
+
|
|
80
|
+
handle.style.cursor = 'move';
|
|
81
|
+
document.body.style.cursor = 'move';
|
|
82
|
+
|
|
83
|
+
function onMouseMove(e) {
|
|
84
|
+
const dx = e.clientX - startX;
|
|
85
|
+
const left = startLeft + dx;
|
|
86
|
+
|
|
87
|
+
setPopupLeft(left);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onMouseUp() {
|
|
91
|
+
document.removeEventListener('mousemove', onMouseMove);
|
|
92
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
93
|
+
|
|
94
|
+
handle.style.cursor = 'grab';
|
|
95
|
+
document.body.style.cursor = 'default';
|
|
96
|
+
|
|
97
|
+
// Remember position
|
|
98
|
+
setLs('popupLeft', popup.style.left);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
document.addEventListener('mousemove', onMouseMove);
|
|
102
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
54
105
|
}
|
|
55
106
|
|
|
56
107
|
function getObject(context) {
|
|
@@ -66,6 +117,26 @@ function getTrace(trace) {
|
|
|
66
117
|
}
|
|
67
118
|
|
|
68
119
|
function closePopup() {
|
|
69
|
-
const popup = document.getElementById(`popup`);
|
|
70
120
|
popup.style.display = 'none';
|
|
71
121
|
}
|
|
122
|
+
|
|
123
|
+
function setPopupLeft(left) {
|
|
124
|
+
if (popup?.style.display === 'block') {
|
|
125
|
+
if (left < 0) {
|
|
126
|
+
left = 0;
|
|
127
|
+
}
|
|
128
|
+
const popupWidth = popup.offsetWidth;
|
|
129
|
+
if (left > window.innerWidth - popupWidth) {
|
|
130
|
+
left = window.innerWidth - popupWidth;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
popup.style.left = `${left}px`;
|
|
134
|
+
setLs('popupLeft', popup.style.left);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
window.addEventListener('resize', () => {
|
|
139
|
+
const left = parseFloat(getLs('popupLeft')) || 0;
|
|
140
|
+
|
|
141
|
+
setPopupLeft(left);
|
|
142
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const LS_KEY = 'nestjs-logger';
|
|
2
|
+
|
|
3
|
+
function getLs(propertyName) {
|
|
4
|
+
const item = localStorage.getItem(LS_KEY);
|
|
5
|
+
|
|
6
|
+
if (!item) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return JSON.parse(item)[propertyName];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function setLs(propertyName, value) {
|
|
14
|
+
const item = localStorage.getItem(LS_KEY);
|
|
15
|
+
|
|
16
|
+
if (!item) {
|
|
17
|
+
localStorage.setItem(LS_KEY, JSON.stringify({}));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ls = JSON.parse(item);
|
|
21
|
+
ls[propertyName] = value;
|
|
22
|
+
localStorage.setItem(LS_KEY, JSON.stringify(ls));
|
|
23
|
+
}
|
package/public/scripts/ws.js
CHANGED
|
@@ -8,21 +8,26 @@ async function connectWebSocket() {
|
|
|
8
8
|
const res = await fetch(`${origin}${pathname}settings${search}`);
|
|
9
9
|
|
|
10
10
|
if (!res.ok) {
|
|
11
|
-
alert(
|
|
11
|
+
alert(
|
|
12
|
+
'An error occurred while fetching settings. Check the `key` url parameter.'
|
|
13
|
+
);
|
|
12
14
|
return;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
const settings = await res.json();
|
|
16
18
|
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
+
if (!!settings.websocket) {
|
|
20
|
+
document.getElementById('refresh').style.display = 'none';
|
|
21
|
+
document.getElementById('freeze').style.display = 'block';
|
|
22
|
+
} else {
|
|
19
23
|
document.getElementById('refresh').style.display = 'block';
|
|
24
|
+
document.getElementById('freeze').style.display = 'none';
|
|
25
|
+
getLogs();
|
|
26
|
+
return;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
document.getElementById('freeze').style.display = 'block';
|
|
23
|
-
|
|
24
29
|
if (!settings.websocket?.port) {
|
|
25
|
-
alert('WebSocket port is not configured.');
|
|
30
|
+
alert('WebSocket port is not configured properly.');
|
|
26
31
|
return;
|
|
27
32
|
}
|
|
28
33
|
|