@agimon-ai/foundation-universal-logger 0.2.0
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/LICENSE +52 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/logger.cjs +2 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +49 -0
- package/dist/logger.d.ts +49 -0
- package/dist/logger.js +2 -0
- package/dist/logger.js.map +1 -0
- package/dist/logger2.d.cts +27 -0
- package/dist/logger2.d.ts +27 -0
- package/dist/transports/console.cjs +2 -0
- package/dist/transports/console.cjs.map +1 -0
- package/dist/transports/console.d.cts +11 -0
- package/dist/transports/console.d.ts +11 -0
- package/dist/transports/console.js +2 -0
- package/dist/transports/console.js.map +1 -0
- package/dist/utils/logFilter.cjs +2 -0
- package/dist/utils/logFilter.cjs.map +1 -0
- package/dist/utils/logFilter.d.cts +20 -0
- package/dist/utils/logFilter.d.ts +20 -0
- package/dist/utils/logFilter.js +2 -0
- package/dist/utils/logFilter.js.map +1 -0
- package/dist/utils/logFormatter.cjs +2 -0
- package/dist/utils/logFormatter.cjs.map +1 -0
- package/dist/utils/logFormatter.d.cts +12 -0
- package/dist/utils/logFormatter.d.ts +12 -0
- package/dist/utils/logFormatter.js +2 -0
- package/dist/utils/logFormatter.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters
|
|
4
|
+
|
|
5
|
+
Licensor: AgiFlow
|
|
6
|
+
Licensed Work: @agimon-ai/public-packages
|
|
7
|
+
The Licensed Work is (c) 2026 AgiFlow.
|
|
8
|
+
Additional Use Grant: None
|
|
9
|
+
Change Date: 2030-03-06
|
|
10
|
+
Change License: Apache License, Version 2.0
|
|
11
|
+
|
|
12
|
+
Terms
|
|
13
|
+
|
|
14
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
15
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
16
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
17
|
+
production use.
|
|
18
|
+
|
|
19
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
20
|
+
available distribution of a specific version of the Licensed Work under this
|
|
21
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
22
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
23
|
+
above terminate.
|
|
24
|
+
|
|
25
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
26
|
+
currently in effect as described in this License, you must purchase a
|
|
27
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
28
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
29
|
+
|
|
30
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
31
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
32
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
33
|
+
for each version of the Licensed Work released by Licensor.
|
|
34
|
+
|
|
35
|
+
You must conspicuously display this License on each original or modified copy
|
|
36
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
37
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
38
|
+
License apply to your use of that work.
|
|
39
|
+
|
|
40
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
41
|
+
terminate your rights under this License for the current and all other
|
|
42
|
+
versions of the Licensed Work.
|
|
43
|
+
|
|
44
|
+
This License does not grant you any right in any trademark or logo of
|
|
45
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
46
|
+
Licensor as expressly required by this License).
|
|
47
|
+
|
|
48
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
49
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
50
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
51
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
52
|
+
TITLE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./utils/logFormatter.cjs`),t=require(`./transports/console.cjs`),n=require(`./utils/logFilter.cjs`),r=require(`./logger.cjs`);exports.CompositeLogFilter=n.CompositeLogFilter,exports.ConsoleTransport=t.ConsoleTransport,exports.DefaultLogFilter=n.DefaultLogFilter,exports.DefaultLogFormatter=e.DefaultLogFormatter,exports.JsonLogFormatter=e.JsonLogFormatter,exports.Logger=r.Logger,exports.RegexLogFilter=n.RegexLogFilter,exports.createLogger=r.createLogger;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { a as LogFormatter, c as Transport, i as LogFilter, l as UniversalLogger, n as LogContext, o as LogLevel, r as LogEntry, s as LoggerOptions, t as Environment } from "./logger.cjs";
|
|
2
|
+
import { Logger, createLogger } from "./logger2.cjs";
|
|
3
|
+
import { ConsoleTransport } from "./transports/console.cjs";
|
|
4
|
+
import { CompositeLogFilter, DefaultLogFilter, RegexLogFilter } from "./utils/logFilter.cjs";
|
|
5
|
+
import { DefaultLogFormatter, JsonLogFormatter } from "./utils/logFormatter.cjs";
|
|
6
|
+
export { CompositeLogFilter, ConsoleTransport, DefaultLogFilter, DefaultLogFormatter, type Environment, JsonLogFormatter, type LogContext, type LogEntry, type LogFilter, type LogFormatter, type LogLevel, Logger, type LoggerOptions, RegexLogFilter, type Transport, type UniversalLogger, createLogger };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { a as LogFormatter, c as Transport, i as LogFilter, l as UniversalLogger, n as LogContext, o as LogLevel, r as LogEntry, s as LoggerOptions, t as Environment } from "./logger.js";
|
|
2
|
+
import { Logger, createLogger } from "./logger2.js";
|
|
3
|
+
import { ConsoleTransport } from "./transports/console.js";
|
|
4
|
+
import { CompositeLogFilter, DefaultLogFilter, RegexLogFilter } from "./utils/logFilter.js";
|
|
5
|
+
import { DefaultLogFormatter, JsonLogFormatter } from "./utils/logFormatter.js";
|
|
6
|
+
export { CompositeLogFilter, ConsoleTransport, DefaultLogFilter, DefaultLogFormatter, type Environment, JsonLogFormatter, type LogContext, type LogEntry, type LogFilter, type LogFormatter, type LogLevel, Logger, type LoggerOptions, RegexLogFilter, type Transport, type UniversalLogger, createLogger };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DefaultLogFormatter as e,JsonLogFormatter as t}from"./utils/logFormatter.js";import{ConsoleTransport as n}from"./transports/console.js";import{CompositeLogFilter as r,DefaultLogFilter as i,RegexLogFilter as a}from"./utils/logFilter.js";import{Logger as o,createLogger as s}from"./logger.js";export{r as CompositeLogFilter,n as ConsoleTransport,i as DefaultLogFilter,e as DefaultLogFormatter,t as JsonLogFormatter,o as Logger,a as RegexLogFilter,s as createLogger};
|
package/dist/logger.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./transports/console.cjs`),t=require(`./utils/logFilter.cjs`);let n=require(`@opentelemetry/api`);const r={trace:10,debug:20,info:30,warn:40,error:50,fatal:60,silent:100};var i=class i{service;level;transports;context;filter;constructor(n){this.service=n?.service,this.level=n?.level||`info`,this.context=n?.context||{},this.filter=new t.DefaultLogFilter,this.transports=n?.transports&&n.transports.length>0?n.transports:[new e.ConsoleTransport]}shouldLog(e){return r[e]>=r[this.level]}async logEntry(e){if(!this.shouldLog(e.level)||!this.filter.shouldLog(e,this.level))return;let t={};try{let e=n.trace.getActiveSpan();if(e){let n=e.spanContext();n.traceId&&(t.traceId=n.traceId),n.spanId&&(t.spanId=n.spanId)}}catch{}let i={...e,context:{...this.context,...t,...e.context},service:this.service},a=this.transports.map(t=>{try{return t.level&&r[e.level]<r[t.level]?Promise.resolve():Promise.resolve(t.log(i))}catch(e){return console.error(`Transport error:`,e),Promise.resolve()}});await Promise.all(a)}parseArgs(e){let t,n;for(let r of e)r instanceof Error?n=r:typeof r==`object`&&r&&!Array.isArray(r)&&(t={...t,...r});return{context:t,error:n}}trace(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`trace`,message:e,timestamp:new Date,context:n,error:r})}debug(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`debug`,message:e,timestamp:new Date,context:n,error:r})}info(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`info`,message:e,timestamp:new Date,context:n,error:r})}warn(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`warn`,message:e,timestamp:new Date,context:n,error:r})}error(e,t,...n){let{context:r}=this.parseArgs(n);this.logEntry({level:`error`,message:e,timestamp:new Date,context:r,error:t})}fatal(e,t,...n){let{context:r}=this.parseArgs(n);this.logEntry({level:`fatal`,message:e,timestamp:new Date,context:r,error:t})}child(e){return new i({service:this.service,level:this.level,transports:this.transports,context:{...this.context,...e}})}setLevel(e){this.level=e}getLevel(){return this.level}};function a(e){return new i(e)}exports.Logger=i,exports.createLogger=a;
|
|
2
|
+
//# sourceMappingURL=logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.cjs","names":["DefaultLogFilter","ConsoleTransport","trace"],"sources":["../src/logger.ts"],"sourcesContent":["import { trace } from '@opentelemetry/api';\nimport { ConsoleTransport } from './transports/console';\nimport type {\n LogContext,\n LogEntry,\n LogFilter,\n LogLevel,\n LoggerOptions,\n Transport,\n UniversalLogger,\n} from './types/logger';\nimport { DefaultLogFilter } from './utils/logFilter';\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n trace: 10,\n debug: 20,\n info: 30,\n warn: 40,\n error: 50,\n fatal: 60,\n silent: 100,\n};\n\nexport class Logger implements UniversalLogger {\n private readonly service?: string;\n private level: LogLevel;\n private readonly transports: Transport[];\n private readonly context: LogContext;\n private readonly filter: LogFilter;\n\n constructor(options?: LoggerOptions) {\n this.service = options?.service;\n this.level = options?.level || 'info';\n this.context = options?.context || {};\n this.filter = new DefaultLogFilter();\n\n this.transports =\n options?.transports && options.transports.length > 0 ? options.transports : [new ConsoleTransport()];\n }\n\n private shouldLog(level: LogLevel): boolean {\n return LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private async logEntry(entry: LogEntry): Promise<void> {\n if (!this.shouldLog(entry.level)) {\n return;\n }\n\n if (!this.filter.shouldLog(entry, this.level)) {\n return;\n }\n\n const traceContext: LogContext = {};\n try {\n const activeSpan = trace.getActiveSpan();\n if (activeSpan) {\n const spanContext = activeSpan.spanContext();\n if (spanContext.traceId) {\n traceContext.traceId = spanContext.traceId;\n }\n if (spanContext.spanId) {\n traceContext.spanId = spanContext.spanId;\n }\n }\n } catch {\n // Gracefully handle cases where OTEL is not initialized\n }\n\n const fullEntry: LogEntry = {\n ...entry,\n context: {\n ...this.context,\n ...traceContext,\n ...entry.context,\n },\n service: this.service,\n };\n\n const promises = this.transports.map((transport) => {\n try {\n if (transport.level && LOG_LEVELS[entry.level] < LOG_LEVELS[transport.level]) {\n return Promise.resolve();\n }\n return Promise.resolve(transport.log(fullEntry));\n } catch (error) {\n console.error('Transport error:', error);\n return Promise.resolve();\n }\n });\n\n await Promise.all(promises);\n }\n\n private parseArgs(args: unknown[]): { context?: LogContext; error?: unknown } {\n let context: LogContext | undefined;\n let error: unknown;\n\n for (const arg of args) {\n if (arg instanceof Error) {\n error = arg;\n } else if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)) {\n context = { ...context, ...(arg as LogContext) };\n }\n }\n\n return { context, error };\n }\n\n trace(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'trace', message, timestamp: new Date(), context, error });\n }\n\n debug(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'debug', message, timestamp: new Date(), context, error });\n }\n\n info(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'info', message, timestamp: new Date(), context, error });\n }\n\n warn(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'warn', message, timestamp: new Date(), context, error });\n }\n\n error(message: string, error?: unknown, ...args: unknown[]): void {\n const { context } = this.parseArgs(args);\n void this.logEntry({ level: 'error', message, timestamp: new Date(), context, error });\n }\n\n fatal(message: string, error?: unknown, ...args: unknown[]): void {\n const { context } = this.parseArgs(args);\n void this.logEntry({ level: 'fatal', message, timestamp: new Date(), context, error });\n }\n\n child(childContext: LogContext): UniversalLogger {\n return new Logger({\n service: this.service,\n level: this.level,\n transports: this.transports,\n context: {\n ...this.context,\n ...childContext,\n },\n });\n }\n\n setLevel(level: LogLevel): void {\n this.level = level;\n }\n\n getLevel(): LogLevel {\n return this.level;\n }\n}\n\nexport function createLogger(options?: LoggerOptions): UniversalLogger {\n return new Logger(options);\n}\n"],"mappings":"sLAaA,MAAM,EAAuC,CAC3C,MAAO,GACP,MAAO,GACP,KAAM,GACN,KAAM,GACN,MAAO,GACP,MAAO,GACP,OAAQ,IACT,CAED,IAAa,EAAb,MAAa,CAAkC,CAC7C,QACA,MACA,WACA,QACA,OAEA,YAAY,EAAyB,CACnC,KAAK,QAAU,GAAS,QACxB,KAAK,MAAQ,GAAS,OAAS,OAC/B,KAAK,QAAU,GAAS,SAAW,EAAE,CACrC,KAAK,OAAS,IAAIA,EAAAA,iBAElB,KAAK,WACH,GAAS,YAAc,EAAQ,WAAW,OAAS,EAAI,EAAQ,WAAa,CAAC,IAAIC,EAAAA,iBAAmB,CAGxG,UAAkB,EAA0B,CAC1C,OAAO,EAAW,IAAU,EAAW,KAAK,OAG9C,MAAc,SAAS,EAAgC,CAKrD,GAJI,CAAC,KAAK,UAAU,EAAM,MAAM,EAI5B,CAAC,KAAK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AAS,SAAU,KAAK,UAAU,EAAK,CAC1C,KAAK,SAAS,CAAE,MAAO,OAAQ,UAAS,UAAW,IAAI,KAAQ,UAAS,QAAO,CAAC,CAGvF,KAAK,EAAiB,GAAG,EAAuB,CAC9C,GAAM,CAAE,UAAS,SAAU,KAAK,UAAU,EAAK,CAC1C,KAAK,SAAS,CAAE,MAAO,OAAQ,UAAS,UAAW,IAAI,KAAQ,UAAS,QAAO,CAAC,CAGvF,MAAM,EAAiB,EAAiB,GAAG,EAAuB,CAChE,GAAM,CAAE,WAAY,KAAK,UAAU,EAAK,CACnC,KAAK,SAAS,CAAE,MAAO,QAAS,UAAS,UAAW,IAAI,KAAQ,UAAS,QAAO,CAAC,CAGxF,MAAM,EAAiB,EAAiB,GAAG,EAAuB,CAChE,GAAM,CAAE,WAAY,KAAK,UAAU,EAAK,CACnC,KAAK,SAAS,CAAE,MAAO,QAAS,UAAS,UAAW,IAAI,KAAQ,UAAS,QAAO,CAAC,CAGxF,MAAM,EAA2C,CAC/C,OAAO,IAAI,EAAO,CAChB,QAAS,KAAK,QACd,MAAO,KAAK,MACZ,WAAY,KAAK,WACjB,QAAS,CACP,GAAG,KAAK,QACR,GAAG,EACJ,CACF,CAAC,CAGJ,SAAS,EAAuB,CAC9B,KAAK,MAAQ,EAGf,UAAqB,CACnB,OAAO,KAAK,QAIhB,SAAgB,EAAa,EAA0C,CACrE,OAAO,IAAI,EAAO,EAAQ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/types/logger.d.ts
|
|
2
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
|
|
3
|
+
type Environment = 'development' | 'production' | 'test';
|
|
4
|
+
interface LogContext {
|
|
5
|
+
traceId?: string;
|
|
6
|
+
spanId?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface LogEntry {
|
|
10
|
+
level: LogLevel;
|
|
11
|
+
message: string;
|
|
12
|
+
timestamp: Date;
|
|
13
|
+
context?: LogContext;
|
|
14
|
+
error?: unknown;
|
|
15
|
+
service?: string;
|
|
16
|
+
environment?: Environment;
|
|
17
|
+
}
|
|
18
|
+
interface Transport {
|
|
19
|
+
name: string;
|
|
20
|
+
log(entry: LogEntry): void | Promise<void>;
|
|
21
|
+
level?: LogLevel;
|
|
22
|
+
}
|
|
23
|
+
interface LoggerOptions {
|
|
24
|
+
service?: string;
|
|
25
|
+
level?: LogLevel;
|
|
26
|
+
environment?: Environment;
|
|
27
|
+
transports?: Transport[];
|
|
28
|
+
context?: LogContext;
|
|
29
|
+
}
|
|
30
|
+
interface UniversalLogger {
|
|
31
|
+
trace(message: string, ...args: unknown[]): void;
|
|
32
|
+
debug(message: string, ...args: unknown[]): void;
|
|
33
|
+
info(message: string, ...args: unknown[]): void;
|
|
34
|
+
warn(message: string, ...args: unknown[]): void;
|
|
35
|
+
error(message: string, error?: unknown, ...args: unknown[]): void;
|
|
36
|
+
fatal(message: string, error?: unknown, ...args: unknown[]): void;
|
|
37
|
+
child(context: LogContext): UniversalLogger;
|
|
38
|
+
setLevel(level: LogLevel): void;
|
|
39
|
+
getLevel(): LogLevel;
|
|
40
|
+
}
|
|
41
|
+
interface LogFormatter {
|
|
42
|
+
format(entry: LogEntry): string;
|
|
43
|
+
}
|
|
44
|
+
interface LogFilter {
|
|
45
|
+
shouldLog(entry: LogEntry, minLevel: LogLevel): boolean;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { LogFormatter as a, Transport as c, LogFilter as i, UniversalLogger as l, LogContext as n, LogLevel as o, LogEntry as r, LoggerOptions as s, Environment as t };
|
|
49
|
+
//# sourceMappingURL=logger.d.cts.map
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/types/logger.d.ts
|
|
2
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'silent';
|
|
3
|
+
type Environment = 'development' | 'production' | 'test';
|
|
4
|
+
interface LogContext {
|
|
5
|
+
traceId?: string;
|
|
6
|
+
spanId?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface LogEntry {
|
|
10
|
+
level: LogLevel;
|
|
11
|
+
message: string;
|
|
12
|
+
timestamp: Date;
|
|
13
|
+
context?: LogContext;
|
|
14
|
+
error?: unknown;
|
|
15
|
+
service?: string;
|
|
16
|
+
environment?: Environment;
|
|
17
|
+
}
|
|
18
|
+
interface Transport {
|
|
19
|
+
name: string;
|
|
20
|
+
log(entry: LogEntry): void | Promise<void>;
|
|
21
|
+
level?: LogLevel;
|
|
22
|
+
}
|
|
23
|
+
interface LoggerOptions {
|
|
24
|
+
service?: string;
|
|
25
|
+
level?: LogLevel;
|
|
26
|
+
environment?: Environment;
|
|
27
|
+
transports?: Transport[];
|
|
28
|
+
context?: LogContext;
|
|
29
|
+
}
|
|
30
|
+
interface UniversalLogger {
|
|
31
|
+
trace(message: string, ...args: unknown[]): void;
|
|
32
|
+
debug(message: string, ...args: unknown[]): void;
|
|
33
|
+
info(message: string, ...args: unknown[]): void;
|
|
34
|
+
warn(message: string, ...args: unknown[]): void;
|
|
35
|
+
error(message: string, error?: unknown, ...args: unknown[]): void;
|
|
36
|
+
fatal(message: string, error?: unknown, ...args: unknown[]): void;
|
|
37
|
+
child(context: LogContext): UniversalLogger;
|
|
38
|
+
setLevel(level: LogLevel): void;
|
|
39
|
+
getLevel(): LogLevel;
|
|
40
|
+
}
|
|
41
|
+
interface LogFormatter {
|
|
42
|
+
format(entry: LogEntry): string;
|
|
43
|
+
}
|
|
44
|
+
interface LogFilter {
|
|
45
|
+
shouldLog(entry: LogEntry, minLevel: LogLevel): boolean;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { LogFormatter as a, Transport as c, LogFilter as i, UniversalLogger as l, LogContext as n, LogLevel as o, LogEntry as r, LoggerOptions as s, Environment as t };
|
|
49
|
+
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ConsoleTransport as e}from"./transports/console.js";import{DefaultLogFilter as t}from"./utils/logFilter.js";import{trace as n}from"@opentelemetry/api";const r={trace:10,debug:20,info:30,warn:40,error:50,fatal:60,silent:100};var i=class i{service;level;transports;context;filter;constructor(n){this.service=n?.service,this.level=n?.level||`info`,this.context=n?.context||{},this.filter=new t,this.transports=n?.transports&&n.transports.length>0?n.transports:[new e]}shouldLog(e){return r[e]>=r[this.level]}async logEntry(e){if(!this.shouldLog(e.level)||!this.filter.shouldLog(e,this.level))return;let t={};try{let e=n.getActiveSpan();if(e){let n=e.spanContext();n.traceId&&(t.traceId=n.traceId),n.spanId&&(t.spanId=n.spanId)}}catch{}let i={...e,context:{...this.context,...t,...e.context},service:this.service},a=this.transports.map(t=>{try{return t.level&&r[e.level]<r[t.level]?Promise.resolve():Promise.resolve(t.log(i))}catch(e){return console.error(`Transport error:`,e),Promise.resolve()}});await Promise.all(a)}parseArgs(e){let t,n;for(let r of e)r instanceof Error?n=r:typeof r==`object`&&r&&!Array.isArray(r)&&(t={...t,...r});return{context:t,error:n}}trace(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`trace`,message:e,timestamp:new Date,context:n,error:r})}debug(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`debug`,message:e,timestamp:new Date,context:n,error:r})}info(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`info`,message:e,timestamp:new Date,context:n,error:r})}warn(e,...t){let{context:n,error:r}=this.parseArgs(t);this.logEntry({level:`warn`,message:e,timestamp:new Date,context:n,error:r})}error(e,t,...n){let{context:r}=this.parseArgs(n);this.logEntry({level:`error`,message:e,timestamp:new Date,context:r,error:t})}fatal(e,t,...n){let{context:r}=this.parseArgs(n);this.logEntry({level:`fatal`,message:e,timestamp:new Date,context:r,error:t})}child(e){return new i({service:this.service,level:this.level,transports:this.transports,context:{...this.context,...e}})}setLevel(e){this.level=e}getLevel(){return this.level}};function a(e){return new i(e)}export{i as Logger,a as createLogger};
|
|
2
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","names":[],"sources":["../src/logger.ts"],"sourcesContent":["import { trace } from '@opentelemetry/api';\nimport { ConsoleTransport } from './transports/console';\nimport type {\n LogContext,\n LogEntry,\n LogFilter,\n LogLevel,\n LoggerOptions,\n Transport,\n UniversalLogger,\n} from './types/logger';\nimport { DefaultLogFilter } from './utils/logFilter';\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n trace: 10,\n debug: 20,\n info: 30,\n warn: 40,\n error: 50,\n fatal: 60,\n silent: 100,\n};\n\nexport class Logger implements UniversalLogger {\n private readonly service?: string;\n private level: LogLevel;\n private readonly transports: Transport[];\n private readonly context: LogContext;\n private readonly filter: LogFilter;\n\n constructor(options?: LoggerOptions) {\n this.service = options?.service;\n this.level = options?.level || 'info';\n this.context = options?.context || {};\n this.filter = new DefaultLogFilter();\n\n this.transports =\n options?.transports && options.transports.length > 0 ? options.transports : [new ConsoleTransport()];\n }\n\n private shouldLog(level: LogLevel): boolean {\n return LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private async logEntry(entry: LogEntry): Promise<void> {\n if (!this.shouldLog(entry.level)) {\n return;\n }\n\n if (!this.filter.shouldLog(entry, this.level)) {\n return;\n }\n\n const traceContext: LogContext = {};\n try {\n const activeSpan = trace.getActiveSpan();\n if (activeSpan) {\n const spanContext = activeSpan.spanContext();\n if (spanContext.traceId) {\n traceContext.traceId = spanContext.traceId;\n }\n if (spanContext.spanId) {\n traceContext.spanId = spanContext.spanId;\n }\n }\n } catch {\n // Gracefully handle cases where OTEL is not initialized\n }\n\n const fullEntry: LogEntry = {\n ...entry,\n context: {\n ...this.context,\n ...traceContext,\n ...entry.context,\n },\n service: this.service,\n };\n\n const promises = this.transports.map((transport) => {\n try {\n if (transport.level && LOG_LEVELS[entry.level] < LOG_LEVELS[transport.level]) {\n return Promise.resolve();\n }\n return Promise.resolve(transport.log(fullEntry));\n } catch (error) {\n console.error('Transport error:', error);\n return Promise.resolve();\n }\n });\n\n await Promise.all(promises);\n }\n\n private parseArgs(args: unknown[]): { context?: LogContext; error?: unknown } {\n let context: LogContext | undefined;\n let error: unknown;\n\n for (const arg of args) {\n if (arg instanceof Error) {\n error = arg;\n } else if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)) {\n context = { ...context, ...(arg as LogContext) };\n }\n }\n\n return { context, error };\n }\n\n trace(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'trace', message, timestamp: new Date(), context, error });\n }\n\n debug(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'debug', message, timestamp: new Date(), context, error });\n }\n\n info(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'info', message, timestamp: new Date(), context, error });\n }\n\n warn(message: string, ...args: unknown[]): void {\n const { context, error } = this.parseArgs(args);\n void this.logEntry({ level: 'warn', message, timestamp: new Date(), context, error });\n }\n\n error(message: string, error?: unknown, ...args: unknown[]): void {\n const { context } = this.parseArgs(args);\n void this.logEntry({ level: 'error', message, timestamp: new Date(), context, error });\n }\n\n fatal(message: string, error?: unknown, ...args: unknown[]): void {\n const { context } = this.parseArgs(args);\n void this.logEntry({ level: 'fatal', message, timestamp: new Date(), context, error });\n }\n\n child(childContext: LogContext): UniversalLogger {\n return new Logger({\n service: this.service,\n level: this.level,\n transports: this.transports,\n context: {\n ...this.context,\n ...childContext,\n },\n });\n }\n\n setLevel(level: LogLevel): void {\n this.level = level;\n }\n\n getLevel(): LogLevel {\n return this.level;\n }\n}\n\nexport function createLogger(options?: LoggerOptions): UniversalLogger {\n return new Logger(options);\n}\n"],"mappings":"8JAaA,MAAM,EAAuC,CAC3C,MAAO,GACP,MAAO,GACP,KAAM,GAC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,EAAuB,CAC9B,KAAK,MAAQ,EAGf,UAAqB,CACnB,OAAO,KAAK,QAIhB,SAAgB,EAAa,EAA0C,CACrE,OAAO,IAAI,EAAO,EAAQ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { l as UniversalLogger, n as LogContext, o as LogLevel, s as LoggerOptions } from "./logger.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/logger.d.ts
|
|
4
|
+
declare class Logger implements UniversalLogger {
|
|
5
|
+
private readonly service?;
|
|
6
|
+
private level;
|
|
7
|
+
private readonly transports;
|
|
8
|
+
private readonly context;
|
|
9
|
+
private readonly filter;
|
|
10
|
+
constructor(options?: LoggerOptions);
|
|
11
|
+
private shouldLog;
|
|
12
|
+
private logEntry;
|
|
13
|
+
private parseArgs;
|
|
14
|
+
trace(message: string, ...args: unknown[]): void;
|
|
15
|
+
debug(message: string, ...args: unknown[]): void;
|
|
16
|
+
info(message: string, ...args: unknown[]): void;
|
|
17
|
+
warn(message: string, ...args: unknown[]): void;
|
|
18
|
+
error(message: string, error?: unknown, ...args: unknown[]): void;
|
|
19
|
+
fatal(message: string, error?: unknown, ...args: unknown[]): void;
|
|
20
|
+
child(childContext: LogContext): UniversalLogger;
|
|
21
|
+
setLevel(level: LogLevel): void;
|
|
22
|
+
getLevel(): LogLevel;
|
|
23
|
+
}
|
|
24
|
+
declare function createLogger(options?: LoggerOptions): UniversalLogger;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Logger, createLogger };
|
|
27
|
+
//# sourceMappingURL=logger2.d.cts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { l as UniversalLogger, n as LogContext, o as LogLevel, s as LoggerOptions } from "./logger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/logger.d.ts
|
|
4
|
+
declare class Logger implements UniversalLogger {
|
|
5
|
+
private readonly service?;
|
|
6
|
+
private level;
|
|
7
|
+
private readonly transports;
|
|
8
|
+
private readonly context;
|
|
9
|
+
private readonly filter;
|
|
10
|
+
constructor(options?: LoggerOptions);
|
|
11
|
+
private shouldLog;
|
|
12
|
+
private logEntry;
|
|
13
|
+
private parseArgs;
|
|
14
|
+
trace(message: string, ...args: unknown[]): void;
|
|
15
|
+
debug(message: string, ...args: unknown[]): void;
|
|
16
|
+
info(message: string, ...args: unknown[]): void;
|
|
17
|
+
warn(message: string, ...args: unknown[]): void;
|
|
18
|
+
error(message: string, error?: unknown, ...args: unknown[]): void;
|
|
19
|
+
fatal(message: string, error?: unknown, ...args: unknown[]): void;
|
|
20
|
+
child(childContext: LogContext): UniversalLogger;
|
|
21
|
+
setLevel(level: LogLevel): void;
|
|
22
|
+
getLevel(): LogLevel;
|
|
23
|
+
}
|
|
24
|
+
declare function createLogger(options?: LoggerOptions): UniversalLogger;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Logger, createLogger };
|
|
27
|
+
//# sourceMappingURL=logger2.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils/logFormatter.cjs`);var t=class{name=`console`;formatter=new e.DefaultLogFormatter;log(e){let t=this.formatter.format(e);switch(e.level){case`trace`:case`debug`:typeof console.debug==`function`?console.debug(t):console.log(t);break;case`info`:typeof console.info==`function`?console.info(t):console.log(t);break;case`warn`:typeof console.warn==`function`?console.warn(t):console.log(t);break;case`error`:case`fatal`:typeof console.error==`function`?console.error(t):console.log(t);break;default:console.log(t)}}};exports.ConsoleTransport=t;
|
|
2
|
+
//# sourceMappingURL=console.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.cjs","names":["DefaultLogFormatter"],"sources":["../../src/transports/console.ts"],"sourcesContent":["import type { LogEntry, Transport } from '../types/logger';\nimport { DefaultLogFormatter } from '../utils/logFormatter';\n\nexport class ConsoleTransport implements Transport {\n name = 'console';\n private formatter = new DefaultLogFormatter();\n\n log(entry: LogEntry): void {\n const formatted = this.formatter.format(entry);\n\n switch (entry.level) {\n case 'trace':\n case 'debug':\n if (typeof console.debug === 'function') {\n console.debug(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'info':\n if (typeof console.info === 'function') {\n console.info(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'warn':\n if (typeof console.warn === 'function') {\n console.warn(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'error':\n case 'fatal':\n if (typeof console.error === 'function') {\n console.error(formatted);\n } else {\n console.log(formatted);\n }\n break;\n default:\n console.log(formatted);\n }\n }\n}\n"],"mappings":"gHAGA,IAAa,EAAb,KAAmD,CACjD,KAAO,UACP,UAAoB,IAAIA,EAAAA,oBAExB,IAAI,EAAuB,CACzB,IAAM,EAAY,KAAK,UAAU,OAAO,EAAM,CAE9C,OAAQ,EAAM,MAAd,CACE,IAAK,QACL,IAAK,QACC,OAAO,QAAQ,OAAU,WAC3B,QAAQ,MAAM,EAAU,CAExB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,OACC,OAAO,QAAQ,MAAS,WAC1B,QAAQ,KAAK,EAAU,CAEvB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,OACC,OAAO,QAAQ,MAAS,WAC1B,QAAQ,KAAK,EAAU,CAEvB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,QACL,IAAK,QACC,OAAO,QAAQ,OAAU,WAC3B,QAAQ,MAAM,EAAU,CAExB,QAAQ,IAAI,EAAU,CAExB,MACF,QACE,QAAQ,IAAI,EAAU"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as Transport, r as LogEntry } from "../logger.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/console.d.ts
|
|
4
|
+
declare class ConsoleTransport implements Transport {
|
|
5
|
+
name: string;
|
|
6
|
+
private formatter;
|
|
7
|
+
log(entry: LogEntry): void;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ConsoleTransport };
|
|
11
|
+
//# sourceMappingURL=console.d.cts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { c as Transport, r as LogEntry } from "../logger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/console.d.ts
|
|
4
|
+
declare class ConsoleTransport implements Transport {
|
|
5
|
+
name: string;
|
|
6
|
+
private formatter;
|
|
7
|
+
log(entry: LogEntry): void;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ConsoleTransport };
|
|
11
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{DefaultLogFormatter as e}from"../utils/logFormatter.js";var t=class{name=`console`;formatter=new e;log(e){let t=this.formatter.format(e);switch(e.level){case`trace`:case`debug`:typeof console.debug==`function`?console.debug(t):console.log(t);break;case`info`:typeof console.info==`function`?console.info(t):console.log(t);break;case`warn`:typeof console.warn==`function`?console.warn(t):console.log(t);break;case`error`:case`fatal`:typeof console.error==`function`?console.error(t):console.log(t);break;default:console.log(t)}}};export{t as ConsoleTransport};
|
|
2
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","names":[],"sources":["../../src/transports/console.ts"],"sourcesContent":["import type { LogEntry, Transport } from '../types/logger';\nimport { DefaultLogFormatter } from '../utils/logFormatter';\n\nexport class ConsoleTransport implements Transport {\n name = 'console';\n private formatter = new DefaultLogFormatter();\n\n log(entry: LogEntry): void {\n const formatted = this.formatter.format(entry);\n\n switch (entry.level) {\n case 'trace':\n case 'debug':\n if (typeof console.debug === 'function') {\n console.debug(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'info':\n if (typeof console.info === 'function') {\n console.info(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'warn':\n if (typeof console.warn === 'function') {\n console.warn(formatted);\n } else {\n console.log(formatted);\n }\n break;\n case 'error':\n case 'fatal':\n if (typeof console.error === 'function') {\n console.error(formatted);\n } else {\n console.log(formatted);\n }\n break;\n default:\n console.log(formatted);\n }\n }\n}\n"],"mappings":"+DAGA,IAAa,EAAb,KAAmD,CACjD,KAAO,UACP,UAAoB,IAAI,EAExB,IAAI,EAAuB,CACzB,IAAM,EAAY,KAAK,UAAU,OAAO,EAAM,CAE9C,OAAQ,EAAM,MAAd,CACE,IAAK,QACL,IAAK,QACC,OAAO,QAAQ,OAAU,WAC3B,QAAQ,MAAM,EAAU,CAExB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,OACC,OAAO,QAAQ,MAAS,WAC1B,QAAQ,KAAK,EAAU,CAEvB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,OACC,OAAO,QAAQ,MAAS,WAC1B,QAAQ,KAAK,EAAU,CAEvB,QAAQ,IAAI,EAAU,CAExB,MACF,IAAK,QACL,IAAK,QACC,OAAO,QAAQ,OAAU,WAC3B,QAAQ,MAAM,EAAU,CAExB,QAAQ,IAAI,EAAU,CAExB,MACF,QACE,QAAQ,IAAI,EAAU"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{shouldLog(e,t){return!0}},t=class{constructor(e,t=!0){this.pattern=e,this.include=t}shouldLog(e,t){let n=this.pattern.test(e.message);return this.include?n:!n}},n=class{constructor(e){this.filters=e}shouldLog(e,t){return this.filters.every(n=>n.shouldLog(e,t))}};exports.CompositeLogFilter=n,exports.DefaultLogFilter=e,exports.RegexLogFilter=t;
|
|
2
|
+
//# sourceMappingURL=logFilter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logFilter.cjs","names":[],"sources":["../../src/utils/logFilter.ts"],"sourcesContent":["import type { LogEntry, LogFilter, LogLevel } from '../types/logger';\n\nexport class DefaultLogFilter implements LogFilter {\n shouldLog(_entry: LogEntry, _minLevel: LogLevel): boolean {\n return true;\n }\n}\n\nexport class RegexLogFilter implements LogFilter {\n constructor(\n private readonly pattern: RegExp,\n private readonly include: boolean = true,\n ) {}\n\n shouldLog(entry: LogEntry, _minLevel: LogLevel): boolean {\n const matches = this.pattern.test(entry.message);\n return this.include ? matches : !matches;\n }\n}\n\nexport class CompositeLogFilter implements LogFilter {\n constructor(private readonly filters: LogFilter[]) {}\n\n shouldLog(entry: LogEntry, minLevel: LogLevel): boolean {\n return this.filters.every((filter) => filter.shouldLog(entry, minLevel));\n }\n}\n"],"mappings":"mEAEA,IAAa,EAAb,KAAmD,CACjD,UAAU,EAAkB,EAA8B,CACxD,MAAO,KAIE,EAAb,KAAiD,CAC/C,YACE,EACA,EAAoC,GACpC,CAFiB,KAAA,QAAA,EACA,KAAA,QAAA,EAGnB,UAAU,EAAiB,EAA8B,CACvD,IAAM,EAAU,KAAK,QAAQ,KAAK,EAAM,QAAQ,CAChD,OAAO,KAAK,QAAU,EAAU,CAAC,IAIxB,EAAb,KAAqD,CACnD,YAAY,EAAuC,CAAtB,KAAA,QAAA,EAE7B,UAAU,EAAiB,EAA6B,CACtD,OAAO,KAAK,QAAQ,MAAO,GAAW,EAAO,UAAU,EAAO,EAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { i as LogFilter, o as LogLevel, r as LogEntry } from "../logger.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logFilter.d.ts
|
|
4
|
+
declare class DefaultLogFilter implements LogFilter {
|
|
5
|
+
shouldLog(_entry: LogEntry, _minLevel: LogLevel): boolean;
|
|
6
|
+
}
|
|
7
|
+
declare class RegexLogFilter implements LogFilter {
|
|
8
|
+
private readonly pattern;
|
|
9
|
+
private readonly include;
|
|
10
|
+
constructor(pattern: RegExp, include?: boolean);
|
|
11
|
+
shouldLog(entry: LogEntry, _minLevel: LogLevel): boolean;
|
|
12
|
+
}
|
|
13
|
+
declare class CompositeLogFilter implements LogFilter {
|
|
14
|
+
private readonly filters;
|
|
15
|
+
constructor(filters: LogFilter[]);
|
|
16
|
+
shouldLog(entry: LogEntry, minLevel: LogLevel): boolean;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CompositeLogFilter, DefaultLogFilter, RegexLogFilter };
|
|
20
|
+
//# sourceMappingURL=logFilter.d.cts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { i as LogFilter, o as LogLevel, r as LogEntry } from "../logger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logFilter.d.ts
|
|
4
|
+
declare class DefaultLogFilter implements LogFilter {
|
|
5
|
+
shouldLog(_entry: LogEntry, _minLevel: LogLevel): boolean;
|
|
6
|
+
}
|
|
7
|
+
declare class RegexLogFilter implements LogFilter {
|
|
8
|
+
private readonly pattern;
|
|
9
|
+
private readonly include;
|
|
10
|
+
constructor(pattern: RegExp, include?: boolean);
|
|
11
|
+
shouldLog(entry: LogEntry, _minLevel: LogLevel): boolean;
|
|
12
|
+
}
|
|
13
|
+
declare class CompositeLogFilter implements LogFilter {
|
|
14
|
+
private readonly filters;
|
|
15
|
+
constructor(filters: LogFilter[]);
|
|
16
|
+
shouldLog(entry: LogEntry, minLevel: LogLevel): boolean;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CompositeLogFilter, DefaultLogFilter, RegexLogFilter };
|
|
20
|
+
//# sourceMappingURL=logFilter.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{shouldLog(e,t){return!0}},t=class{constructor(e,t=!0){this.pattern=e,this.include=t}shouldLog(e,t){let n=this.pattern.test(e.message);return this.include?n:!n}},n=class{constructor(e){this.filters=e}shouldLog(e,t){return this.filters.every(n=>n.shouldLog(e,t))}};export{n as CompositeLogFilter,e as DefaultLogFilter,t as RegexLogFilter};
|
|
2
|
+
//# sourceMappingURL=logFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logFilter.js","names":[],"sources":["../../src/utils/logFilter.ts"],"sourcesContent":["import type { LogEntry, LogFilter, LogLevel } from '../types/logger';\n\nexport class DefaultLogFilter implements LogFilter {\n shouldLog(_entry: LogEntry, _minLevel: LogLevel): boolean {\n return true;\n }\n}\n\nexport class RegexLogFilter implements LogFilter {\n constructor(\n private readonly pattern: RegExp,\n private readonly include: boolean = true,\n ) {}\n\n shouldLog(entry: LogEntry, _minLevel: LogLevel): boolean {\n const matches = this.pattern.test(entry.message);\n return this.include ? matches : !matches;\n }\n}\n\nexport class CompositeLogFilter implements LogFilter {\n constructor(private readonly filters: LogFilter[]) {}\n\n shouldLog(entry: LogEntry, minLevel: LogLevel): boolean {\n return this.filters.every((filter) => filter.shouldLog(entry, minLevel));\n }\n}\n"],"mappings":"AAEA,IAAa,EAAb,KAAmD,CACjD,UAAU,EAAkB,EAA8B,CACxD,MAAO,KAIE,EAAb,KAAiD,CAC/C,YACE,EACA,EAAoC,GACpC,CAFiB,KAAA,QAAA,EACA,KAAA,QAAA,EAGnB,UAAU,EAAiB,EAA8B,CACvD,IAAM,EAAU,KAAK,QAAQ,KAAK,EAAM,QAAQ,CAChD,OAAO,KAAK,QAAU,EAAU,CAAC,IAIxB,EAAb,KAAqD,CACnD,YAAY,EAAuC,CAAtB,KAAA,QAAA,EAE7B,UAAU,EAAiB,EAA6B,CACtD,OAAO,KAAK,QAAQ,MAAO,GAAW,EAAO,UAAU,EAAO,EAAS,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{format(e){let t=`${e.timestamp.toISOString()} ${e.level.toUpperCase().padEnd(5)} ${e.service?`[${e.service}]`:``} ${e.message}`.trim();return e.context&&Object.keys(e.context).length>0&&(t+=` ${JSON.stringify(e.context)}`),e.error&&(e.error instanceof Error?(t+=`\n Error: ${e.error.message}`,e.error.stack&&(t+=`\n Stack: ${e.error.stack}`)):t+=`\n Error: ${JSON.stringify(e.error)}`),t}},t=class{format(e){let t={timestamp:e.timestamp.toISOString(),level:e.level,message:e.message};return e.service&&(t.service=e.service),e.context&&(t.context=e.context),e.error&&(e.error instanceof Error?t.error={message:e.error.message,stack:e.error.stack,name:e.error.name}:t.error=e.error),JSON.stringify(t)}};exports.DefaultLogFormatter=e,exports.JsonLogFormatter=t;
|
|
2
|
+
//# sourceMappingURL=logFormatter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logFormatter.cjs","names":[],"sources":["../../src/utils/logFormatter.ts"],"sourcesContent":["import type { LogEntry, LogFormatter } from '../types/logger';\n\nexport class DefaultLogFormatter implements LogFormatter {\n format(entry: LogEntry): string {\n const timestamp = entry.timestamp.toISOString();\n const level = entry.level.toUpperCase().padEnd(5);\n const service = entry.service ? `[${entry.service}]` : '';\n\n let message = `${timestamp} ${level} ${service} ${entry.message}`.trim();\n\n if (entry.context && Object.keys(entry.context).length > 0) {\n message += ` ${JSON.stringify(entry.context)}`;\n }\n\n if (entry.error) {\n if (entry.error instanceof Error) {\n message += `\\n Error: ${entry.error.message}`;\n if (entry.error.stack) {\n message += `\\n Stack: ${entry.error.stack}`;\n }\n } else {\n message += `\\n Error: ${JSON.stringify(entry.error)}`;\n }\n }\n\n return message;\n }\n}\n\nexport class JsonLogFormatter implements LogFormatter {\n format(entry: LogEntry): string {\n const logObject: Record<string, unknown> = {\n timestamp: entry.timestamp.toISOString(),\n level: entry.level,\n message: entry.message,\n };\n\n if (entry.service) {\n logObject.service = entry.service;\n }\n\n if (entry.context) {\n logObject.context = entry.context;\n }\n\n if (entry.error) {\n if (entry.error instanceof Error) {\n logObject.error = {\n message: entry.error.message,\n stack: entry.error.stack,\n name: entry.error.name,\n };\n } else {\n logObject.error = entry.error;\n }\n }\n\n return JSON.stringify(logObject);\n }\n}\n"],"mappings":"mEAEA,IAAa,EAAb,KAAyD,CACvD,OAAO,EAAyB,CAK9B,IAAI,EAAU,GAJI,EAAM,UAAU,aAAa,CAIpB,GAHb,EAAM,MAAM,aAAa,CAAC,OAAO,EAAE,CAGb,GAFpB,EAAM,QAAU,IAAI,EAAM,QAAQ,GAAK,GAER,GAAG,EAAM,UAAU,MAAM,CAiBxE,OAfI,EAAM,SAAW,OAAO,KAAK,EAAM,QAAQ,CAAC,OAAS,IACvD,GAAW,IAAI,KAAK,UAAU,EAAM,QAAQ,IAG1C,EAAM,QACJ,EAAM,iBAAiB,OACzB,GAAW,cAAc,EAAM,MAAM,UACjC,EAAM,MAAM,QACd,GAAW,cAAc,EAAM,MAAM,UAGvC,GAAW,cAAc,KAAK,UAAU,EAAM,MAAM,IAIjD,IAIE,EAAb,KAAsD,CACpD,OAAO,EAAyB,CAC9B,IAAM,EAAqC,CACzC,UAAW,EAAM,UAAU,aAAa,CACxC,MAAO,EAAM,MACb,QAAS,EAAM,QAChB,CAsBD,OApBI,EAAM,UACR,EAAU,QAAU,EAAM,SAGxB,EAAM,UACR,EAAU,QAAU,EAAM,SAGxB,EAAM,QACJ,EAAM,iBAAiB,MACzB,EAAU,MAAQ,CAChB,QAAS,EAAM,MAAM,QACrB,MAAO,EAAM,MAAM,MACnB,KAAM,EAAM,MAAM,KACnB,CAED,EAAU,MAAQ,EAAM,OAIrB,KAAK,UAAU,EAAU"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as LogFormatter, r as LogEntry } from "../logger.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logFormatter.d.ts
|
|
4
|
+
declare class DefaultLogFormatter implements LogFormatter {
|
|
5
|
+
format(entry: LogEntry): string;
|
|
6
|
+
}
|
|
7
|
+
declare class JsonLogFormatter implements LogFormatter {
|
|
8
|
+
format(entry: LogEntry): string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DefaultLogFormatter, JsonLogFormatter };
|
|
12
|
+
//# sourceMappingURL=logFormatter.d.cts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as LogFormatter, r as LogEntry } from "../logger.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/logFormatter.d.ts
|
|
4
|
+
declare class DefaultLogFormatter implements LogFormatter {
|
|
5
|
+
format(entry: LogEntry): string;
|
|
6
|
+
}
|
|
7
|
+
declare class JsonLogFormatter implements LogFormatter {
|
|
8
|
+
format(entry: LogEntry): string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { DefaultLogFormatter, JsonLogFormatter };
|
|
12
|
+
//# sourceMappingURL=logFormatter.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=class{format(e){let t=`${e.timestamp.toISOString()} ${e.level.toUpperCase().padEnd(5)} ${e.service?`[${e.service}]`:``} ${e.message}`.trim();return e.context&&Object.keys(e.context).length>0&&(t+=` ${JSON.stringify(e.context)}`),e.error&&(e.error instanceof Error?(t+=`\n Error: ${e.error.message}`,e.error.stack&&(t+=`\n Stack: ${e.error.stack}`)):t+=`\n Error: ${JSON.stringify(e.error)}`),t}},t=class{format(e){let t={timestamp:e.timestamp.toISOString(),level:e.level,message:e.message};return e.service&&(t.service=e.service),e.context&&(t.context=e.context),e.error&&(e.error instanceof Error?t.error={message:e.error.message,stack:e.error.stack,name:e.error.name}:t.error=e.error),JSON.stringify(t)}};export{e as DefaultLogFormatter,t as JsonLogFormatter};
|
|
2
|
+
//# sourceMappingURL=logFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logFormatter.js","names":[],"sources":["../../src/utils/logFormatter.ts"],"sourcesContent":["import type { LogEntry, LogFormatter } from '../types/logger';\n\nexport class DefaultLogFormatter implements LogFormatter {\n format(entry: LogEntry): string {\n const timestamp = entry.timestamp.toISOString();\n const level = entry.level.toUpperCase().padEnd(5);\n const service = entry.service ? `[${entry.service}]` : '';\n\n let message = `${timestamp} ${level} ${service} ${entry.message}`.trim();\n\n if (entry.context && Object.keys(entry.context).length > 0) {\n message += ` ${JSON.stringify(entry.context)}`;\n }\n\n if (entry.error) {\n if (entry.error instanceof Error) {\n message += `\\n Error: ${entry.error.message}`;\n if (entry.error.stack) {\n message += `\\n Stack: ${entry.error.stack}`;\n }\n } else {\n message += `\\n Error: ${JSON.stringify(entry.error)}`;\n }\n }\n\n return message;\n }\n}\n\nexport class JsonLogFormatter implements LogFormatter {\n format(entry: LogEntry): string {\n const logObject: Record<string, unknown> = {\n timestamp: entry.timestamp.toISOString(),\n level: entry.level,\n message: entry.message,\n };\n\n if (entry.service) {\n logObject.service = entry.service;\n }\n\n if (entry.context) {\n logObject.context = entry.context;\n }\n\n if (entry.error) {\n if (entry.error instanceof Error) {\n logObject.error = {\n message: entry.error.message,\n stack: entry.error.stack,\n name: entry.error.name,\n };\n } else {\n logObject.error = entry.error;\n }\n }\n\n return JSON.stringify(logObject);\n }\n}\n"],"mappings":"AAEA,IAAa,EAAb,KAAyD,CACvD,OAAO,EAAyB,CAK9B,IAAI,EAAU,GAJI,EAAM,UAAU,aAAa,CAIpB,GAHb,EAAM,MAAM,aAAa,CAAC,OAAO,EAAE,CAGb,GAFpB,EAAM,QAAU,IAAI,EAAM,QAAQ,GAAK,GAER,GAAG,EAAM,UAAU,MAAM,CAiBxE,OAfI,EAAM,SAAW,OAAO,KAAK,EAAM,QAAQ,CAAC,OAAS,IACvD,GAAW,IAAI,KAAK,UAAU,EAAM,QAAQ,IAG1C,EAAM,QACJ,EAAM,iBAAiB,OACzB,GAAW,cAAc,EAAM,MAAM,UACjC,EAAM,MAAM,QACd,GAAW,cAAc,EAAM,MAAM,UAGvC,GAAW,cAAc,KAAK,UAAU,EAAM,MAAM,IAIjD,IAIE,EAAb,KAAsD,CACpD,OAAO,EAAyB,CAC9B,IAAM,EAAqC,CACzC,UAAW,EAAM,UAAU,aAAa,CACxC,MAAO,EAAM,MACb,QAAS,EAAM,QAChB,CAsBD,OApBI,EAAM,UACR,EAAU,QAAU,EAAM,SAGxB,EAAM,UACR,EAAU,QAAU,EAAM,SAGxB,EAAM,QACJ,EAAM,iBAAiB,MACzB,EAAU,MAAQ,CAChB,QAAS,EAAM,MAAM,QACrB,MAAO,EAAM,MAAM,MACnB,KAAM,EAAM,MAAM,KACnB,CAED,EAAU,MAAQ,EAAM,OAIrB,KAAK,UAAU,EAAU"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agimon-ai/foundation-universal-logger",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A universal logger package with TypeScript support for frontend and backend environments",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@opentelemetry/api": "1.9.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/node": "25.6.0",
|
|
17
|
+
"tsdown": "0.21.7",
|
|
18
|
+
"typescript": "6.0.2",
|
|
19
|
+
"vitest": "4.1.4"
|
|
20
|
+
},
|
|
21
|
+
"author": "Vuong Ngo",
|
|
22
|
+
"license": "BUSL-1.1",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./logger": {
|
|
31
|
+
"types": "./dist/logger.d.mts",
|
|
32
|
+
"import": "./dist/logger.mjs",
|
|
33
|
+
"require": "./dist/logger.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./transports/console": {
|
|
36
|
+
"types": "./dist/transports/console.d.mts",
|
|
37
|
+
"import": "./dist/transports/console.mjs",
|
|
38
|
+
"require": "./dist/transports/console.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./utils/logFilter": {
|
|
41
|
+
"types": "./dist/utils/logFilter.d.mts",
|
|
42
|
+
"import": "./dist/utils/logFilter.mjs",
|
|
43
|
+
"require": "./dist/utils/logFilter.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./utils/logFormatter": {
|
|
46
|
+
"types": "./dist/utils/logFormatter.d.mts",
|
|
47
|
+
"import": "./dist/utils/logFormatter.mjs",
|
|
48
|
+
"require": "./dist/utils/logFormatter.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./*": "./*"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist",
|
|
54
|
+
"README.md"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsdown",
|
|
58
|
+
"test": "vitest run --coverage.enabled=false",
|
|
59
|
+
"lint": "eslint src",
|
|
60
|
+
"fixcode": "pnpm exec biome check --write",
|
|
61
|
+
"typecheck": "tsc --noEmit"
|
|
62
|
+
}
|
|
63
|
+
}
|