@crimsonsunset/jsg-logger 1.1.2 → 1.1.4
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 +5 -5
- package/config/component-schemes.js +1 -1
- package/config/config-manager.js +7 -2
- package/config/default-config.json +1 -1
- package/docs/roadmap.md +1 -0
- package/examples/advanced-config.json +1 -1
- package/formatters/browser-formatter.js +1 -1
- package/formatters/cli-formatter.js +32 -21
- package/formatters/server-formatter.js +1 -1
- package/index.js +23 -23
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -442,11 +442,11 @@ logger.controls.addFileOverride('src/popup.js', { // Debug popup
|
|
|
442
442
|
In browser environments, runtime controls are available globally:
|
|
443
443
|
|
|
444
444
|
```javascript
|
|
445
|
-
// Available as window.
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
445
|
+
// Available as window.JSG_Logger
|
|
446
|
+
JSG_Logger.enableDebugMode();
|
|
447
|
+
JSG_Logger.setDisplayOption('level', true);
|
|
448
|
+
JSG_Logger.addFileOverride('src/popup.js', { level: 'trace' });
|
|
449
|
+
JSG_Logger.getStats();
|
|
450
450
|
```
|
|
451
451
|
|
|
452
452
|
## ⚠️ **Disclaimer**
|
package/config/config-manager.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configuration Manager for
|
|
2
|
+
* Configuration Manager for JSG Logger
|
|
3
3
|
* Handles loading, merging, and validation of logger configurations
|
|
4
4
|
* Implements smart level resolution and file override system
|
|
5
5
|
*/
|
|
@@ -126,6 +126,11 @@ export class ConfigManager {
|
|
|
126
126
|
* @private
|
|
127
127
|
*/
|
|
128
128
|
async _loadConfigNode(path) {
|
|
129
|
+
// Only use Node.js APIs when actually in Node.js environment
|
|
130
|
+
if (typeof process === 'undefined' || !process.versions || !process.versions.node) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
129
134
|
try {
|
|
130
135
|
// Try dynamic import first (works with ES modules)
|
|
131
136
|
const module = await import(path, { assert: { type: 'json' } });
|
|
@@ -489,7 +494,7 @@ export class ConfigManager {
|
|
|
489
494
|
* @returns {string} Project name
|
|
490
495
|
*/
|
|
491
496
|
getProjectName() {
|
|
492
|
-
return this.config.projectName || '
|
|
497
|
+
return this.config.projectName || 'JSG Logger';
|
|
493
498
|
}
|
|
494
499
|
|
|
495
500
|
/**
|
package/docs/roadmap.md
CHANGED
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
- [ ] **Performance Monitoring** - Log performance metrics
|
|
116
116
|
- [ ] **Export Utilities** - Save logs to file formats
|
|
117
117
|
- [ ] **Integration Guides** - Framework-specific examples
|
|
118
|
+
- [ ] **Restore pino-pretty Support** - Add back full pino-pretty formatter with proper browser/Node.js environment detection to avoid bundling conflicts
|
|
118
119
|
|
|
119
120
|
---
|
|
120
121
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CLI/Terminal Formatter for
|
|
2
|
+
* CLI/Terminal Formatter for JSG Logger
|
|
3
3
|
* Uses pino-colada for beautiful terminal output with fallbacks
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { COMPONENT_SCHEME, LEVEL_SCHEME } from '../config/component-schemes.js';
|
|
7
7
|
import pinoColada from 'pino-colada';
|
|
8
|
-
|
|
8
|
+
// Note: pino-pretty imported conditionally to avoid browser bundle issues
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Create CLI formatter using pino-colada or pino-pretty
|
|
@@ -18,28 +18,39 @@ export const createCLIFormatter = () => {
|
|
|
18
18
|
colada.pipe(process.stdout);
|
|
19
19
|
return colada;
|
|
20
20
|
} catch (error) {
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
// Ultimate fallback - basic formatted output (works in all environments)
|
|
22
|
+
return {
|
|
23
|
+
write: (chunk) => {
|
|
24
|
+
try {
|
|
25
|
+
const log = JSON.parse(chunk);
|
|
26
|
+
|
|
27
|
+
// Get component info
|
|
27
28
|
const component = COMPONENT_SCHEME[log.name] || COMPONENT_SCHEME['cacp'];
|
|
28
29
|
const componentName = component.name.toUpperCase().replace(/([a-z])([A-Z])/g, '$1-$2');
|
|
30
|
+
|
|
31
|
+
// Get level info
|
|
29
32
|
const level = LEVEL_SCHEME[log.level] || LEVEL_SCHEME[30];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
// Format timestamp like pino-pretty
|
|
35
|
+
const timestamp = new Date(log.time).toLocaleTimeString('en-US', {
|
|
36
|
+
hour12: false,
|
|
37
|
+
hour: '2-digit',
|
|
38
|
+
minute: '2-digit',
|
|
39
|
+
second: '2-digit',
|
|
40
|
+
fractionalSecondDigits: 1
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Format message like pino-pretty messageFormat
|
|
44
|
+
const message = `${level.emoji} [${componentName}] ${log.msg || ''}`;
|
|
45
|
+
|
|
46
|
+
// Output with timestamp prefix
|
|
47
|
+
console.log(`${timestamp} ${message}`);
|
|
48
|
+
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// Raw fallback
|
|
51
|
+
console.log(chunk);
|
|
36
52
|
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Ultimate fallback - basic JSON
|
|
40
|
-
return {
|
|
41
|
-
write: (data) => console.log(data)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
44
55
|
}
|
|
45
56
|
};
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {LogStore} from './stores/log-store.js';
|
|
|
17
17
|
* Main Logger Class
|
|
18
18
|
* Manages logger instances and provides the public API
|
|
19
19
|
*/
|
|
20
|
-
class
|
|
20
|
+
class JSGLogger {
|
|
21
21
|
// Static singleton instance
|
|
22
22
|
static _instance = null;
|
|
23
23
|
|
|
@@ -32,27 +32,27 @@ class CACPLogger {
|
|
|
32
32
|
/**
|
|
33
33
|
* Get singleton instance with auto-initialization
|
|
34
34
|
* @param {Object} options - Initialization options (only used on first call)
|
|
35
|
-
* @returns {Promise<
|
|
35
|
+
* @returns {Promise<JSGLogger>} Singleton logger instance
|
|
36
36
|
*/
|
|
37
37
|
static async getInstance(options = {}) {
|
|
38
|
-
if (!
|
|
39
|
-
|
|
40
|
-
await
|
|
38
|
+
if (!JSGLogger._instance) {
|
|
39
|
+
JSGLogger._instance = new JSGLogger();
|
|
40
|
+
await JSGLogger._instance.init(options);
|
|
41
41
|
}
|
|
42
|
-
return
|
|
42
|
+
return JSGLogger._instance;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Get singleton instance synchronously (for environments without async support)
|
|
47
47
|
* @param {Object} options - Initialization options (only used on first call)
|
|
48
|
-
* @returns {
|
|
48
|
+
* @returns {JSGLogger} Singleton logger instance
|
|
49
49
|
*/
|
|
50
50
|
static getInstanceSync(options = {}) {
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (!JSGLogger._instance) {
|
|
52
|
+
JSGLogger._instance = new JSGLogger();
|
|
53
|
+
JSGLogger._instance.initSync(options);
|
|
54
54
|
}
|
|
55
|
-
return
|
|
55
|
+
return JSGLogger._instance;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -87,7 +87,7 @@ class CACPLogger {
|
|
|
87
87
|
|
|
88
88
|
// Log initialization success
|
|
89
89
|
if (this.loggers.cacp) {
|
|
90
|
-
this.loggers.cacp.info('
|
|
90
|
+
this.loggers.cacp.info('JSG Logger initialized', {
|
|
91
91
|
environment: this.environment,
|
|
92
92
|
components: components.length,
|
|
93
93
|
projectName: configManager.getProjectName(),
|
|
@@ -98,7 +98,7 @@ class CACPLogger {
|
|
|
98
98
|
|
|
99
99
|
return this.getLoggerExports();
|
|
100
100
|
} catch (error) {
|
|
101
|
-
console.error('
|
|
101
|
+
console.error('JSG Logger initialization failed:', error);
|
|
102
102
|
// Return minimal fallback logger
|
|
103
103
|
return this.createFallbackLogger();
|
|
104
104
|
}
|
|
@@ -130,7 +130,7 @@ class CACPLogger {
|
|
|
130
130
|
|
|
131
131
|
// Log initialization success
|
|
132
132
|
if (this.loggers.cacp) {
|
|
133
|
-
this.loggers.cacp.info('
|
|
133
|
+
this.loggers.cacp.info('JSG Logger initialized (sync)', {
|
|
134
134
|
environment: this.environment,
|
|
135
135
|
components: components.length,
|
|
136
136
|
projectName: configManager.getProjectName(),
|
|
@@ -141,7 +141,7 @@ class CACPLogger {
|
|
|
141
141
|
|
|
142
142
|
return this.getLoggerExports();
|
|
143
143
|
} catch (error) {
|
|
144
|
-
console.error('
|
|
144
|
+
console.error('JSG Logger sync initialization failed:', error);
|
|
145
145
|
// Return minimal fallback logger
|
|
146
146
|
return this.createFallbackLogger();
|
|
147
147
|
}
|
|
@@ -514,7 +514,7 @@ class CACPLogger {
|
|
|
514
514
|
*/
|
|
515
515
|
static async logPerformance(operation, startTime, component = 'performance') {
|
|
516
516
|
try {
|
|
517
|
-
const instance = await
|
|
517
|
+
const instance = await JSGLogger.getInstance();
|
|
518
518
|
const logger = instance.getComponent(component);
|
|
519
519
|
const duration = performance.now() - startTime;
|
|
520
520
|
|
|
@@ -537,7 +537,7 @@ class CACPLogger {
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// Create singleton instance
|
|
540
|
-
const logger = new
|
|
540
|
+
const logger = new JSGLogger();
|
|
541
541
|
|
|
542
542
|
// Initialize synchronously with default config for immediate use
|
|
543
543
|
// (Chrome extensions and other environments that don't support top-level await)
|
|
@@ -545,15 +545,15 @@ const enhancedLoggers = logger.initSync();
|
|
|
545
545
|
|
|
546
546
|
// Make runtime controls available globally in browser for debugging
|
|
547
547
|
if (isBrowser() && typeof window !== 'undefined') {
|
|
548
|
-
window.
|
|
548
|
+
window.JSG_Logger = enhancedLoggers.controls;
|
|
549
549
|
}
|
|
550
550
|
|
|
551
551
|
// Add static methods to the enhanced loggers for convenience
|
|
552
|
-
enhancedLoggers.getInstance =
|
|
553
|
-
enhancedLoggers.getInstanceSync =
|
|
554
|
-
enhancedLoggers.logPerformance =
|
|
555
|
-
enhancedLoggers.
|
|
552
|
+
enhancedLoggers.getInstance = JSGLogger.getInstance;
|
|
553
|
+
enhancedLoggers.getInstanceSync = JSGLogger.getInstanceSync;
|
|
554
|
+
enhancedLoggers.logPerformance = JSGLogger.logPerformance;
|
|
555
|
+
enhancedLoggers.JSGLogger = JSGLogger;
|
|
556
556
|
|
|
557
557
|
// Export both the initialized loggers and the class for advanced usage
|
|
558
558
|
export default enhancedLoggers;
|
|
559
|
-
export {logger as
|
|
559
|
+
export {logger as JSGLogger};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crimsonsunset/jsg-logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "JSG Logger - Multi-environment logger with smart detection, file-level overrides, and beautiful console formatting",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"pino": "^9.7.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"pino-colada": "^2.2.2"
|
|
34
|
-
"pino-pretty": "^13.1.1"
|
|
33
|
+
"pino-colada": "^2.2.2"
|
|
35
34
|
},
|
|
36
35
|
"peerDependencies": {
|
|
37
36
|
"pino-colada": "^2.2.2"
|