@wsxjs/wsx-logger 0.0.24 → 0.0.25

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @wsxjs/wsx-logger
2
2
 
3
- Browser-optimized logging utility for WSXJS, powered by [loglevel](https://github.com/pimterry/loglevel).
3
+ Browser-optimized logging utility for WSXJS. Pure native browser implementation with zero dependencies.
4
4
 
5
5
  ## Installation
6
6
 
@@ -42,18 +42,17 @@ const logger = createLoggerWithConfig({
42
42
  });
43
43
  ```
44
44
 
45
- ### Advanced Usage with Loglevel
45
+ ### Advanced Usage
46
46
 
47
47
  ```typescript
48
- import { createLogger, type LoglevelLogger } from "@wsxjs/wsx-logger";
48
+ import { createLogger } from "@wsxjs/wsx-logger";
49
49
 
50
- const wsxLogger = createLogger("MyComponent");
51
- const loglevelLogger = wsxLogger.getLoglevelLogger(); // Access underlying loglevel logger
50
+ const logger = createLogger("MyComponent");
52
51
 
53
- // Use loglevel's advanced features
54
- loglevelLogger.setLevel("warn");
55
- const currentLevel = wsxLogger.getLevel();
56
- wsxLogger.setLevel("debug");
52
+ // Dynamic log level control
53
+ logger.setLevel("warn");
54
+ const currentLevel = logger.getLevel();
55
+ logger.setLevel("debug");
57
56
  ```
58
57
 
59
58
  ## Configuration
@@ -74,22 +73,24 @@ wsxLogger.setLevel("debug");
74
73
 
75
74
  ## Features
76
75
 
77
- - ✅ Browser-optimized with loglevel (~1KB)
78
- - ✅ Zero dependencies (loglevel is the only dependency)
79
- - ✅ Compatible with WSXJS core logger interface
80
- - ✅ TypeScript support
81
- - ✅ Environment-aware configuration
82
- - ✅ Component-specific loggers
83
- - ✅ Dynamic log level control
84
- - ✅ Production-ready (automatically reduces verbosity in production)
85
-
86
- ## Why Loglevel?
87
-
88
- - **Lightweight**: Only ~1KB minified
89
- - **Browser-first**: Designed specifically for browser environments
90
- - **No Node.js dependencies**: Pure browser implementation
91
- - **Performance**: Minimal overhead, uses native console methods
92
- - **Flexible**: Easy to configure and extend
76
+ - ✅ **Zero dependencies** - Pure native browser implementation
77
+ - ✅ **Lightweight** - Minimal bundle size (~500 bytes gzipped)
78
+ - ✅ **Browser-optimized** - Uses native `console` API
79
+ - ✅ **Compatible** - WSXJS core logger interface
80
+ - ✅ **TypeScript** - Full type support
81
+ - ✅ **Environment-aware** - Auto-configures based on production/development
82
+ - ✅ **Component-specific** - Create loggers with custom prefixes
83
+ - ✅ **Dynamic control** - Change log levels at runtime
84
+ - ✅ **Production-ready** - Automatically reduces verbosity in production
85
+
86
+ ## Why Native Implementation?
87
+
88
+ - **Zero dependencies**: No external packages, perfect for WSXJS's zero-dependency philosophy
89
+ - **Native browser API**: Uses standard `console` methods (debug, info, warn, error)
90
+ - **Maximum compatibility**: Works in all modern browsers without polyfills
91
+ - **Minimal overhead**: Direct console calls, no abstraction layer
92
+ - **Full control**: Complete control over logging behavior
93
+ - **Bundle size**: Smaller than any external logging library
93
94
 
94
95
  ## License
95
96
 
package/dist/index.cjs CHANGED
@@ -1,21 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const log = require("loglevel");
4
- const LOG_LEVEL_MAP = {
5
- trace: "trace",
6
- debug: "debug",
7
- info: "info",
8
- warn: "warn",
9
- error: "error",
10
- silent: "silent"
11
- };
12
- const NUMERIC_TO_LEVEL = {
13
- 0: "trace",
14
- 1: "debug",
15
- 2: "info",
16
- 3: "warn",
17
- 4: "error",
18
- 5: "silent"
3
+ const LOG_LEVEL_VALUES = {
4
+ trace: 0,
5
+ debug: 1,
6
+ info: 2,
7
+ warn: 3,
8
+ error: 4,
9
+ silent: 5
19
10
  };
20
11
  function isProduction() {
21
12
  var _a, _b;
@@ -37,31 +28,42 @@ const DEFAULT_CONFIG = {
37
28
  level: isProduction() ? "info" : "debug",
38
29
  pretty: !isProduction()
39
30
  };
40
- function createLoglevelLogger(config = {}) {
41
- const { name, level } = { ...DEFAULT_CONFIG, ...config };
42
- const loggerName = name || DEFAULT_CONFIG.name;
43
- const loggerInstance = log.getLogger(loggerName);
44
- const targetLevel = level || DEFAULT_CONFIG.level;
45
- loggerInstance.setLevel(LOG_LEVEL_MAP[targetLevel]);
46
- return loggerInstance;
47
- }
48
31
  function formatMessage(name, message) {
49
32
  return name ? `[${name}] ${message}` : message;
50
33
  }
51
- class WSXLogger {
52
- constructor(config = {}) {
34
+ class NativeLogger {
35
+ constructor(name, level) {
36
+ this.name = name;
37
+ this.level = level;
38
+ this.levelValue = LOG_LEVEL_VALUES[level];
53
39
  this.isProd = isProduction();
54
- this.name = config.name || DEFAULT_CONFIG.name;
55
- this.currentLevel = config.level || DEFAULT_CONFIG.level;
56
- this.logInstance = createLoglevelLogger(config);
40
+ }
41
+ /**
42
+ * Check if a log level should be logged
43
+ */
44
+ shouldLog(level) {
45
+ if (this.level === "silent") {
46
+ return false;
47
+ }
48
+ return LOG_LEVEL_VALUES[level] >= this.levelValue;
49
+ }
50
+ trace(message, ...args) {
51
+ if (!this.isProd || this.shouldLog("trace")) {
52
+ const formattedMessage = formatMessage(this.name, message);
53
+ if (args.length > 0) {
54
+ console.debug(formattedMessage, ...args);
55
+ } else {
56
+ console.debug(formattedMessage);
57
+ }
58
+ }
57
59
  }
58
60
  debug(message, ...args) {
59
61
  if (!this.isProd || this.shouldLog("debug")) {
60
62
  const formattedMessage = formatMessage(this.name, message);
61
63
  if (args.length > 0) {
62
- this.logInstance.debug(formattedMessage, ...args);
64
+ console.debug(formattedMessage, ...args);
63
65
  } else {
64
- this.logInstance.debug(formattedMessage);
66
+ console.debug(formattedMessage);
65
67
  }
66
68
  }
67
69
  }
@@ -69,74 +71,87 @@ class WSXLogger {
69
71
  if (this.shouldLog("info")) {
70
72
  const formattedMessage = formatMessage(this.name, message);
71
73
  if (args.length > 0) {
72
- this.logInstance.info(formattedMessage, ...args);
74
+ console.info(formattedMessage, ...args);
73
75
  } else {
74
- this.logInstance.info(formattedMessage);
76
+ console.info(formattedMessage);
75
77
  }
76
78
  }
77
79
  }
78
80
  warn(message, ...args) {
79
- const formattedMessage = formatMessage(this.name, message);
80
- if (args.length > 0) {
81
- this.logInstance.warn(formattedMessage, ...args);
82
- } else {
83
- this.logInstance.warn(formattedMessage);
81
+ if (this.shouldLog("warn")) {
82
+ const formattedMessage = formatMessage(this.name, message);
83
+ if (args.length > 0) {
84
+ console.warn(formattedMessage, ...args);
85
+ } else {
86
+ console.warn(formattedMessage);
87
+ }
84
88
  }
85
89
  }
86
90
  error(message, ...args) {
87
- const formattedMessage = formatMessage(this.name, message);
88
- if (args.length > 0) {
89
- this.logInstance.error(formattedMessage, ...args);
90
- } else {
91
- this.logInstance.error(formattedMessage);
92
- }
93
- }
94
- fatal(message, ...args) {
95
- const formattedMessage = formatMessage(this.name, message);
96
- if (args.length > 0) {
97
- this.logInstance.error(`[FATAL] ${formattedMessage}`, ...args);
98
- } else {
99
- this.logInstance.error(`[FATAL] ${formattedMessage}`);
100
- }
101
- }
102
- trace(message, ...args) {
103
- if (!this.isProd || this.shouldLog("trace")) {
91
+ if (this.shouldLog("error")) {
104
92
  const formattedMessage = formatMessage(this.name, message);
105
93
  if (args.length > 0) {
106
- this.logInstance.trace(formattedMessage, ...args);
94
+ console.error(formattedMessage, ...args);
107
95
  } else {
108
- this.logInstance.trace(formattedMessage);
96
+ console.error(formattedMessage);
109
97
  }
110
98
  }
111
99
  }
112
100
  /**
113
- * Check if a log level should be logged based on current level
101
+ * Set the log level dynamically
114
102
  */
115
- shouldLog(level) {
116
- const levels = ["trace", "debug", "info", "warn", "error", "silent"];
117
- const currentLevelIndex = levels.indexOf(this.currentLevel);
118
- const messageLevelIndex = levels.indexOf(level);
119
- return messageLevelIndex >= currentLevelIndex;
103
+ setLevel(level) {
104
+ this.level = level;
105
+ this.levelValue = LOG_LEVEL_VALUES[level];
120
106
  }
121
107
  /**
122
- * Get the underlying loglevel logger instance
108
+ * Get the current log level
123
109
  */
124
- getLoglevelLogger() {
125
- return this.logInstance;
110
+ getLevel() {
111
+ return this.level;
112
+ }
113
+ }
114
+ class WSXLogger {
115
+ constructor(config = {}) {
116
+ this.name = config.name || DEFAULT_CONFIG.name;
117
+ this.currentLevel = config.level || DEFAULT_CONFIG.level;
118
+ this.nativeLogger = new NativeLogger(this.name, this.currentLevel);
119
+ }
120
+ debug(message, ...args) {
121
+ this.nativeLogger.debug(message, ...args);
122
+ }
123
+ info(message, ...args) {
124
+ this.nativeLogger.info(message, ...args);
125
+ }
126
+ warn(message, ...args) {
127
+ this.nativeLogger.warn(message, ...args);
128
+ }
129
+ error(message, ...args) {
130
+ this.nativeLogger.error(message, ...args);
131
+ }
132
+ fatal(message, ...args) {
133
+ const formattedMessage = formatMessage(this.name, `[FATAL] ${message}`);
134
+ if (args.length > 0) {
135
+ console.error(formattedMessage, ...args);
136
+ } else {
137
+ console.error(formattedMessage);
138
+ }
139
+ }
140
+ trace(message, ...args) {
141
+ this.nativeLogger.trace(message, ...args);
126
142
  }
127
143
  /**
128
144
  * Set the log level dynamically
129
145
  */
130
146
  setLevel(level) {
131
147
  this.currentLevel = level;
132
- this.logInstance.setLevel(LOG_LEVEL_MAP[level]);
148
+ this.nativeLogger.setLevel(level);
133
149
  }
134
150
  /**
135
151
  * Get the current log level
136
152
  */
137
153
  getLevel() {
138
- const numericLevel = this.logInstance.getLevel();
139
- return NUMERIC_TO_LEVEL[numericLevel] || this.currentLevel;
154
+ return this.nativeLogger.getLevel();
140
155
  }
141
156
  }
142
157
  const logger = new WSXLogger();
@@ -149,10 +164,6 @@ function createLogger(componentName, config = {}) {
149
164
  function createLoggerWithConfig(config) {
150
165
  return new WSXLogger(config);
151
166
  }
152
- Object.defineProperty(exports, "loglevel", {
153
- enumerable: true,
154
- get: () => log.log
155
- });
156
167
  exports.WSXLogger = WSXLogger;
157
168
  exports.createLogger = createLogger;
158
169
  exports.createLoggerWithConfig = createLoggerWithConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["/**\n * @wsxjs/wsx-logger\n * Browser-optimized logging utility for WSXJS\n */\n\nimport log from \"loglevel\";\n\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n\n/**\n * Logger interface compatible with WSXJS core logger\n */\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n fatal?(message: string, ...args: unknown[]): void;\n trace?(message: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger configuration options\n */\nexport interface LoggerConfig {\n /** Logger name/prefix */\n name?: string;\n /** Minimum log level */\n level?: LogLevel;\n /** Enable pretty printing (for development) - kept for API compatibility */\n pretty?: boolean;\n}\n\n/**\n * Map WSXJS log levels to loglevel string levels\n */\nconst LOG_LEVEL_MAP: Record<LogLevel, log.LogLevelDesc> = {\n trace: \"trace\",\n debug: \"debug\",\n info: \"info\",\n warn: \"warn\",\n error: \"error\",\n silent: \"silent\",\n};\n\n/**\n * Map loglevel numeric levels to WSXJS log levels\n */\nconst NUMERIC_TO_LEVEL: Record<number, LogLevel> = {\n 0: \"trace\",\n 1: \"debug\",\n 2: \"info\",\n 3: \"warn\",\n 4: \"error\",\n 5: \"silent\",\n};\n\n/**\n * Check if we're in production environment\n */\nfunction isProduction(): boolean {\n if (typeof process !== \"undefined\") {\n return process.env.NODE_ENV === \"production\" || process.env.MODE === \"production\";\n }\n // Check Vite's import.meta.env in browser (if available)\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const meta = globalThis as any;\n if (meta.import?.meta?.env) {\n const viteEnv = meta.import.meta.env;\n return viteEnv.MODE === \"production\" || viteEnv.PROD === true;\n }\n } catch {\n // Ignore errors\n }\n return false;\n}\n\n/**\n * Default logger configuration\n * - Production: info level\n * - Development: debug level\n */\nconst DEFAULT_CONFIG: LoggerConfig = {\n name: \"WSX\",\n level: isProduction() ? \"info\" : \"debug\",\n pretty: !isProduction(),\n};\n\n/**\n * Create a loglevel logger instance with prefix support\n */\nfunction createLoglevelLogger(config: LoggerConfig = {}): log.Logger {\n const { name, level } = { ...DEFAULT_CONFIG, ...config };\n\n // Create a new logger instance for this component\n const loggerName = name || DEFAULT_CONFIG.name || \"WSX\";\n const loggerInstance = log.getLogger(loggerName);\n\n // Set the log level\n const targetLevel = level || DEFAULT_CONFIG.level || \"info\";\n loggerInstance.setLevel(LOG_LEVEL_MAP[targetLevel]);\n\n return loggerInstance;\n}\n\n/**\n * Format log message with prefix\n */\nfunction formatMessage(name: string, message: string): string {\n return name ? `[${name}] ${message}` : message;\n}\n\n/**\n * WSX Logger wrapper that implements the Logger interface\n * and uses loglevel under the hood\n */\nexport class WSXLogger implements Logger {\n private logInstance: log.Logger;\n private name: string;\n private isProd: boolean;\n private currentLevel: LogLevel;\n\n constructor(config: LoggerConfig = {}) {\n this.isProd = isProduction();\n this.name = config.name || DEFAULT_CONFIG.name || \"WSX\";\n this.currentLevel =\n config.level || DEFAULT_CONFIG.level || (this.isProd ? \"info\" : \"debug\");\n this.logInstance = createLoglevelLogger(config);\n }\n\n debug(message: string, ...args: unknown[]): void {\n // Always show debug logs in non-production environments\n if (!this.isProd || this.shouldLog(\"debug\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.debug(formattedMessage, ...args);\n } else {\n this.logInstance.debug(formattedMessage);\n }\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"info\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.info(formattedMessage, ...args);\n } else {\n this.logInstance.info(formattedMessage);\n }\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n // Always show warnings (in both production and development)\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.warn(formattedMessage, ...args);\n } else {\n this.logInstance.warn(formattedMessage);\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n // Always show errors (in both production and development)\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.error(formattedMessage, ...args);\n } else {\n this.logInstance.error(formattedMessage);\n }\n }\n\n fatal(message: string, ...args: unknown[]): void {\n // Fatal is treated as error in loglevel\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.error(`[FATAL] ${formattedMessage}`, ...args);\n } else {\n this.logInstance.error(`[FATAL] ${formattedMessage}`);\n }\n }\n\n trace(message: string, ...args: unknown[]): void {\n // Always show trace logs in non-production environments\n if (!this.isProd || this.shouldLog(\"trace\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.trace(formattedMessage, ...args);\n } else {\n this.logInstance.trace(formattedMessage);\n }\n }\n }\n\n /**\n * Check if a log level should be logged based on current level\n */\n private shouldLog(level: LogLevel): boolean {\n const levels: LogLevel[] = [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"silent\"];\n const currentLevelIndex = levels.indexOf(this.currentLevel);\n const messageLevelIndex = levels.indexOf(level);\n\n return messageLevelIndex >= currentLevelIndex;\n }\n\n /**\n * Get the underlying loglevel logger instance\n */\n getLoglevelLogger(): log.Logger {\n return this.logInstance;\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.currentLevel = level;\n this.logInstance.setLevel(LOG_LEVEL_MAP[level] as log.LogLevelDesc);\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n const numericLevel = this.logInstance.getLevel();\n return NUMERIC_TO_LEVEL[numericLevel] || this.currentLevel;\n }\n}\n\n/**\n * Default logger instance\n */\nexport const logger = new WSXLogger();\n\n/**\n * Create a component-specific logger\n *\n * @param componentName - Name of the component/module\n * @param config - Optional logger configuration\n * @returns Logger instance\n */\nexport function createLogger(componentName: string, config: LoggerConfig = {}): Logger {\n return new WSXLogger({\n ...config,\n name: config.name || `WSX:${componentName}`,\n });\n}\n\n/**\n * Create a logger with custom configuration\n *\n * @param config - Logger configuration\n * @returns Logger instance\n */\nexport function createLoggerWithConfig(config: LoggerConfig): Logger {\n return new WSXLogger(config);\n}\n\n// Export loglevel types for advanced usage\nexport type { Logger as LoglevelLogger } from \"loglevel\";\nexport { log as loglevel } from \"loglevel\";\n"],"names":[],"mappings":";;;AAoCA,MAAM,gBAAoD;AAAA,EACtD,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ;AAKA,MAAM,mBAA6C;AAAA,EAC/C,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACP;AAKA,SAAS,eAAwB;;AAC7B,MAAI,OAAO,YAAY,aAAa;AAChC,WAAO,QAAQ,IAAI,aAAa,gBAAgB,QAAQ,IAAI,SAAS;AAAA,EACzE;AAEA,MAAI;AAEA,UAAM,OAAO;AACb,SAAI,gBAAK,WAAL,mBAAa,SAAb,mBAAmB,KAAK;AACxB,YAAM,UAAU,KAAK,OAAO,KAAK;AACjC,aAAO,QAAQ,SAAS,gBAAgB,QAAQ,SAAS;AAAA,IAC7D;AAAA,EACJ,QAAQ;AAAA,EAER;AACA,SAAO;AACX;AAOA,MAAM,iBAA+B;AAAA,EACjC,MAAM;AAAA,EACN,OAAO,iBAAiB,SAAS;AAAA,EACjC,QAAQ,CAAC,aAAA;AACb;AAKA,SAAS,qBAAqB,SAAuB,IAAgB;AACjE,QAAM,EAAE,MAAM,MAAA,IAAU,EAAE,GAAG,gBAAgB,GAAG,OAAA;AAGhD,QAAM,aAAa,QAAQ,eAAe;AAC1C,QAAM,iBAAiB,IAAI,UAAU,UAAU;AAG/C,QAAM,cAAc,SAAS,eAAe;AAC5C,iBAAe,SAAS,cAAc,WAAW,CAAC;AAElD,SAAO;AACX;AAKA,SAAS,cAAc,MAAc,SAAyB;AAC1D,SAAO,OAAO,IAAI,IAAI,KA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,QAAQ,OAAO,aAAa;AAAA,EAAA,CAC5C;AACL;AAQO,SAAS,uBAAuB,QAA8B;AACjE,SAAO,IAAI,UAAU,MAAM;AAC/B;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["/**\n * @wsxjs/wsx-logger\n * Browser-optimized logging utility for WSXJS\n *\n * Pure native browser implementation - zero dependencies\n * Uses native console API for maximum compatibility and minimal bundle size\n */\n\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n\n/**\n * Logger interface compatible with WSXJS core logger\n */\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n fatal?(message: string, ...args: unknown[]): void;\n trace?(message: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger configuration options\n */\nexport interface LoggerConfig {\n /** Logger name/prefix */\n name?: string;\n /** Minimum log level */\n level?: LogLevel;\n /** Enable pretty printing (for development) - kept for API compatibility */\n pretty?: boolean;\n}\n\n/**\n * Log level hierarchy (numeric values for comparison)\n */\nconst LOG_LEVEL_VALUES: Record<LogLevel, number> = {\n trace: 0,\n debug: 1,\n info: 2,\n warn: 3,\n error: 4,\n silent: 5,\n};\n\n/**\n * Check if we're in production environment\n */\nfunction isProduction(): boolean {\n if (typeof process !== \"undefined\") {\n return process.env.NODE_ENV === \"production\" || process.env.MODE === \"production\";\n }\n // Check Vite's import.meta.env in browser (if available)\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const meta = globalThis as any;\n if (meta.import?.meta?.env) {\n const viteEnv = meta.import.meta.env;\n return viteEnv.MODE === \"production\" || viteEnv.PROD === true;\n }\n } catch {\n // Ignore errors\n }\n return false;\n}\n\n/**\n * Default logger configuration\n * - Production: info level\n * - Development: debug level\n */\nconst DEFAULT_CONFIG: LoggerConfig = {\n name: \"WSX\",\n level: isProduction() ? \"info\" : \"debug\",\n pretty: !isProduction(),\n};\n\n/**\n * Format log message with prefix\n */\nfunction formatMessage(name: string, message: string): string {\n return name ? `[${name}] ${message}` : message;\n}\n\n/**\n * Native browser logger implementation using console API\n * Zero dependencies, perfect browser compatibility\n */\nclass NativeLogger {\n private name: string;\n private level: LogLevel;\n private levelValue: number;\n private isProd: boolean;\n\n constructor(name: string, level: LogLevel) {\n this.name = name;\n this.level = level;\n this.levelValue = LOG_LEVEL_VALUES[level];\n this.isProd = isProduction();\n }\n\n /**\n * Check if a log level should be logged\n */\n private shouldLog(level: LogLevel): boolean {\n if (this.level === \"silent\") {\n return false;\n }\n return LOG_LEVEL_VALUES[level] >= this.levelValue;\n }\n\n trace(message: string, ...args: unknown[]): void {\n // Trace is only shown in non-production or if explicitly enabled\n if (!this.isProd || this.shouldLog(\"trace\")) {\n const formattedMessage = formatMessage(this.name, message);\n // Use console.debug for trace (browsers don't have console.trace as a log method)\n if (args.length > 0) {\n console.debug(formattedMessage, ...args);\n } else {\n console.debug(formattedMessage);\n }\n }\n }\n\n debug(message: string, ...args: unknown[]): void {\n // Always show debug logs in non-production environments\n if (!this.isProd || this.shouldLog(\"debug\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.debug(formattedMessage, ...args);\n } else {\n console.debug(formattedMessage);\n }\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"info\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.info(formattedMessage, ...args);\n } else {\n console.info(formattedMessage);\n }\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n // Always show warnings (in both production and development)\n if (this.shouldLog(\"warn\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.warn(formattedMessage, ...args);\n } else {\n console.warn(formattedMessage);\n }\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n // Always show errors (in both production and development)\n if (this.shouldLog(\"error\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.error(formattedMessage, ...args);\n } else {\n console.error(formattedMessage);\n }\n }\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.level = level;\n this.levelValue = LOG_LEVEL_VALUES[level];\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n return this.level;\n }\n}\n\n/**\n * WSX Logger wrapper that implements the Logger interface\n * Uses native browser console API - zero dependencies\n */\nexport class WSXLogger implements Logger {\n private nativeLogger: NativeLogger;\n private name: string;\n private currentLevel: LogLevel;\n\n constructor(config: LoggerConfig = {}) {\n this.name = config.name || DEFAULT_CONFIG.name || \"WSX\";\n this.currentLevel =\n config.level || DEFAULT_CONFIG.level || (isProduction() ? \"info\" : \"debug\");\n this.nativeLogger = new NativeLogger(this.name, this.currentLevel);\n }\n\n debug(message: string, ...args: unknown[]): void {\n this.nativeLogger.debug(message, ...args);\n }\n\n info(message: string, ...args: unknown[]): void {\n this.nativeLogger.info(message, ...args);\n }\n\n warn(message: string, ...args: unknown[]): void {\n this.nativeLogger.warn(message, ...args);\n }\n\n error(message: string, ...args: unknown[]): void {\n this.nativeLogger.error(message, ...args);\n }\n\n fatal(message: string, ...args: unknown[]): void {\n // Fatal is treated as error with [FATAL] prefix\n const formattedMessage = formatMessage(this.name, `[FATAL] ${message}`);\n if (args.length > 0) {\n console.error(formattedMessage, ...args);\n } else {\n console.error(formattedMessage);\n }\n }\n\n trace(message: string, ...args: unknown[]): void {\n this.nativeLogger.trace(message, ...args);\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.currentLevel = level;\n this.nativeLogger.setLevel(level);\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n return this.nativeLogger.getLevel();\n }\n}\n\n/**\n * Default logger instance\n */\nexport const logger = new WSXLogger();\n\n/**\n * Create a component-specific logger\n *\n * @param componentName - Name of the component/module\n * @param config - Optional logger configuration\n * @returns Logger instance\n */\nexport function createLogger(componentName: string, config: LoggerConfig = {}): Logger {\n return new WSXLogger({\n ...config,\n name: config.name || `WSX:${componentName}`,\n });\n}\n\n/**\n * Create a logger with custom configuration\n *\n * @param config - Logger configuration\n * @returns Logger instance\n */\nexport function createLoggerWithConfig(config: LoggerConfig): Logger {\n return new WSXLogger(config);\n}\n"],"names":[],"mappings":";;AAqCA,MAAM,mBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ;AAKA,SAAS,eAAwB;;AAC7B,MAAI,OAAO,YAAY,aAAa;AAChC,WAAO,QAAQ,IAAI,aAAa,gBAAgB,QAAQ,IAAI,SAAS;AAAA,EACzE;AAEA,MAAI;AAEA,UAAM,OAAO;AACb,SAAI,gBAAK,WAAL,mBAAa,SAAb,mBAAmB,KAAK;AACxB,YAAM,UAAU,KAAK,OAAO,KAAK;AACjC,aAAO,QAAQ,SAAS,gBAAgB,QAAQ,SAAS;AAAA,IAC7D;AAAA,EACJ,QAAQ;AAAA,EAER;AACA,SAAO;AACX;AAOA,MAAM,iBAA+B;AAAA,EACjC,MAAM;AAAA,EACN,OAAO,iBAAiB,SAAS;AAAA,EACjC,QAAQ,CAAC,aAAA;AACb;AAKA,SAAS,cAAc,MAAc,SAAyB;AAC1D,SAAO,OAAO,IAAI,IAAI,KAAK,OAAO,KAAK;AAC3C;AAMA,MAAM,aAAa;AAAA,EAMf,YAAY,MAAc,OAAiB;AACvC,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,aAAa,iBAAiB,KAAK;AACxC,SAAK,SAAS,aAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKQ,UAAU,OAA0B;AACxC,QAAI,KAAK,UAAU,UAAU;AACzB,aAAO;AAAA,IACX;AACA,WAAO,iBAAiB,KAAK,KAAK,KAAK;AAAA,EAC3C;AAAA,EAEA,MAAM,YAAoB,MAAuB;AAE7C,QAAI,CAAC,KAAK,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AA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKA,WAAqB;AACjB,WAAO,KAAK,aAAa,SAAA;AAAA,EAC7B;AACJ;AAKO,MAAM,SAAS,IAAI,UAAA;AASnB,SAAS,aAAa,eAAuB,SAAuB,IAAY;AACnF,SAAO,IAAI,UAAU;AAAA,IACjB,GAAG;AAAA,IACH,MAAM,OAAO,QAAQ,OAAO,aAAa;AAAA,EAAA,CAC5C;AACL;AAQO,SAAS,uBAAuB,QAA8B;AACjE,SAAO,IAAI,UAAU,MAAM;AAC/B;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * @wsxjs/wsx-logger
3
3
  * Browser-optimized logging utility for WSXJS
4
+ *
5
+ * Pure native browser implementation - zero dependencies
6
+ * Uses native console API for maximum compatibility and minimal bundle size
4
7
  */
5
- import log from "loglevel";
6
8
  export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
7
9
  /**
8
10
  * Logger interface compatible with WSXJS core logger
@@ -28,12 +30,11 @@ export interface LoggerConfig {
28
30
  }
29
31
  /**
30
32
  * WSX Logger wrapper that implements the Logger interface
31
- * and uses loglevel under the hood
33
+ * Uses native browser console API - zero dependencies
32
34
  */
33
35
  export declare class WSXLogger implements Logger {
34
- private logInstance;
36
+ private nativeLogger;
35
37
  private name;
36
- private isProd;
37
38
  private currentLevel;
38
39
  constructor(config?: LoggerConfig);
39
40
  debug(message: string, ...args: unknown[]): void;
@@ -42,14 +43,6 @@ export declare class WSXLogger implements Logger {
42
43
  error(message: string, ...args: unknown[]): void;
43
44
  fatal(message: string, ...args: unknown[]): void;
44
45
  trace(message: string, ...args: unknown[]): void;
45
- /**
46
- * Check if a log level should be logged based on current level
47
- */
48
- private shouldLog;
49
- /**
50
- * Get the underlying loglevel logger instance
51
- */
52
- getLoglevelLogger(): log.Logger;
53
46
  /**
54
47
  * Set the log level dynamically
55
48
  */
@@ -78,6 +71,4 @@ export declare function createLogger(componentName: string, config?: LoggerConfi
78
71
  * @returns Logger instance
79
72
  */
80
73
  export declare function createLoggerWithConfig(config: LoggerConfig): Logger;
81
- export type { Logger as LoglevelLogger } from "loglevel";
82
- export { log as loglevel } from "loglevel";
83
74
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAClD,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAkFD;;;GAGG;AACH,qBAAa,SAAU,YAAW,MAAM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AC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAUhD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAK/B;;OAEG;IACH,QAAQ,IAAI,QAAQ;CAGvB;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,WAAkB,CAAC;AAEtC;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,GAAE,YAAiB,GAAG,MAAM,CAKrF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAEnE"}
package/dist/index.js CHANGED
@@ -1,20 +1,10 @@
1
- import log from "loglevel";
2
- import { log as log2 } from "loglevel";
3
- const LOG_LEVEL_MAP = {
4
- trace: "trace",
5
- debug: "debug",
6
- info: "info",
7
- warn: "warn",
8
- error: "error",
9
- silent: "silent"
10
- };
11
- const NUMERIC_TO_LEVEL = {
12
- 0: "trace",
13
- 1: "debug",
14
- 2: "info",
15
- 3: "warn",
16
- 4: "error",
17
- 5: "silent"
1
+ const LOG_LEVEL_VALUES = {
2
+ trace: 0,
3
+ debug: 1,
4
+ info: 2,
5
+ warn: 3,
6
+ error: 4,
7
+ silent: 5
18
8
  };
19
9
  function isProduction() {
20
10
  var _a, _b;
@@ -36,31 +26,42 @@ const DEFAULT_CONFIG = {
36
26
  level: isProduction() ? "info" : "debug",
37
27
  pretty: !isProduction()
38
28
  };
39
- function createLoglevelLogger(config = {}) {
40
- const { name, level } = { ...DEFAULT_CONFIG, ...config };
41
- const loggerName = name || DEFAULT_CONFIG.name;
42
- const loggerInstance = log.getLogger(loggerName);
43
- const targetLevel = level || DEFAULT_CONFIG.level;
44
- loggerInstance.setLevel(LOG_LEVEL_MAP[targetLevel]);
45
- return loggerInstance;
46
- }
47
29
  function formatMessage(name, message) {
48
30
  return name ? `[${name}] ${message}` : message;
49
31
  }
50
- class WSXLogger {
51
- constructor(config = {}) {
32
+ class NativeLogger {
33
+ constructor(name, level) {
34
+ this.name = name;
35
+ this.level = level;
36
+ this.levelValue = LOG_LEVEL_VALUES[level];
52
37
  this.isProd = isProduction();
53
- this.name = config.name || DEFAULT_CONFIG.name;
54
- this.currentLevel = config.level || DEFAULT_CONFIG.level;
55
- this.logInstance = createLoglevelLogger(config);
38
+ }
39
+ /**
40
+ * Check if a log level should be logged
41
+ */
42
+ shouldLog(level) {
43
+ if (this.level === "silent") {
44
+ return false;
45
+ }
46
+ return LOG_LEVEL_VALUES[level] >= this.levelValue;
47
+ }
48
+ trace(message, ...args) {
49
+ if (!this.isProd || this.shouldLog("trace")) {
50
+ const formattedMessage = formatMessage(this.name, message);
51
+ if (args.length > 0) {
52
+ console.debug(formattedMessage, ...args);
53
+ } else {
54
+ console.debug(formattedMessage);
55
+ }
56
+ }
56
57
  }
57
58
  debug(message, ...args) {
58
59
  if (!this.isProd || this.shouldLog("debug")) {
59
60
  const formattedMessage = formatMessage(this.name, message);
60
61
  if (args.length > 0) {
61
- this.logInstance.debug(formattedMessage, ...args);
62
+ console.debug(formattedMessage, ...args);
62
63
  } else {
63
- this.logInstance.debug(formattedMessage);
64
+ console.debug(formattedMessage);
64
65
  }
65
66
  }
66
67
  }
@@ -68,74 +69,87 @@ class WSXLogger {
68
69
  if (this.shouldLog("info")) {
69
70
  const formattedMessage = formatMessage(this.name, message);
70
71
  if (args.length > 0) {
71
- this.logInstance.info(formattedMessage, ...args);
72
+ console.info(formattedMessage, ...args);
72
73
  } else {
73
- this.logInstance.info(formattedMessage);
74
+ console.info(formattedMessage);
74
75
  }
75
76
  }
76
77
  }
77
78
  warn(message, ...args) {
78
- const formattedMessage = formatMessage(this.name, message);
79
- if (args.length > 0) {
80
- this.logInstance.warn(formattedMessage, ...args);
81
- } else {
82
- this.logInstance.warn(formattedMessage);
79
+ if (this.shouldLog("warn")) {
80
+ const formattedMessage = formatMessage(this.name, message);
81
+ if (args.length > 0) {
82
+ console.warn(formattedMessage, ...args);
83
+ } else {
84
+ console.warn(formattedMessage);
85
+ }
83
86
  }
84
87
  }
85
88
  error(message, ...args) {
86
- const formattedMessage = formatMessage(this.name, message);
87
- if (args.length > 0) {
88
- this.logInstance.error(formattedMessage, ...args);
89
- } else {
90
- this.logInstance.error(formattedMessage);
91
- }
92
- }
93
- fatal(message, ...args) {
94
- const formattedMessage = formatMessage(this.name, message);
95
- if (args.length > 0) {
96
- this.logInstance.error(`[FATAL] ${formattedMessage}`, ...args);
97
- } else {
98
- this.logInstance.error(`[FATAL] ${formattedMessage}`);
99
- }
100
- }
101
- trace(message, ...args) {
102
- if (!this.isProd || this.shouldLog("trace")) {
89
+ if (this.shouldLog("error")) {
103
90
  const formattedMessage = formatMessage(this.name, message);
104
91
  if (args.length > 0) {
105
- this.logInstance.trace(formattedMessage, ...args);
92
+ console.error(formattedMessage, ...args);
106
93
  } else {
107
- this.logInstance.trace(formattedMessage);
94
+ console.error(formattedMessage);
108
95
  }
109
96
  }
110
97
  }
111
98
  /**
112
- * Check if a log level should be logged based on current level
99
+ * Set the log level dynamically
113
100
  */
114
- shouldLog(level) {
115
- const levels = ["trace", "debug", "info", "warn", "error", "silent"];
116
- const currentLevelIndex = levels.indexOf(this.currentLevel);
117
- const messageLevelIndex = levels.indexOf(level);
118
- return messageLevelIndex >= currentLevelIndex;
101
+ setLevel(level) {
102
+ this.level = level;
103
+ this.levelValue = LOG_LEVEL_VALUES[level];
119
104
  }
120
105
  /**
121
- * Get the underlying loglevel logger instance
106
+ * Get the current log level
122
107
  */
123
- getLoglevelLogger() {
124
- return this.logInstance;
108
+ getLevel() {
109
+ return this.level;
110
+ }
111
+ }
112
+ class WSXLogger {
113
+ constructor(config = {}) {
114
+ this.name = config.name || DEFAULT_CONFIG.name;
115
+ this.currentLevel = config.level || DEFAULT_CONFIG.level;
116
+ this.nativeLogger = new NativeLogger(this.name, this.currentLevel);
117
+ }
118
+ debug(message, ...args) {
119
+ this.nativeLogger.debug(message, ...args);
120
+ }
121
+ info(message, ...args) {
122
+ this.nativeLogger.info(message, ...args);
123
+ }
124
+ warn(message, ...args) {
125
+ this.nativeLogger.warn(message, ...args);
126
+ }
127
+ error(message, ...args) {
128
+ this.nativeLogger.error(message, ...args);
129
+ }
130
+ fatal(message, ...args) {
131
+ const formattedMessage = formatMessage(this.name, `[FATAL] ${message}`);
132
+ if (args.length > 0) {
133
+ console.error(formattedMessage, ...args);
134
+ } else {
135
+ console.error(formattedMessage);
136
+ }
137
+ }
138
+ trace(message, ...args) {
139
+ this.nativeLogger.trace(message, ...args);
125
140
  }
126
141
  /**
127
142
  * Set the log level dynamically
128
143
  */
129
144
  setLevel(level) {
130
145
  this.currentLevel = level;
131
- this.logInstance.setLevel(LOG_LEVEL_MAP[level]);
146
+ this.nativeLogger.setLevel(level);
132
147
  }
133
148
  /**
134
149
  * Get the current log level
135
150
  */
136
151
  getLevel() {
137
- const numericLevel = this.logInstance.getLevel();
138
- return NUMERIC_TO_LEVEL[numericLevel] || this.currentLevel;
152
+ return this.nativeLogger.getLevel();
139
153
  }
140
154
  }
141
155
  const logger = new WSXLogger();
@@ -152,7 +166,6 @@ export {
152
166
  WSXLogger,
153
167
  createLogger,
154
168
  createLoggerWithConfig,
155
- logger,
156
- log2 as loglevel
169
+ logger
157
170
  };
158
171
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * @wsxjs/wsx-logger\n * Browser-optimized logging utility for WSXJS\n */\n\nimport log from \"loglevel\";\n\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n\n/**\n * Logger interface compatible with WSXJS core logger\n */\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n fatal?(message: string, ...args: unknown[]): void;\n trace?(message: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger configuration options\n */\nexport interface LoggerConfig {\n /** Logger name/prefix */\n name?: string;\n /** Minimum log level */\n level?: LogLevel;\n /** Enable pretty printing (for development) - kept for API compatibility */\n pretty?: boolean;\n}\n\n/**\n * Map WSXJS log levels to loglevel string levels\n */\nconst LOG_LEVEL_MAP: Record<LogLevel, log.LogLevelDesc> = {\n trace: \"trace\",\n debug: \"debug\",\n info: \"info\",\n warn: \"warn\",\n error: \"error\",\n silent: \"silent\",\n};\n\n/**\n * Map loglevel numeric levels to WSXJS log levels\n */\nconst NUMERIC_TO_LEVEL: Record<number, LogLevel> = {\n 0: \"trace\",\n 1: \"debug\",\n 2: \"info\",\n 3: \"warn\",\n 4: \"error\",\n 5: \"silent\",\n};\n\n/**\n * Check if we're in production environment\n */\nfunction isProduction(): boolean {\n if (typeof process !== \"undefined\") {\n return process.env.NODE_ENV === \"production\" || process.env.MODE === \"production\";\n }\n // Check Vite's import.meta.env in browser (if available)\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const meta = globalThis as any;\n if (meta.import?.meta?.env) {\n const viteEnv = meta.import.meta.env;\n return viteEnv.MODE === \"production\" || viteEnv.PROD === true;\n }\n } catch {\n // Ignore errors\n }\n return false;\n}\n\n/**\n * Default logger configuration\n * - Production: info level\n * - Development: debug level\n */\nconst DEFAULT_CONFIG: LoggerConfig = {\n name: \"WSX\",\n level: isProduction() ? \"info\" : \"debug\",\n pretty: !isProduction(),\n};\n\n/**\n * Create a loglevel logger instance with prefix support\n */\nfunction createLoglevelLogger(config: LoggerConfig = {}): log.Logger {\n const { name, level } = { ...DEFAULT_CONFIG, ...config };\n\n // Create a new logger instance for this component\n const loggerName = name || DEFAULT_CONFIG.name || \"WSX\";\n const loggerInstance = log.getLogger(loggerName);\n\n // Set the log level\n const targetLevel = level || DEFAULT_CONFIG.level || \"info\";\n loggerInstance.setLevel(LOG_LEVEL_MAP[targetLevel]);\n\n return loggerInstance;\n}\n\n/**\n * Format log message with prefix\n */\nfunction formatMessage(name: string, message: string): string {\n return name ? `[${name}] ${message}` : message;\n}\n\n/**\n * WSX Logger wrapper that implements the Logger interface\n * and uses loglevel under the hood\n */\nexport class WSXLogger implements Logger {\n private logInstance: log.Logger;\n private name: string;\n private isProd: boolean;\n private currentLevel: LogLevel;\n\n constructor(config: LoggerConfig = {}) {\n this.isProd = isProduction();\n this.name = config.name || DEFAULT_CONFIG.name || \"WSX\";\n this.currentLevel =\n config.level || DEFAULT_CONFIG.level || (this.isProd ? \"info\" : \"debug\");\n this.logInstance = createLoglevelLogger(config);\n }\n\n debug(message: string, ...args: unknown[]): void {\n // Always show debug logs in non-production environments\n if (!this.isProd || this.shouldLog(\"debug\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.debug(formattedMessage, ...args);\n } else {\n this.logInstance.debug(formattedMessage);\n }\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"info\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.info(formattedMessage, ...args);\n } else {\n this.logInstance.info(formattedMessage);\n }\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n // Always show warnings (in both production and development)\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.warn(formattedMessage, ...args);\n } else {\n this.logInstance.warn(formattedMessage);\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n // Always show errors (in both production and development)\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.error(formattedMessage, ...args);\n } else {\n this.logInstance.error(formattedMessage);\n }\n }\n\n fatal(message: string, ...args: unknown[]): void {\n // Fatal is treated as error in loglevel\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.error(`[FATAL] ${formattedMessage}`, ...args);\n } else {\n this.logInstance.error(`[FATAL] ${formattedMessage}`);\n }\n }\n\n trace(message: string, ...args: unknown[]): void {\n // Always show trace logs in non-production environments\n if (!this.isProd || this.shouldLog(\"trace\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n this.logInstance.trace(formattedMessage, ...args);\n } else {\n this.logInstance.trace(formattedMessage);\n }\n }\n }\n\n /**\n * Check if a log level should be logged based on current level\n */\n private shouldLog(level: LogLevel): boolean {\n const levels: LogLevel[] = [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"silent\"];\n const currentLevelIndex = levels.indexOf(this.currentLevel);\n const messageLevelIndex = levels.indexOf(level);\n\n return messageLevelIndex >= currentLevelIndex;\n }\n\n /**\n * Get the underlying loglevel logger instance\n */\n getLoglevelLogger(): log.Logger {\n return this.logInstance;\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.currentLevel = level;\n this.logInstance.setLevel(LOG_LEVEL_MAP[level] as log.LogLevelDesc);\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n const numericLevel = this.logInstance.getLevel();\n return NUMERIC_TO_LEVEL[numericLevel] || this.currentLevel;\n }\n}\n\n/**\n * Default logger instance\n */\nexport const logger = new WSXLogger();\n\n/**\n * Create a component-specific logger\n *\n * @param componentName - Name of the component/module\n * @param config - Optional logger configuration\n * @returns Logger instance\n */\nexport function createLogger(componentName: string, config: LoggerConfig = {}): Logger {\n return new WSXLogger({\n ...config,\n name: config.name || `WSX:${componentName}`,\n });\n}\n\n/**\n * Create a logger with custom configuration\n *\n * @param config - Logger configuration\n * @returns Logger instance\n */\nexport function createLoggerWithConfig(config: LoggerConfig): Logger {\n return new WSXLogger(config);\n}\n\n// Export loglevel types for advanced usage\nexport type { Logger as LoglevelLogger } from \"loglevel\";\nexport { log as loglevel } from \"loglevel\";\n"],"names":[],"mappings":";;AAoCA,MAAM,gBAAoD;AAAA,EACtD,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ;AAKA,MAAM,mBAA6C;AAAA,EAC/C,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACP;AAKA,SAAS,eAAwB;;AAC7B,MAAI,OAAO,YAAY,aAAa;AAChC,WAAO,QAAQ,IAAI,aAAa,gBAAgB,QAAQ,IAAI,SAAS;AAAA,EACzE;AAEA,MAAI;AAEA,UAAM,OAAO;AACb,SAAI,gBAAK,WAAL,mBAAa,SAAb,mBAAmB,KAAK;AACxB,YAAM,UAAU,KAAK,OAAO,KAAK;AACjC,aAAO,QAAQ,SAAS,gBAAgB,QAAQ,SAAS;AAAA,IAC7D;AAAA,EACJ,QAAQ;AAAA,EAER;AACA,SAAO;AACX;AAOA,MAAM,iBAA+B;AAAA,EACjC,MAAM;AAAA,EACN,OAAO,iBAAiB,SAAS;AAAA,EACjC,QAAQ,CAAC,aAAA;AACb;AAKA,SAAS,qBAAqB,SAAuB,IAAgB;AACjE,QAAM,EAAE,MAAM,MAAA,IAAU,EAAE,GAAG,gBAAgB,GAAG,OAAA;AAGhD,QAAM,aAAa,QAAQ,eAAe;AAC1C,QAAM,iBAAiB,IAAI,UAAU,UAAU;AAG/C,QAAM,cAAc,SAAS,eAAe;AAC5C,iBAAe,SAAS,cAAc,WAAW,CAAC;AAElD,SAAO;AACX;AAKA,SAAS,cAAc,MAAc,SAAyB;AAC1D,SAAO,OAAO,IAAI,IAAI,KAAK,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AQ,OAAO,aAAa;AAAA,EAAA,CAC5C;AACL;AAQO,SAAS,uBAAuB,QAA8B;AACjE,SAAO,IAAI,UAAU,MAAM;AAC/B;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * @wsxjs/wsx-logger\n * Browser-optimized logging utility for WSXJS\n *\n * Pure native browser implementation - zero dependencies\n * Uses native console API for maximum compatibility and minimal bundle size\n */\n\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n\n/**\n * Logger interface compatible with WSXJS core logger\n */\nexport interface Logger {\n debug(message: string, ...args: unknown[]): void;\n info(message: string, ...args: unknown[]): void;\n warn(message: string, ...args: unknown[]): void;\n error(message: string, ...args: unknown[]): void;\n fatal?(message: string, ...args: unknown[]): void;\n trace?(message: string, ...args: unknown[]): void;\n}\n\n/**\n * Logger configuration options\n */\nexport interface LoggerConfig {\n /** Logger name/prefix */\n name?: string;\n /** Minimum log level */\n level?: LogLevel;\n /** Enable pretty printing (for development) - kept for API compatibility */\n pretty?: boolean;\n}\n\n/**\n * Log level hierarchy (numeric values for comparison)\n */\nconst LOG_LEVEL_VALUES: Record<LogLevel, number> = {\n trace: 0,\n debug: 1,\n info: 2,\n warn: 3,\n error: 4,\n silent: 5,\n};\n\n/**\n * Check if we're in production environment\n */\nfunction isProduction(): boolean {\n if (typeof process !== \"undefined\") {\n return process.env.NODE_ENV === \"production\" || process.env.MODE === \"production\";\n }\n // Check Vite's import.meta.env in browser (if available)\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const meta = globalThis as any;\n if (meta.import?.meta?.env) {\n const viteEnv = meta.import.meta.env;\n return viteEnv.MODE === \"production\" || viteEnv.PROD === true;\n }\n } catch {\n // Ignore errors\n }\n return false;\n}\n\n/**\n * Default logger configuration\n * - Production: info level\n * - Development: debug level\n */\nconst DEFAULT_CONFIG: LoggerConfig = {\n name: \"WSX\",\n level: isProduction() ? \"info\" : \"debug\",\n pretty: !isProduction(),\n};\n\n/**\n * Format log message with prefix\n */\nfunction formatMessage(name: string, message: string): string {\n return name ? `[${name}] ${message}` : message;\n}\n\n/**\n * Native browser logger implementation using console API\n * Zero dependencies, perfect browser compatibility\n */\nclass NativeLogger {\n private name: string;\n private level: LogLevel;\n private levelValue: number;\n private isProd: boolean;\n\n constructor(name: string, level: LogLevel) {\n this.name = name;\n this.level = level;\n this.levelValue = LOG_LEVEL_VALUES[level];\n this.isProd = isProduction();\n }\n\n /**\n * Check if a log level should be logged\n */\n private shouldLog(level: LogLevel): boolean {\n if (this.level === \"silent\") {\n return false;\n }\n return LOG_LEVEL_VALUES[level] >= this.levelValue;\n }\n\n trace(message: string, ...args: unknown[]): void {\n // Trace is only shown in non-production or if explicitly enabled\n if (!this.isProd || this.shouldLog(\"trace\")) {\n const formattedMessage = formatMessage(this.name, message);\n // Use console.debug for trace (browsers don't have console.trace as a log method)\n if (args.length > 0) {\n console.debug(formattedMessage, ...args);\n } else {\n console.debug(formattedMessage);\n }\n }\n }\n\n debug(message: string, ...args: unknown[]): void {\n // Always show debug logs in non-production environments\n if (!this.isProd || this.shouldLog(\"debug\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.debug(formattedMessage, ...args);\n } else {\n console.debug(formattedMessage);\n }\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog(\"info\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.info(formattedMessage, ...args);\n } else {\n console.info(formattedMessage);\n }\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n // Always show warnings (in both production and development)\n if (this.shouldLog(\"warn\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.warn(formattedMessage, ...args);\n } else {\n console.warn(formattedMessage);\n }\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n // Always show errors (in both production and development)\n if (this.shouldLog(\"error\")) {\n const formattedMessage = formatMessage(this.name, message);\n if (args.length > 0) {\n console.error(formattedMessage, ...args);\n } else {\n console.error(formattedMessage);\n }\n }\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.level = level;\n this.levelValue = LOG_LEVEL_VALUES[level];\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n return this.level;\n }\n}\n\n/**\n * WSX Logger wrapper that implements the Logger interface\n * Uses native browser console API - zero dependencies\n */\nexport class WSXLogger implements Logger {\n private nativeLogger: NativeLogger;\n private name: string;\n private currentLevel: LogLevel;\n\n constructor(config: LoggerConfig = {}) {\n this.name = config.name || DEFAULT_CONFIG.name || \"WSX\";\n this.currentLevel =\n config.level || DEFAULT_CONFIG.level || (isProduction() ? \"info\" : \"debug\");\n this.nativeLogger = new NativeLogger(this.name, this.currentLevel);\n }\n\n debug(message: string, ...args: unknown[]): void {\n this.nativeLogger.debug(message, ...args);\n }\n\n info(message: string, ...args: unknown[]): void {\n this.nativeLogger.info(message, ...args);\n }\n\n warn(message: string, ...args: unknown[]): void {\n this.nativeLogger.warn(message, ...args);\n }\n\n error(message: string, ...args: unknown[]): void {\n this.nativeLogger.error(message, ...args);\n }\n\n fatal(message: string, ...args: unknown[]): void {\n // Fatal is treated as error with [FATAL] prefix\n const formattedMessage = formatMessage(this.name, `[FATAL] ${message}`);\n if (args.length > 0) {\n console.error(formattedMessage, ...args);\n } else {\n console.error(formattedMessage);\n }\n }\n\n trace(message: string, ...args: unknown[]): void {\n this.nativeLogger.trace(message, ...args);\n }\n\n /**\n * Set the log level dynamically\n */\n setLevel(level: LogLevel): void {\n this.currentLevel = level;\n this.nativeLogger.setLevel(level);\n }\n\n /**\n * Get the current log level\n */\n getLevel(): LogLevel {\n return this.nativeLogger.getLevel();\n }\n}\n\n/**\n * Default logger instance\n */\nexport const logger = new WSXLogger();\n\n/**\n * Create a component-specific logger\n *\n * @param componentName - Name of the component/module\n * @param config - Optional logger configuration\n * @returns Logger instance\n */\nexport function createLogger(componentName: string, config: LoggerConfig = {}): Logger {\n return new WSXLogger({\n ...config,\n name: config.name || `WSX:${componentName}`,\n });\n}\n\n/**\n * Create a logger with custom configuration\n *\n * @param config - Logger configuration\n * @returns Logger instance\n */\nexport function createLoggerWithConfig(config: LoggerConfig): Logger {\n return new WSXLogger(config);\n}\n"],"names":[],"mappings":"AAqCA,MAAM,mBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ;AAKA,SAAS,eAAwB;AAZjC;AAaI,MAAI,OAAO,YAAY,aAAa;AAChC,WAAO,QAAQ,IAAI,aAAa,gBAAgB,QAAQ,IAAI,SAAS;AAAA,EACzE;AAEA,MAAI;AAEA,UAAM,OAAO;AACb,SAAI,gBAAK,WAAL,mBAAa,SAAb,mBAAmB,KAAK;AACxB,YAAM,UAAU,KAAK,OAAO,KAAK;AACjC,aAAO,QAAQ,SAAS,gBAAgB,QAAQ,SAAS;AAAA,IAC7D;AAAA,EACJ,QAAQ;AAAA,EAER;AACA,SAAO;AACX;AAOA,MAAM,iBAA+B;AAAA,EACjC,MAAM;AAAA,EACN,OAAO,iBAAiB,SAAS;AAAA,EACjC,QAAQ,CAAC,aAAA;AACb;AAKA,SAAS,cAAc,MAAc,SAAyB;AAC1D,SAAO,OAAO,IAAI,IAAI,KAAK,OAAO,KAAK;AAC3C;AAMA,MAAM,aAAa;AAAA,EAMf,YAAY,MAAc,OAAiB;AACvC,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,aAAa,iBAAiB,KAAK;AACxC,SAAK,SAAS,aAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKQ,UAAU,OAA0B;AACxC,QAAI,KAAK,UAAU,UAAU;AACzB,aAAO;AAAA,IACX;AACA,WAAO,iBAAiB,KAAK,KAAK,KAAK;AAAA,EAC3C;AAAA,EAEA,MAAM,YAAoB,MAAuB;AAE7C,QAAI,CAAC,KAAK,UAAU,KAAK,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AA;AAAA;AAAA;AAAA,EAKA,WAAqB;AACjB,WAAO,KAAK,aAAa,SAAA;AAAA,EAC7B;AACJ;AAKO,MAAM,SAAS,IAAI,UAAA;AASnB,SAAS,aAAa,eAAuB,SAAuB,IAAY;AACnF,SAAO,IAAI,UAAU;AAAA,IACjB,GAAG;AAAA,IACH,MAAM,OAAO,QAAQ,OAAO,aAAa;AAAA,EAAA,CAC5C;AACL;AAQO,SAAS,uBAAuB,QAA8B;AACjE,SAAO,IAAI,UAAU,MAAM;AAC/B;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wsxjs/wsx-logger",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "WSXJS Logger - Browser-optimized logging utility for WSXJS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -19,9 +19,7 @@
19
19
  "!**/__tests__",
20
20
  "!**/test"
21
21
  ],
22
- "dependencies": {
23
- "loglevel": "^1.9.1"
24
- },
22
+ "dependencies": {},
25
23
  "devDependencies": {
26
24
  "@types/node": "^20.0.0",
27
25
  "@typescript-eslint/eslint-plugin": "^8.37.0",
@@ -33,10 +31,11 @@
33
31
  "keywords": [
34
32
  "wsx",
35
33
  "logger",
36
- "loglevel",
37
34
  "logging",
38
35
  "web-components",
39
- "browser"
36
+ "browser",
37
+ "zero-dependencies",
38
+ "native"
40
39
  ],
41
40
  "author": "WSXJS Team",
42
41
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * @wsxjs/wsx-logger
3
3
  * Browser-optimized logging utility for WSXJS
4
+ *
5
+ * Pure native browser implementation - zero dependencies
6
+ * Uses native console API for maximum compatibility and minimal bundle size
4
7
  */
5
8
 
6
- import log from "loglevel";
7
-
8
9
  export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "silent";
9
10
 
10
11
  /**
@@ -32,27 +33,15 @@ export interface LoggerConfig {
32
33
  }
33
34
 
34
35
  /**
35
- * Map WSXJS log levels to loglevel string levels
36
- */
37
- const LOG_LEVEL_MAP: Record<LogLevel, log.LogLevelDesc> = {
38
- trace: "trace",
39
- debug: "debug",
40
- info: "info",
41
- warn: "warn",
42
- error: "error",
43
- silent: "silent",
44
- };
45
-
46
- /**
47
- * Map loglevel numeric levels to WSXJS log levels
36
+ * Log level hierarchy (numeric values for comparison)
48
37
  */
49
- const NUMERIC_TO_LEVEL: Record<number, LogLevel> = {
50
- 0: "trace",
51
- 1: "debug",
52
- 2: "info",
53
- 3: "warn",
54
- 4: "error",
55
- 5: "silent",
38
+ const LOG_LEVEL_VALUES: Record<LogLevel, number> = {
39
+ trace: 0,
40
+ debug: 1,
41
+ info: 2,
42
+ warn: 3,
43
+ error: 4,
44
+ silent: 5,
56
45
  };
57
46
 
58
47
  /**
@@ -87,23 +76,6 @@ const DEFAULT_CONFIG: LoggerConfig = {
87
76
  pretty: !isProduction(),
88
77
  };
89
78
 
90
- /**
91
- * Create a loglevel logger instance with prefix support
92
- */
93
- function createLoglevelLogger(config: LoggerConfig = {}): log.Logger {
94
- const { name, level } = { ...DEFAULT_CONFIG, ...config };
95
-
96
- // Create a new logger instance for this component
97
- const loggerName = name || DEFAULT_CONFIG.name || "WSX";
98
- const loggerInstance = log.getLogger(loggerName);
99
-
100
- // Set the log level
101
- const targetLevel = level || DEFAULT_CONFIG.level || "info";
102
- loggerInstance.setLevel(LOG_LEVEL_MAP[targetLevel]);
103
-
104
- return loggerInstance;
105
- }
106
-
107
79
  /**
108
80
  * Format log message with prefix
109
81
  */
@@ -112,21 +84,43 @@ function formatMessage(name: string, message: string): string {
112
84
  }
113
85
 
114
86
  /**
115
- * WSX Logger wrapper that implements the Logger interface
116
- * and uses loglevel under the hood
87
+ * Native browser logger implementation using console API
88
+ * Zero dependencies, perfect browser compatibility
117
89
  */
118
- export class WSXLogger implements Logger {
119
- private logInstance: log.Logger;
90
+ class NativeLogger {
120
91
  private name: string;
92
+ private level: LogLevel;
93
+ private levelValue: number;
121
94
  private isProd: boolean;
122
- private currentLevel: LogLevel;
123
95
 
124
- constructor(config: LoggerConfig = {}) {
96
+ constructor(name: string, level: LogLevel) {
97
+ this.name = name;
98
+ this.level = level;
99
+ this.levelValue = LOG_LEVEL_VALUES[level];
125
100
  this.isProd = isProduction();
126
- this.name = config.name || DEFAULT_CONFIG.name || "WSX";
127
- this.currentLevel =
128
- config.level || DEFAULT_CONFIG.level || (this.isProd ? "info" : "debug");
129
- this.logInstance = createLoglevelLogger(config);
101
+ }
102
+
103
+ /**
104
+ * Check if a log level should be logged
105
+ */
106
+ private shouldLog(level: LogLevel): boolean {
107
+ if (this.level === "silent") {
108
+ return false;
109
+ }
110
+ return LOG_LEVEL_VALUES[level] >= this.levelValue;
111
+ }
112
+
113
+ trace(message: string, ...args: unknown[]): void {
114
+ // Trace is only shown in non-production or if explicitly enabled
115
+ if (!this.isProd || this.shouldLog("trace")) {
116
+ const formattedMessage = formatMessage(this.name, message);
117
+ // Use console.debug for trace (browsers don't have console.trace as a log method)
118
+ if (args.length > 0) {
119
+ console.debug(formattedMessage, ...args);
120
+ } else {
121
+ console.debug(formattedMessage);
122
+ }
123
+ }
130
124
  }
131
125
 
132
126
  debug(message: string, ...args: unknown[]): void {
@@ -134,9 +128,9 @@ export class WSXLogger implements Logger {
134
128
  if (!this.isProd || this.shouldLog("debug")) {
135
129
  const formattedMessage = formatMessage(this.name, message);
136
130
  if (args.length > 0) {
137
- this.logInstance.debug(formattedMessage, ...args);
131
+ console.debug(formattedMessage, ...args);
138
132
  } else {
139
- this.logInstance.debug(formattedMessage);
133
+ console.debug(formattedMessage);
140
134
  }
141
135
  }
142
136
  }
@@ -145,71 +139,97 @@ export class WSXLogger implements Logger {
145
139
  if (this.shouldLog("info")) {
146
140
  const formattedMessage = formatMessage(this.name, message);
147
141
  if (args.length > 0) {
148
- this.logInstance.info(formattedMessage, ...args);
142
+ console.info(formattedMessage, ...args);
149
143
  } else {
150
- this.logInstance.info(formattedMessage);
144
+ console.info(formattedMessage);
151
145
  }
152
146
  }
153
147
  }
154
148
 
155
149
  warn(message: string, ...args: unknown[]): void {
156
150
  // Always show warnings (in both production and development)
157
- const formattedMessage = formatMessage(this.name, message);
158
- if (args.length > 0) {
159
- this.logInstance.warn(formattedMessage, ...args);
160
- } else {
161
- this.logInstance.warn(formattedMessage);
151
+ if (this.shouldLog("warn")) {
152
+ const formattedMessage = formatMessage(this.name, message);
153
+ if (args.length > 0) {
154
+ console.warn(formattedMessage, ...args);
155
+ } else {
156
+ console.warn(formattedMessage);
157
+ }
162
158
  }
163
159
  }
164
160
 
165
161
  error(message: string, ...args: unknown[]): void {
166
162
  // Always show errors (in both production and development)
167
- const formattedMessage = formatMessage(this.name, message);
168
- if (args.length > 0) {
169
- this.logInstance.error(formattedMessage, ...args);
170
- } else {
171
- this.logInstance.error(formattedMessage);
172
- }
173
- }
174
-
175
- fatal(message: string, ...args: unknown[]): void {
176
- // Fatal is treated as error in loglevel
177
- const formattedMessage = formatMessage(this.name, message);
178
- if (args.length > 0) {
179
- this.logInstance.error(`[FATAL] ${formattedMessage}`, ...args);
180
- } else {
181
- this.logInstance.error(`[FATAL] ${formattedMessage}`);
182
- }
183
- }
184
-
185
- trace(message: string, ...args: unknown[]): void {
186
- // Always show trace logs in non-production environments
187
- if (!this.isProd || this.shouldLog("trace")) {
163
+ if (this.shouldLog("error")) {
188
164
  const formattedMessage = formatMessage(this.name, message);
189
165
  if (args.length > 0) {
190
- this.logInstance.trace(formattedMessage, ...args);
166
+ console.error(formattedMessage, ...args);
191
167
  } else {
192
- this.logInstance.trace(formattedMessage);
168
+ console.error(formattedMessage);
193
169
  }
194
170
  }
195
171
  }
196
172
 
197
173
  /**
198
- * Check if a log level should be logged based on current level
174
+ * Set the log level dynamically
199
175
  */
200
- private shouldLog(level: LogLevel): boolean {
201
- const levels: LogLevel[] = ["trace", "debug", "info", "warn", "error", "silent"];
202
- const currentLevelIndex = levels.indexOf(this.currentLevel);
203
- const messageLevelIndex = levels.indexOf(level);
204
-
205
- return messageLevelIndex >= currentLevelIndex;
176
+ setLevel(level: LogLevel): void {
177
+ this.level = level;
178
+ this.levelValue = LOG_LEVEL_VALUES[level];
206
179
  }
207
180
 
208
181
  /**
209
- * Get the underlying loglevel logger instance
182
+ * Get the current log level
210
183
  */
211
- getLoglevelLogger(): log.Logger {
212
- return this.logInstance;
184
+ getLevel(): LogLevel {
185
+ return this.level;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * WSX Logger wrapper that implements the Logger interface
191
+ * Uses native browser console API - zero dependencies
192
+ */
193
+ export class WSXLogger implements Logger {
194
+ private nativeLogger: NativeLogger;
195
+ private name: string;
196
+ private currentLevel: LogLevel;
197
+
198
+ constructor(config: LoggerConfig = {}) {
199
+ this.name = config.name || DEFAULT_CONFIG.name || "WSX";
200
+ this.currentLevel =
201
+ config.level || DEFAULT_CONFIG.level || (isProduction() ? "info" : "debug");
202
+ this.nativeLogger = new NativeLogger(this.name, this.currentLevel);
203
+ }
204
+
205
+ debug(message: string, ...args: unknown[]): void {
206
+ this.nativeLogger.debug(message, ...args);
207
+ }
208
+
209
+ info(message: string, ...args: unknown[]): void {
210
+ this.nativeLogger.info(message, ...args);
211
+ }
212
+
213
+ warn(message: string, ...args: unknown[]): void {
214
+ this.nativeLogger.warn(message, ...args);
215
+ }
216
+
217
+ error(message: string, ...args: unknown[]): void {
218
+ this.nativeLogger.error(message, ...args);
219
+ }
220
+
221
+ fatal(message: string, ...args: unknown[]): void {
222
+ // Fatal is treated as error with [FATAL] prefix
223
+ const formattedMessage = formatMessage(this.name, `[FATAL] ${message}`);
224
+ if (args.length > 0) {
225
+ console.error(formattedMessage, ...args);
226
+ } else {
227
+ console.error(formattedMessage);
228
+ }
229
+ }
230
+
231
+ trace(message: string, ...args: unknown[]): void {
232
+ this.nativeLogger.trace(message, ...args);
213
233
  }
214
234
 
215
235
  /**
@@ -217,15 +237,14 @@ export class WSXLogger implements Logger {
217
237
  */
218
238
  setLevel(level: LogLevel): void {
219
239
  this.currentLevel = level;
220
- this.logInstance.setLevel(LOG_LEVEL_MAP[level] as log.LogLevelDesc);
240
+ this.nativeLogger.setLevel(level);
221
241
  }
222
242
 
223
243
  /**
224
244
  * Get the current log level
225
245
  */
226
246
  getLevel(): LogLevel {
227
- const numericLevel = this.logInstance.getLevel();
228
- return NUMERIC_TO_LEVEL[numericLevel] || this.currentLevel;
247
+ return this.nativeLogger.getLevel();
229
248
  }
230
249
  }
231
250
 
@@ -257,7 +276,3 @@ export function createLogger(componentName: string, config: LoggerConfig = {}):
257
276
  export function createLoggerWithConfig(config: LoggerConfig): Logger {
258
277
  return new WSXLogger(config);
259
278
  }
260
-
261
- // Export loglevel types for advanced usage
262
- export type { Logger as LoglevelLogger } from "loglevel";
263
- export { log as loglevel } from "loglevel";