logan-logger 1.1.2 → 1.1.6

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/browser.d.ts CHANGED
@@ -1,335 +1,25 @@
1
- declare abstract class BaseLogger implements ILogger {
2
- protected level: LogLevel;
3
- protected config: Partial<LoggerConfig>;
4
- protected runtime: RuntimeName;
5
- protected childMetadata: Record<string, any>;
6
- protected constructor(config?: Partial<LoggerConfig>);
7
- debug(message: LogMessage, metadata?: any): void;
8
- info(message: LogMessage, metadata?: any): void;
9
- warn(message: LogMessage, metadata?: any): void;
10
- error(message: LogMessage, metadata?: any): void;
11
- log(level: LogLevel, message: LogMessage, metadata?: any): void;
12
- setLevel(level: LogLevel): void;
13
- getLevel(): LogLevel;
14
- child(metadata: Record<string, any>): ILogger;
15
- protected shouldLog(level: LogLevel): boolean;
16
- protected abstract writeLog(entry: LogEntry): void;
17
- protected abstract createChild(): BaseLogger;
18
- }
19
-
20
- export declare class BrowserLogger extends BaseLogger {
21
- constructor(config?: Partial<LoggerConfig>);
22
- protected writeLog(entry: LogEntry): void;
23
- protected createChild(): BaseLogger;
24
- private formatMessage;
25
- private getConsoleStyle;
26
- private shouldLogInProduction;
27
- protected shouldLog(level: LogLevel): boolean;
28
- }
29
-
30
- export declare class ConsoleGroupLogger extends BrowserLogger {
31
- private groupStack;
32
- group(label: string): void;
33
- groupCollapsed(label: string): void;
34
- groupEnd(): void;
35
- getCurrentGroupStack(): string[];
36
- getCurrentGroupPath(): string;
37
- time(label: string): void;
38
- timeEnd(label: string): void;
39
- trace(message: string, metadata?: any): void;
40
- count(label?: string): void;
41
- countReset(label?: string): void;
42
- table(data: any): void;
43
- }
44
-
45
- /**
46
- * Convenience function for creating a logger instance.
47
- * @param config - Optional configuration for the logger
48
- * @returns A logger instance appropriate for the current runtime
49
- * @example
50
- * ```typescript
51
- * import { createLogger, LogLevel } from 'logan-logger';
52
- *
53
- * const logger = createLogger({
54
- * level: LogLevel.DEBUG,
55
- * colorize: true
56
- * });
57
- *
58
- * logger.info('Hello world!');
59
- * ```
60
- */
61
- export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
62
-
63
- /**
64
- * Create a logger with configuration based on the current environment.
65
- * Automatically detects production/development/test environments and
66
- * sets appropriate log levels and formatting.
67
- * @returns A logger instance configured for the current environment
68
- */
69
- export declare function createLoggerForEnvironment(): ILogger;
70
-
71
- /**
72
- * Detects the current JavaScript runtime environment and its capabilities.
73
- * @returns Information about the detected runtime
74
- * @example
75
- * ```typescript
76
- * const runtime = detectRuntime();
77
- * console.log(`Running on: ${runtime.name} ${runtime.version}`);
78
- * ```
79
- */
80
- export declare function detectRuntime(): RuntimeInfo;
81
-
82
- /**
83
- * Filter out sensitive data from an object before logging.
84
- * @param obj - The object to filter
85
- * @param sensitiveKeys - Array of key names to redact (case-insensitive)
86
- * @returns A new object with sensitive values replaced with '[REDACTED]'
87
- * @example
88
- * ```typescript
89
- * const data = { username: 'john', password: 'secret123' };
90
- * const filtered = filterSensitiveData(data);
91
- * // Result: { username: 'john', password: '[REDACTED]' }
92
- * ```
93
- */
94
- export declare function filterSensitiveData(obj: any, sensitiveKeys?: string[]): any;
95
-
96
- /**
97
- * Format log level as a colored string for terminal output.
98
- * @param level - The log level to format
99
- * @param colorize - Whether to apply ANSI color codes
100
- * @returns Formatted level string with optional colors
101
- */
102
- export declare function formatLevel(level: LogLevel, colorize?: boolean): string;
103
-
104
- /**
105
- * Format a log entry for output in different formats.
106
- * @param entry - The log entry to format
107
- * @param format - Output format ('json' or 'text')
108
- * @returns Formatted log string
109
- * @example
110
- * ```typescript
111
- * const entry: LogEntry = {
112
- * timestamp: new Date(),
113
- * level: LogLevel.INFO,
114
- * message: 'User logged in',
115
- * metadata: { userId: 123 },
116
- * runtime: 'node'
117
- * };
118
- *
119
- * const textFormat = formatLogEntry(entry, 'text');
120
- * // Result: "[2024-01-01T12:00:00.000Z] INFO: User logged in {\"userId\":123}"
121
- *
122
- * const jsonFormat = formatLogEntry(entry, 'json');
123
- * // Result: {"timestamp":"2024-01-01T12:00:00.000Z","level":"info","message":"User logged in","metadata":{"userId":123},"runtime":"node"}
124
- * ```
125
- */
126
- export declare function formatLogEntry(entry: LogEntry, format?: 'json' | 'text'): string;
127
-
128
- /**
129
- * Main logger interface providing methods for logging at different levels.
130
- * This interface is implemented by all logger implementations across different runtimes.
131
- */
132
- export declare interface ILogger {
133
- /**
134
- * Log a debug message. Only shown when log level is DEBUG.
135
- * @param message - The message to log (string or lazy function)
136
- * @param metadata - Optional structured data to include
137
- */
138
- debug(message: LogMessage, metadata?: any): void;
139
- /**
140
- * Log an informational message.
141
- * @param message - The message to log (string or lazy function)
142
- * @param metadata - Optional structured data to include
143
- */
144
- info(message: LogMessage, metadata?: any): void;
145
- /**
146
- * Log a warning message.
147
- * @param message - The message to log (string or lazy function)
148
- * @param metadata - Optional structured data to include
149
- */
150
- warn(message: LogMessage, metadata?: any): void;
151
- /**
152
- * Log an error message.
153
- * @param message - The message to log (string or lazy function)
154
- * @param metadata - Optional structured data to include
155
- */
156
- error(message: LogMessage, metadata?: any): void;
157
- /**
158
- * Log a message at a specific level.
159
- * @param level - The log level
160
- * @param message - The message to log (string or lazy function)
161
- * @param metadata - Optional structured data to include
162
- */
163
- log(level: LogLevel, message: LogMessage, metadata?: any): void;
164
- /**
165
- * Set the minimum log level for this logger.
166
- * @param level - The minimum log level
167
- */
168
- setLevel(level: LogLevel): void;
169
- /**
170
- * Get the current minimum log level.
171
- * @returns The current log level
172
- */
173
- getLevel(): LogLevel;
174
- /**
175
- * Create a child logger with additional metadata.
176
- * @param metadata - Additional metadata to include in all child log messages
177
- * @returns A new logger instance with the additional metadata
178
- */
179
- child(metadata: Record<string, any>): ILogger;
180
- }
181
-
182
- /**
183
- * Check if the current runtime is a browser.
184
- * @returns True if running in a browser
185
- */
186
- export declare function isBrowser(): boolean;
187
-
188
- /**
189
- * Check if the current runtime is Bun.
190
- * @returns True if running in Bun
191
- */
192
- export declare function isBun(): boolean;
193
-
194
- /**
195
- * Check if the current runtime is Deno.
196
- * @returns True if running in Deno
197
- */
198
- export declare function isDeno(): boolean;
199
-
200
- /**
201
- * Check if the current runtime is Node.js.
202
- * @returns True if running in Node.js
203
- */
204
- export declare function isNode(): boolean;
205
-
206
- /**
207
- * Internal representation of a log entry.
208
- */
209
- declare interface LogEntry {
210
- /** When the log entry was created */
211
- timestamp: Date;
212
- /** Log level of this entry */
213
- level: LogLevel;
214
- /** The log message */
215
- message: string;
216
- /** Additional structured data */
217
- metadata?: Record<string, any>;
218
- /** Runtime that generated this log entry */
219
- runtime: RuntimeName;
220
- }
221
-
222
- /**
223
- * Configuration options for creating a logger instance.
224
- */
225
- export declare interface LoggerConfig {
226
- /** Minimum log level to output */
227
- level: LogLevel;
228
- /** Output format for log messages */
229
- format: 'json' | 'text' | 'custom';
230
- /** Whether to include timestamps in log output */
231
- timestamp: boolean;
232
- /** Whether to colorize log output (if supported) */
233
- colorize: boolean;
234
- /** Default metadata to include with all log messages */
235
- metadata: Record<string, any>;
236
- /** Transport configurations for log output */
237
- transports?: TransportConfig[];
238
- }
239
-
240
- /**
241
- * Log levels in ascending order of severity.
242
- * Used to filter which messages should be logged.
243
- */
244
- export declare enum LogLevel {
245
- /** Debug messages - most verbose */
246
- DEBUG = 0,
247
- /** Informational messages */
248
- INFO = 1,
249
- /** Warning messages */
250
- WARN = 2,
251
- /** Error messages */
252
- ERROR = 3,
253
- /** No messages - silent mode */
254
- SILENT = 4
255
- }
256
-
257
- /**
258
- * A log message can be a string or a function that returns a string.
259
- * Functions enable lazy evaluation for expensive log message generation.
260
- */
261
- declare type LogMessage = string | (() => string);
262
-
263
- export declare class PerformanceLogger extends BrowserLogger {
264
- mark(name: string): void;
265
- measure(name: string, startMark?: string, endMark?: string): void;
266
- clearMarks(name?: string): void;
267
- clearMeasures(name?: string): void;
268
- }
269
-
270
- /**
271
- * Capabilities that a runtime may or may not support.
272
- */
273
- declare interface RuntimeCapabilities {
274
- /** Whether the runtime supports file system operations */
275
- fileSystem: boolean;
276
- /** Whether the runtime supports colored console output */
277
- colorSupport: boolean;
278
- /** Whether the runtime provides process information */
279
- processInfo: boolean;
280
- /** Whether the runtime supports streams */
281
- streams: boolean;
282
- }
283
-
284
- /**
285
- * Information about the detected JavaScript runtime environment.
286
- */
287
- declare interface RuntimeInfo {
288
- /** The name of the runtime */
289
- name: RuntimeName;
290
- /** Version string of the runtime (if available) */
291
- version?: string;
292
- /** Capabilities supported by this runtime */
293
- capabilities: RuntimeCapabilities;
294
- }
295
-
296
- /**
297
- * Supported JavaScript runtime environments.
298
- */
299
- declare type RuntimeName = 'node' | 'deno' | 'bun' | 'browser' | 'webworker' | 'unknown';
300
-
301
- /**
302
- * Safely stringify an object to JSON, handling circular references,
303
- * Error objects, functions, and other non-serializable values.
304
- * @param obj - The object to stringify
305
- * @param space - Number of spaces for pretty-printing (optional)
306
- * @returns JSON string representation
307
- */
308
- export declare function safeStringify(obj: any, space?: number): string;
309
-
310
- /**
311
- * Serialize Error objects to plain objects for logging.
312
- * @param error - The error to serialize
313
- * @returns Serialized error object or original value if not an Error
314
- * @example
315
- * ```typescript
316
- * const error = new Error('Something went wrong');
317
- * const serialized = serializeError(error);
318
- * // Result: { name: 'Error', message: 'Something went wrong', stack: '...' }
319
- * ```
320
- */
321
- export declare function serializeError(error: any): any;
322
-
323
- /**
324
- * Configuration for a specific log transport (output destination).
325
- */
326
- declare interface TransportConfig {
327
- /** Type of transport */
328
- type: 'console' | 'file' | 'http' | 'custom';
329
- /** Minimum log level for this transport */
330
- level?: LogLevel;
331
- /** Transport-specific options */
332
- options: Record<string, any>;
333
- }
334
-
335
- export { }
1
+ import { LoggerConfig, ILogger } from './core/types';
2
+ export { BrowserLogger, ConsoleGroupLogger, PerformanceLogger } from './runtime/browser';
3
+ export type { ILogger, LoggerConfig } from './core/types';
4
+ export { LogLevel } from './core/types';
5
+ export * from './utils/runtime';
6
+ export * from './utils/serialization';
7
+ export * from './utils/formatting';
8
+ /**
9
+ * Browser-specific logger factory function.
10
+ * Creates a BrowserLogger instance without importing Node.js dependencies.
11
+ */
12
+ export declare function createLogger(config?: Partial<LoggerConfig>): ILogger;
13
+ /**
14
+ * Create a browser logger with configuration based on the current environment.
15
+ * Automatically detects production/development/test environments and
16
+ * sets appropriate log levels and formatting.
17
+ */
18
+ export declare function createLoggerForEnvironment(): ILogger;
19
+ export declare const logger: ILogger;
20
+ export declare const log: {
21
+ debug: (message: string, meta?: any) => void;
22
+ info: (message: string, meta?: any) => void;
23
+ warn: (message: string, meta?: any) => void;
24
+ error: (message: string, meta?: any) => void;
25
+ };
@@ -1,19 +1,82 @@
1
- import { B as o, C as a, P as s, a as t, c as i, e as g, p as n, f, h as m, g as L, i as c, o as l, q as p } from "./node-BqvVrzA_.mjs";
2
- import { formatLevel as u, formatLogEntry as v } from "./deno.esm.js";
1
+ import { L as o, B as s, d as a } from "./browser-C6UkWymL.mjs";
2
+ import { C as v, P as E, f as L, a as N, c as w, b as B, i as _, s as C, e as R } from "./browser-C6UkWymL.mjs";
3
+ import { a as x, f as y } from "./formatting-BZyid6rr.mjs";
4
+ function i() {
5
+ const e = a();
6
+ return {
7
+ level: o.INFO,
8
+ format: "text",
9
+ timestamp: !0,
10
+ colorize: e.capabilities.colorSupport,
11
+ metadata: {},
12
+ transports: [
13
+ {
14
+ type: "console",
15
+ options: {}
16
+ }
17
+ ]
18
+ };
19
+ }
20
+ function c() {
21
+ return typeof process < "u" && process.env ? process.env.NODE_ENV || process.env.NEXT_PUBLIC_APP_ENV || process.env.ENVIRONMENT || "development" : typeof window < "u" && globalThis.__ENV__ || "development";
22
+ }
23
+ function f(e) {
24
+ switch (e) {
25
+ case "production":
26
+ return o.ERROR;
27
+ case "staging":
28
+ case "test":
29
+ return o.WARN;
30
+ case "development":
31
+ case "dev":
32
+ return o.DEBUG;
33
+ default:
34
+ return o.INFO;
35
+ }
36
+ }
37
+ function u(e = {}) {
38
+ const r = i(), n = {
39
+ ...r,
40
+ ...e,
41
+ metadata: {
42
+ ...r.metadata,
43
+ ...e.metadata
44
+ }
45
+ };
46
+ return new s(n);
47
+ }
48
+ function g() {
49
+ const e = c(), r = {
50
+ level: f(e),
51
+ colorize: e !== "production",
52
+ timestamp: !0,
53
+ format: e === "production" ? "json" : "text"
54
+ };
55
+ return u(r);
56
+ }
57
+ const t = g(), p = {
58
+ debug: (e, r) => t.debug(e, r),
59
+ info: (e, r) => t.info(e, r),
60
+ warn: (e, r) => t.warn(e, r),
61
+ error: (e, r) => t.error(e, r)
62
+ };
3
63
  export {
4
- o as BrowserLogger,
5
- a as ConsoleGroupLogger,
6
- s as PerformanceLogger,
7
- t as createLogger,
8
- i as createLoggerForEnvironment,
9
- g as detectRuntime,
10
- n as filterSensitiveData,
11
- u as formatLevel,
12
- v as formatLogEntry,
13
- f as isBrowser,
14
- m as isBun,
15
- L as isDeno,
16
- c as isNode,
17
- l as safeStringify,
18
- p as serializeError
64
+ s as BrowserLogger,
65
+ v as ConsoleGroupLogger,
66
+ o as LogLevel,
67
+ E as PerformanceLogger,
68
+ u as createLogger,
69
+ g as createLoggerForEnvironment,
70
+ a as detectRuntime,
71
+ L as filterSensitiveData,
72
+ x as formatLevel,
73
+ y as formatLogEntry,
74
+ N as isBrowser,
75
+ w as isBun,
76
+ B as isDeno,
77
+ _ as isNode,
78
+ p as log,
79
+ t as logger,
80
+ C as safeStringify,
81
+ R as serializeError
19
82
  };
package/dist/browser.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./node-BKsollr4.js"),r=require("./deno.js");exports.BrowserLogger=e.BrowserLogger;exports.ConsoleGroupLogger=e.ConsoleGroupLogger;exports.PerformanceLogger=e.PerformanceLogger;exports.createLogger=e.createLogger;exports.createLoggerForEnvironment=e.createLoggerForEnvironment;exports.detectRuntime=e.detectRuntime;exports.filterSensitiveData=e.filterSensitiveData;exports.isBrowser=e.isBrowser;exports.isBun=e.isBun;exports.isDeno=e.isDeno;exports.isNode=e.isNode;exports.safeStringify=e.safeStringify;exports.serializeError=e.serializeError;exports.formatLevel=r.formatLevel;exports.formatLogEntry=r.formatLogEntry;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./browser-BzeNXjes.js"),n=require("./formatting-BDuKuXIh.js");function a(){const r=e.detectRuntime();return{level:e.LogLevel.INFO,format:"text",timestamp:!0,colorize:r.capabilities.colorSupport,metadata:{},transports:[{type:"console",options:{}}]}}function c(){return typeof process<"u"&&process.env?process.env.NODE_ENV||process.env.NEXT_PUBLIC_APP_ENV||process.env.ENVIRONMENT||"development":typeof window<"u"&&globalThis.__ENV__||"development"}function l(r){switch(r){case"production":return e.LogLevel.ERROR;case"staging":case"test":return e.LogLevel.WARN;case"development":case"dev":return e.LogLevel.DEBUG;default:return e.LogLevel.INFO}}function i(r={}){const o=a(),g={...o,...r,metadata:{...o.metadata,...r.metadata}};return new e.BrowserLogger(g)}function s(){const r=c(),o={level:l(r),colorize:r!=="production",timestamp:!0,format:r==="production"?"json":"text"};return i(o)}const t=s(),u={debug:(r,o)=>t.debug(r,o),info:(r,o)=>t.info(r,o),warn:(r,o)=>t.warn(r,o),error:(r,o)=>t.error(r,o)};exports.BrowserLogger=e.BrowserLogger;exports.ConsoleGroupLogger=e.ConsoleGroupLogger;exports.LogLevel=e.LogLevel;exports.PerformanceLogger=e.PerformanceLogger;exports.detectRuntime=e.detectRuntime;exports.filterSensitiveData=e.filterSensitiveData;exports.isBrowser=e.isBrowser;exports.isBun=e.isBun;exports.isDeno=e.isDeno;exports.isNode=e.isNode;exports.safeStringify=e.safeStringify;exports.serializeError=e.serializeError;exports.formatLevel=n.formatLevel;exports.formatLogEntry=n.formatLogEntry;exports.createLogger=i;exports.createLoggerForEnvironment=s;exports.log=u;exports.logger=t;