@kawaiininja/logger 1.0.2 → 1.0.3
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/dist/index.d.ts +15 -0
- package/dist/index.js +49 -6
- package/package.json +3 -2
- package/publish-logger-major.bat +99 -0
- package/publish-logger-minor.bat +99 -0
- package/publish-logger-patch.bat +99 -0
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface LoggerOptions {
|
|
|
7
7
|
level?: string;
|
|
8
8
|
isDevelopment?: boolean;
|
|
9
9
|
colors?: Partial<Record<LogLevel, string>>;
|
|
10
|
+
stringifyObjects?: boolean;
|
|
10
11
|
}
|
|
11
12
|
type LogLevel = "debug" | "info" | "warn" | "error" | "off";
|
|
12
13
|
export declare class Logger {
|
|
@@ -15,6 +16,8 @@ export declare class Logger {
|
|
|
15
16
|
private currentLevel;
|
|
16
17
|
private isDevelopment;
|
|
17
18
|
private colors;
|
|
19
|
+
private stringifyObjects;
|
|
20
|
+
private timers;
|
|
18
21
|
constructor(options?: LoggerOptions);
|
|
19
22
|
private shouldLog;
|
|
20
23
|
private log;
|
|
@@ -22,6 +25,14 @@ export declare class Logger {
|
|
|
22
25
|
info(...args: any[]): void;
|
|
23
26
|
warn(...args: any[]): void;
|
|
24
27
|
error(...args: any[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Start a timer
|
|
30
|
+
*/
|
|
31
|
+
time(label: string, level?: LogLevel): void;
|
|
32
|
+
/**
|
|
33
|
+
* End a timer and log the duration
|
|
34
|
+
*/
|
|
35
|
+
timeEnd(label: string, level?: LogLevel): void;
|
|
25
36
|
/**
|
|
26
37
|
* Start a collapsible group
|
|
27
38
|
*/
|
|
@@ -34,5 +45,9 @@ export declare class Logger {
|
|
|
34
45
|
* Log data as a table
|
|
35
46
|
*/
|
|
36
47
|
table(data: any, level?: LogLevel): void;
|
|
48
|
+
/**
|
|
49
|
+
* Log an interactive object reference
|
|
50
|
+
*/
|
|
51
|
+
dir(obj: any, level?: LogLevel): void;
|
|
37
52
|
}
|
|
38
53
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Logger class for application logging
|
|
4
3
|
* Based on variant.v2/logger.util.js from frontend-libs
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
exports.Logger = void 0;
|
|
8
|
-
class Logger {
|
|
5
|
+
export class Logger {
|
|
9
6
|
constructor(options = {}) {
|
|
10
7
|
this.name = options.name || "App";
|
|
11
8
|
this.levels = { debug: 4, info: 3, warn: 2, error: 1, off: 0 };
|
|
@@ -15,6 +12,8 @@ class Logger {
|
|
|
15
12
|
? this.levels[requestedLevel]
|
|
16
13
|
: this.levels.error;
|
|
17
14
|
this.isDevelopment = options.isDevelopment ?? false;
|
|
15
|
+
this.stringifyObjects = options.stringifyObjects ?? false;
|
|
16
|
+
this.timers = new Map();
|
|
18
17
|
this.colors = {
|
|
19
18
|
debug: "#38BDF8",
|
|
20
19
|
info: "#10B981",
|
|
@@ -32,10 +31,23 @@ class Logger {
|
|
|
32
31
|
log(level, ...args) {
|
|
33
32
|
if (!this.shouldLog(level))
|
|
34
33
|
return;
|
|
34
|
+
const processedArgs = this.stringifyObjects
|
|
35
|
+
? args.map((arg) => {
|
|
36
|
+
if (typeof arg === "object" && arg !== null) {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.stringify(arg, null, 2);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return "[Circular]";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return arg;
|
|
45
|
+
})
|
|
46
|
+
: args;
|
|
35
47
|
const prefix = `%c[${this.name}] ${level.toUpperCase()}`;
|
|
36
48
|
const style = `color: ${this.colors[level]}; font-weight: bold;`;
|
|
37
49
|
const method = console[level] || console.log;
|
|
38
|
-
method(prefix, style, ...
|
|
50
|
+
method(prefix, style, ...processedArgs);
|
|
39
51
|
}
|
|
40
52
|
debug(...args) {
|
|
41
53
|
this.log("debug", ...args);
|
|
@@ -49,6 +61,30 @@ class Logger {
|
|
|
49
61
|
error(...args) {
|
|
50
62
|
this.log("error", ...args);
|
|
51
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Start a timer
|
|
66
|
+
*/
|
|
67
|
+
time(label, level = "debug") {
|
|
68
|
+
if (!this.shouldLog(level))
|
|
69
|
+
return;
|
|
70
|
+
this.timers.set(label, performance.now());
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* End a timer and log the duration
|
|
74
|
+
*/
|
|
75
|
+
timeEnd(label, level = "debug") {
|
|
76
|
+
if (!this.shouldLog(level))
|
|
77
|
+
return;
|
|
78
|
+
const start = this.timers.get(label);
|
|
79
|
+
if (start !== undefined) {
|
|
80
|
+
const duration = performance.now() - start;
|
|
81
|
+
console.log(`%c${label}: ${duration.toFixed(3)}ms`, "color: #10B981; font-weight: bold;");
|
|
82
|
+
this.timers.delete(label);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.warn(`Timer '${label}' was not started.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
52
88
|
/**
|
|
53
89
|
* Start a collapsible group
|
|
54
90
|
*/
|
|
@@ -71,5 +107,12 @@ class Logger {
|
|
|
71
107
|
return;
|
|
72
108
|
console.table(data);
|
|
73
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Log an interactive object reference
|
|
112
|
+
*/
|
|
113
|
+
dir(obj, level = "debug") {
|
|
114
|
+
if (!this.shouldLog(level))
|
|
115
|
+
return;
|
|
116
|
+
console.dir(obj);
|
|
117
|
+
}
|
|
74
118
|
}
|
|
75
|
-
exports.Logger = Logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kawaiininja/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Logger class for application logging",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"keywords": [
|
|
11
11
|
"logger",
|
|
12
12
|
"logging",
|
|
13
|
-
"
|
|
13
|
+
"javascript"
|
|
14
14
|
],
|
|
15
|
+
"type": "module",
|
|
15
16
|
"author": "",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"devDependencies": {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM Publish logger major version
|
|
3
|
+
REM 10/10 Pro Version: Login Check, Smart Revert, Git Sync
|
|
4
|
+
|
|
5
|
+
REM Check login status
|
|
6
|
+
echo [INFO] Checking npm login status...
|
|
7
|
+
call npm whoami >nul 2>&1
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo [WARN] Not logged in. Attempting login...
|
|
10
|
+
call npm login
|
|
11
|
+
if errorlevel 1 (
|
|
12
|
+
echo [ERROR] Login failed. Aborting.
|
|
13
|
+
pause
|
|
14
|
+
exit /b 1
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
cd /d "%~dp0"
|
|
19
|
+
if errorlevel 1 (
|
|
20
|
+
echo [ERROR] Could not find logger directory.
|
|
21
|
+
pause
|
|
22
|
+
exit /b 1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
echo.
|
|
26
|
+
echo ========================================
|
|
27
|
+
echo Publishing LOGGER MAJOR version
|
|
28
|
+
echo ========================================
|
|
29
|
+
echo.
|
|
30
|
+
|
|
31
|
+
REM Bump version
|
|
32
|
+
call npm version major
|
|
33
|
+
if errorlevel 1 (
|
|
34
|
+
echo [ERROR] Failed to bump version
|
|
35
|
+
REM cd ..
|
|
36
|
+
pause
|
|
37
|
+
exit /b 1
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
REM Build
|
|
41
|
+
echo.
|
|
42
|
+
echo [INFO] Building logger...
|
|
43
|
+
call npm run build
|
|
44
|
+
if errorlevel 1 (
|
|
45
|
+
echo [ERROR] Failed to build logger. Reverting...
|
|
46
|
+
call :Revert
|
|
47
|
+
REM cd ..
|
|
48
|
+
pause
|
|
49
|
+
exit /b 1
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
REM Publish
|
|
53
|
+
echo.
|
|
54
|
+
echo [INFO] Publishing to npm...
|
|
55
|
+
call npm publish --access public
|
|
56
|
+
if errorlevel 1 (
|
|
57
|
+
echo [ERROR] Failed to publish logger. Reverting...
|
|
58
|
+
call :Revert
|
|
59
|
+
REM cd ..
|
|
60
|
+
pause
|
|
61
|
+
exit /b 1
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
echo.
|
|
65
|
+
echo [INFO] Pushing changes to remote...
|
|
66
|
+
git push && git push --tags
|
|
67
|
+
if errorlevel 1 (
|
|
68
|
+
echo [WARN] Failed to push to remote. Please push manually.
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
REM cd ..
|
|
72
|
+
echo.
|
|
73
|
+
echo ========================================
|
|
74
|
+
echo [SUCCESS] Logger published and synced!
|
|
75
|
+
echo ========================================
|
|
76
|
+
echo.
|
|
77
|
+
pause
|
|
78
|
+
goto :EOF
|
|
79
|
+
|
|
80
|
+
:Revert
|
|
81
|
+
echo [INFO] Attempting to revert changes...
|
|
82
|
+
REM Get the current version from package.json
|
|
83
|
+
for /f "tokens=*" %%v in ('node -p "require('./package.json').version"') do set VERSION=%%v
|
|
84
|
+
|
|
85
|
+
REM Safety Check: Inspect last commit message
|
|
86
|
+
for /f "tokens=*" %%c in ('git log -1 --pretty^=%%s') do set LAST_MSG=%%c
|
|
87
|
+
|
|
88
|
+
REM Check if last commit matches the version (Standard npm version behavior)
|
|
89
|
+
if "%LAST_MSG%"=="%VERSION%" (
|
|
90
|
+
echo [INFO] Last commit matches version bump. Resetting...
|
|
91
|
+
git tag -d v%VERSION%
|
|
92
|
+
git reset --hard HEAD~1
|
|
93
|
+
echo [INFO] Version bump reverted successfully.
|
|
94
|
+
) else (
|
|
95
|
+
echo [WARN] Last commit '%LAST_MSG%' does not match version '%VERSION%'.
|
|
96
|
+
echo [WARN] Skipping hard reset to protect your data.
|
|
97
|
+
echo [WARN] Please check git status and revert manually if needed.
|
|
98
|
+
)
|
|
99
|
+
exit /b 0
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM Publish logger minor version
|
|
3
|
+
REM 10/10 Pro Version: Login Check, Smart Revert, Git Sync
|
|
4
|
+
|
|
5
|
+
REM Check login status
|
|
6
|
+
echo [INFO] Checking npm login status...
|
|
7
|
+
call npm whoami >nul 2>&1
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo [WARN] Not logged in. Attempting login...
|
|
10
|
+
call npm login
|
|
11
|
+
if errorlevel 1 (
|
|
12
|
+
echo [ERROR] Login failed. Aborting.
|
|
13
|
+
pause
|
|
14
|
+
exit /b 1
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
cd /d "%~dp0"
|
|
19
|
+
if errorlevel 1 (
|
|
20
|
+
echo [ERROR] Could not find logger directory.
|
|
21
|
+
pause
|
|
22
|
+
exit /b 1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
echo.
|
|
26
|
+
echo ========================================
|
|
27
|
+
echo Publishing LOGGER MINOR version
|
|
28
|
+
echo ========================================
|
|
29
|
+
echo.
|
|
30
|
+
|
|
31
|
+
REM Bump version
|
|
32
|
+
call npm version minor
|
|
33
|
+
if errorlevel 1 (
|
|
34
|
+
echo [ERROR] Failed to bump version
|
|
35
|
+
REM cd ..
|
|
36
|
+
pause
|
|
37
|
+
exit /b 1
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
REM Build
|
|
41
|
+
echo.
|
|
42
|
+
echo [INFO] Building logger...
|
|
43
|
+
call npm run build
|
|
44
|
+
if errorlevel 1 (
|
|
45
|
+
echo [ERROR] Failed to build logger. Reverting...
|
|
46
|
+
call :Revert
|
|
47
|
+
REM cd ..
|
|
48
|
+
pause
|
|
49
|
+
exit /b 1
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
REM Publish
|
|
53
|
+
echo.
|
|
54
|
+
echo [INFO] Publishing to npm...
|
|
55
|
+
call npm publish --access public
|
|
56
|
+
if errorlevel 1 (
|
|
57
|
+
echo [ERROR] Failed to publish logger. Reverting...
|
|
58
|
+
call :Revert
|
|
59
|
+
REM cd ..
|
|
60
|
+
pause
|
|
61
|
+
exit /b 1
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
echo.
|
|
65
|
+
echo [INFO] Pushing changes to remote...
|
|
66
|
+
git push && git push --tags
|
|
67
|
+
if errorlevel 1 (
|
|
68
|
+
echo [WARN] Failed to push to remote. Please push manually.
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
REM cd ..
|
|
72
|
+
echo.
|
|
73
|
+
echo ========================================
|
|
74
|
+
echo [SUCCESS] Logger published and synced!
|
|
75
|
+
echo ========================================
|
|
76
|
+
echo.
|
|
77
|
+
pause
|
|
78
|
+
goto :EOF
|
|
79
|
+
|
|
80
|
+
:Revert
|
|
81
|
+
echo [INFO] Attempting to revert changes...
|
|
82
|
+
REM Get the current version from package.json
|
|
83
|
+
for /f "tokens=*" %%v in ('node -p "require('./package.json').version"') do set VERSION=%%v
|
|
84
|
+
|
|
85
|
+
REM Safety Check: Inspect last commit message
|
|
86
|
+
for /f "tokens=*" %%c in ('git log -1 --pretty^=%%s') do set LAST_MSG=%%c
|
|
87
|
+
|
|
88
|
+
REM Check if last commit matches the version (Standard npm version behavior)
|
|
89
|
+
if "%LAST_MSG%"=="%VERSION%" (
|
|
90
|
+
echo [INFO] Last commit matches version bump. Resetting...
|
|
91
|
+
git tag -d v%VERSION%
|
|
92
|
+
git reset --hard HEAD~1
|
|
93
|
+
echo [INFO] Version bump reverted successfully.
|
|
94
|
+
) else (
|
|
95
|
+
echo [WARN] Last commit '%LAST_MSG%' does not match version '%VERSION%'.
|
|
96
|
+
echo [WARN] Skipping hard reset to protect your data.
|
|
97
|
+
echo [WARN] Please check git status and revert manually if needed.
|
|
98
|
+
)
|
|
99
|
+
exit /b 0
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM Publish logger patch version
|
|
3
|
+
REM 10/10 Pro Version: Login Check, Smart Revert, Git Sync
|
|
4
|
+
|
|
5
|
+
REM Check login status
|
|
6
|
+
echo [INFO] Checking npm login status...
|
|
7
|
+
call npm whoami >nul 2>&1
|
|
8
|
+
if errorlevel 1 (
|
|
9
|
+
echo [WARN] Not logged in. Attempting login...
|
|
10
|
+
call npm login
|
|
11
|
+
if errorlevel 1 (
|
|
12
|
+
echo [ERROR] Login failed. Aborting.
|
|
13
|
+
pause
|
|
14
|
+
exit /b 1
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
cd /d "%~dp0"
|
|
19
|
+
if errorlevel 1 (
|
|
20
|
+
echo [ERROR] Could not find logger directory.
|
|
21
|
+
pause
|
|
22
|
+
exit /b 1
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
echo.
|
|
26
|
+
echo ========================================
|
|
27
|
+
echo Publishing LOGGER PATCH version
|
|
28
|
+
echo ========================================
|
|
29
|
+
echo.
|
|
30
|
+
|
|
31
|
+
REM Bump version
|
|
32
|
+
call npm version patch
|
|
33
|
+
if errorlevel 1 (
|
|
34
|
+
echo [ERROR] Failed to bump version
|
|
35
|
+
REM cd ..
|
|
36
|
+
pause
|
|
37
|
+
exit /b 1
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
REM Build
|
|
41
|
+
echo.
|
|
42
|
+
echo [INFO] Building logger...
|
|
43
|
+
call npm run build
|
|
44
|
+
if errorlevel 1 (
|
|
45
|
+
echo [ERROR] Failed to build logger. Reverting...
|
|
46
|
+
call :Revert
|
|
47
|
+
REM cd ..
|
|
48
|
+
pause
|
|
49
|
+
exit /b 1
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
REM Publish
|
|
53
|
+
echo.
|
|
54
|
+
echo [INFO] Publishing to npm...
|
|
55
|
+
call npm publish --access public
|
|
56
|
+
if errorlevel 1 (
|
|
57
|
+
echo [ERROR] Failed to publish logger. Reverting...
|
|
58
|
+
call :Revert
|
|
59
|
+
REM cd ..
|
|
60
|
+
pause
|
|
61
|
+
exit /b 1
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
echo.
|
|
65
|
+
echo [INFO] Pushing changes to remote...
|
|
66
|
+
git push && git push --tags
|
|
67
|
+
if errorlevel 1 (
|
|
68
|
+
echo [WARN] Failed to push to remote. Please push manually.
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
REM cd ..
|
|
72
|
+
echo.
|
|
73
|
+
echo ========================================
|
|
74
|
+
echo [SUCCESS] Logger published and synced!
|
|
75
|
+
echo ========================================
|
|
76
|
+
echo.
|
|
77
|
+
pause
|
|
78
|
+
goto :EOF
|
|
79
|
+
|
|
80
|
+
:Revert
|
|
81
|
+
echo [INFO] Attempting to revert changes...
|
|
82
|
+
REM Get the current version from package.json
|
|
83
|
+
for /f "tokens=*" %%v in ('node -p "require('./package.json').version"') do set VERSION=%%v
|
|
84
|
+
|
|
85
|
+
REM Safety Check: Inspect last commit message
|
|
86
|
+
for /f "tokens=*" %%c in ('git log -1 --pretty^=%%s') do set LAST_MSG=%%c
|
|
87
|
+
|
|
88
|
+
REM Check if last commit matches the version (Standard npm version behavior)
|
|
89
|
+
if "%LAST_MSG%"=="%VERSION%" (
|
|
90
|
+
echo [INFO] Last commit matches version bump. Resetting...
|
|
91
|
+
git tag -d v%VERSION%
|
|
92
|
+
git reset --hard HEAD~1
|
|
93
|
+
echo [INFO] Version bump reverted successfully.
|
|
94
|
+
) else (
|
|
95
|
+
echo [WARN] Last commit '%LAST_MSG%' does not match version '%VERSION%'.
|
|
96
|
+
echo [WARN] Skipping hard reset to protect your data.
|
|
97
|
+
echo [WARN] Please check git status and revert manually if needed.
|
|
98
|
+
)
|
|
99
|
+
exit /b 0
|