@padosoft/logger 1.3.2
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/adapters/drizzle.d.mts +8 -0
- package/dist/adapters/drizzle.mjs +1 -0
- package/dist/adapters/hono.d.mts +6 -0
- package/dist/adapters/hono.mjs +1 -0
- package/dist/core/logger.d.mts +44 -0
- package/dist/core/logger.mjs +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/format.d.mts +6 -0
- package/dist/lib/format.mjs +1 -0
- package/dist/lib/index.d.mts +4 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/levels.d.mts +14 -0
- package/dist/lib/levels.mjs +1 -0
- package/dist/lib/mods.d.mts +7 -0
- package/dist/lib/mods.mjs +1 -0
- package/dist/lib/utils.d.mts +10 -0
- package/dist/lib/utils.mjs +1 -0
- package/dist/package.mjs +1 -0
- package/dist/plugins/context.d.mts +21 -0
- package/dist/plugins/context.mjs +1 -0
- package/dist/plugins/metrics.d.mts +20 -0
- package/dist/plugins/metrics.mjs +1 -0
- package/dist/plugins/rate-limiter.d.mts +7 -0
- package/dist/plugins/rate-limiter.mjs +1 -0
- package/dist/shared.d.mts +6 -0
- package/dist/shared.mjs +1 -0
- package/dist/transports/console/index.d.mts +13 -0
- package/dist/transports/console/index.mjs +1 -0
- package/dist/transports/console/lib/colors.d.mts +20 -0
- package/dist/transports/console/lib/colors.mjs +1 -0
- package/dist/transports/console/lib/symbols.d.mts +15 -0
- package/dist/transports/console/lib/symbols.mjs +1 -0
- package/dist/transports/console/lib/utils.d.mts +7 -0
- package/dist/transports/console/lib/utils.mjs +1 -0
- package/dist/transports/console/types.d.mts +4 -0
- package/dist/transports/console/types.mjs +1 -0
- package/dist/transports/discord/index.d.mts +9 -0
- package/dist/transports/discord/index.mjs +2 -0
- package/dist/transports/expo-fs/index.d.mts +15 -0
- package/dist/transports/expo-fs/index.mjs +2 -0
- package/dist/transports/expo-fs/lib/constants.d.mts +4 -0
- package/dist/transports/expo-fs/lib/constants.mjs +2 -0
- package/dist/transports/expo-fs/lib/file-logger.d.mts +20 -0
- package/dist/transports/expo-fs/lib/file-logger.mjs +3 -0
- package/dist/transports/file.d.mts +21 -0
- package/dist/transports/file.mjs +2 -0
- package/dist/transports/http.d.mts +18 -0
- package/dist/transports/http.mjs +1 -0
- package/dist/transports/otel/index.d.mts +10 -0
- package/dist/transports/otel/index.mjs +1 -0
- package/dist/transports/otel/types.d.mts +23 -0
- package/dist/transports/otel/types.mjs +1 -0
- package/dist/transports/otel/utils.d.mts +11 -0
- package/dist/transports/otel/utils.mjs +1 -0
- package/dist/transports/ws.d.mts +9 -0
- package/dist/transports/ws.mjs +1 -0
- package/dist/types/batching.d.mts +44 -0
- package/dist/types/batching.mjs +1 -0
- package/dist/types/format.d.mts +4 -0
- package/dist/types/format.mjs +1 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/logger.d.mts +46 -0
- package/dist/types/logger.mjs +1 -0
- package/dist/types/mods.d.mts +74 -0
- package/dist/types/mods.mjs +1 -0
- package/package.json +200 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>({logQuery(t,n){e.debug(`drizzle-orm DB query`,{query:t,params:n})}});export{e as createDrizzleAdapter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>(t,...n)=>{e.info(t,...n)};export{e as createHonoAdapter};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LogLevel } from "../lib/levels.mjs";
|
|
2
|
+
import { Plugin, Transport } from "../types/mods.mjs";
|
|
3
|
+
import { LogEntry, LoggerOptions } from "../types/logger.mjs";
|
|
4
|
+
import { BatchingOptions, BatchingState } from "../types/batching.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/logger.d.ts
|
|
7
|
+
declare class Logger {
|
|
8
|
+
protected level: LogLevel;
|
|
9
|
+
readonly transports: Transport[];
|
|
10
|
+
readonly plugins: Plugin[];
|
|
11
|
+
protected batching?: BatchingOptions | undefined;
|
|
12
|
+
protected batchingState: BatchingState;
|
|
13
|
+
constructor(opts?: LoggerOptions);
|
|
14
|
+
addPlugin(plugin: Plugin): this;
|
|
15
|
+
addTransport(transport: Transport): this;
|
|
16
|
+
use(mod: Transport | Plugin): this;
|
|
17
|
+
setLevel(level: LogLevel): this;
|
|
18
|
+
setBatching(options: BatchingOptions | null): this;
|
|
19
|
+
protected shouldLog(level: LogLevel): boolean;
|
|
20
|
+
protected applyTransforms(entry: LogEntry): Promise<LogEntry>;
|
|
21
|
+
protected handleEntry(entry: LogEntry): Promise<void>;
|
|
22
|
+
emit(level: LogLevel, data: unknown[]): this;
|
|
23
|
+
trace: (...a: unknown[]) => this;
|
|
24
|
+
debug: (...a: unknown[]) => this;
|
|
25
|
+
info: (...a: unknown[]) => this;
|
|
26
|
+
success: (...a: unknown[]) => this;
|
|
27
|
+
warn: (...a: unknown[]) => this;
|
|
28
|
+
error: (...a: unknown[]) => this;
|
|
29
|
+
fatal: (...a: unknown[]) => this;
|
|
30
|
+
assert(cond: boolean, ...a: unknown[]): this;
|
|
31
|
+
table(data: unknown, properties?: readonly string[]): this;
|
|
32
|
+
clear(): this;
|
|
33
|
+
group(...label: unknown[]): this;
|
|
34
|
+
groupEnd(): this;
|
|
35
|
+
clone(extra?: Partial<LoggerOptions>): Logger;
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
38
|
+
[Symbol.dispose](): void;
|
|
39
|
+
private clearTimer;
|
|
40
|
+
private scheduleTimer;
|
|
41
|
+
flush(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { Logger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LogLevels as e,LogLevelsValues as t}from"../lib/levels.mjs";var n=class n{level;transports;plugins;batching;batchingState;constructor(t={}){this.level=t.level??e.INFO,this.transports=t.transports??[],this.plugins=t.plugins??[],this.batching=t.batching?t.batching:void 0,this.batchingState={buf:[],timer:null},Promise.allSettled(this.plugins.map(e=>e.enrichLogger?.(this)))}addPlugin(e){return this.plugins.push(e),e.enrichLogger?.(this),this}addTransport(e){return this.transports.push(e),this}use(e){return e._tag===`plugin`?this.addPlugin(e):e._tag===`transport`?this.addTransport(e):this}setLevel(e){return this.level=e,this}setBatching(e){return this.batching=e??void 0,this}shouldLog(e){return t[e]>=t[this.level]}async applyTransforms(e){let t=e;for(let e of this.plugins)e.transformEntry&&(t=await e.transformEntry(this,t));return t}async handleEntry(e){let t=await this.applyTransforms(e);if(!this.batching||this.batching.maxBatchSize<=1){Promise.allSettled(this.transports.map(e=>e.send(this,t)));return}if(!(this.batching.dropIfBufferFull&&this.batchingState.buf.length>=this.batching.maxBatchSize)){if(this.batchingState.buf.push(t),this.batchingState.buf.length>=this.batching.maxBatchSize)return this.flush();this.batching.maxIntervalMs&&this.batching.maxIntervalMs>0&&this.scheduleTimer()}}emit(e,t){if(!this.shouldLog(e))return this;let n={level:e,time:new Date,data:t};return this.handleEntry(n),this}trace=(...t)=>this.emit(e.TRACE,t);debug=(...t)=>this.emit(e.DEBUG,t);info=(...t)=>this.emit(e.INFO,t);success=(...t)=>this.emit(e.SUCCESS,t);warn=(...t)=>this.emit(e.WARN,t);error=(...t)=>this.emit(e.ERROR,t);fatal=(...t)=>this.emit(e.FATAL,t);assert(e,...t){return e||this.error(`Assertion failed:`,...t),this}table(e,t){return console.table?.(e,t),this}clear(){return console.clear?.(),this}group(...e){return console.group?.(e),this}groupEnd(){return console.groupEnd?.(),this}clone(e){return new n({level:this.level,transports:this.transports,plugins:this.plugins,...e})}async close(){(this.batching?.flushOnDispose??!0)&&await this.flush(),await Promise.all(this.transports.map(e=>(this.transports.pop(),e.teardown?.(this)))),await Promise.all(this.plugins.map(e=>(this.plugins.pop(),e.teardown?.(this)))),this.clearTimer()}[Symbol.asyncDispose](){return this.close()}[Symbol.dispose](){this.close()}clearTimer(){this.batchingState.timer&&(clearTimeout(this.batchingState.timer),this.batchingState.timer=null)}scheduleTimer(){!this.batching?.maxIntervalMs||this.batchingState.timer||(this.batchingState.timer=setTimeout(()=>{this.flush()},this.batching.maxIntervalMs))}async flush(){this.batchingState.buf.length!==0&&(await Promise.allSettled(this.transports.map(e=>typeof e.batch==`function`?e.batch(this,this.batchingState.buf):Promise.all(this.batchingState.buf.map(t=>e.send(this,t))))),this.batchingState.buf=[],this.clearTimer())}};export{n as Logger};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Mod, Plugin, Transport } from "./types/mods.mjs";
|
|
2
|
+
import { LogEntry, LoggerOptions } from "./types/logger.mjs";
|
|
3
|
+
import { BatchingOptions, BatchingState } from "./types/batching.mjs";
|
|
4
|
+
import { Logger } from "./core/logger.mjs";
|
|
5
|
+
export { BatchingOptions, BatchingState, LogEntry, Logger, LoggerOptions, Mod, Plugin, Transport };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Logger as e}from"./core/logger.mjs";export{e as Logger};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>{if(typeof e==`function`)return e;let t=e===`local`?e=>e.toLocaleString():e=>e.toISOString();return e=>t(e)};export{e as makeTimestamp};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LogLevel, LogLevels, LogLevelsValues } from "./levels.mjs";
|
|
2
|
+
import { createPlugin, createTransport } from "./mods.mjs";
|
|
3
|
+
import { isAzurePipeline, isCI, isModernTerminal, isWindowsCmd, supportsColors, supportsTTY, supportsUnicode } from "./utils.mjs";
|
|
4
|
+
export { LogLevel, LogLevels, LogLevelsValues, createPlugin, createTransport, isAzurePipeline, isCI, isModernTerminal, isWindowsCmd, supportsColors, supportsTTY, supportsUnicode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LogLevels as e,LogLevelsValues as t}from"./levels.mjs";import{createPlugin as n,createTransport as r}from"./mods.mjs";import{isAzurePipeline as i,isCI as a,isModernTerminal as o,isWindowsCmd as s,supportsColors as c,supportsTTY as l,supportsUnicode as u}from"./utils.mjs";export{e as LogLevels,t as LogLevelsValues,n as createPlugin,r as createTransport,i as isAzurePipeline,a as isCI,o as isModernTerminal,s as isWindowsCmd,c as supportsColors,l as supportsTTY,u as supportsUnicode};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/lib/levels.d.ts
|
|
2
|
+
declare const LogLevels: {
|
|
3
|
+
readonly TRACE: "trace";
|
|
4
|
+
readonly DEBUG: "debug";
|
|
5
|
+
readonly INFO: "info";
|
|
6
|
+
readonly SUCCESS: "success";
|
|
7
|
+
readonly WARN: "warn";
|
|
8
|
+
readonly ERROR: "error";
|
|
9
|
+
readonly FATAL: "fatal";
|
|
10
|
+
};
|
|
11
|
+
declare const LogLevelsValues: Record<LogLevel, number>;
|
|
12
|
+
type LogLevel = (typeof LogLevels)[keyof typeof LogLevels];
|
|
13
|
+
//#endregion
|
|
14
|
+
export { LogLevel, LogLevels, LogLevelsValues };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={TRACE:`trace`,DEBUG:`debug`,INFO:`info`,SUCCESS:`success`,WARN:`warn`,ERROR:`error`,FATAL:`fatal`},t={trace:10,debug:20,info:30,success:35,warn:40,error:50,fatal:60};export{e as LogLevels,t as LogLevelsValues};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Mod, Plugin, Transport } from "../types/mods.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/mods.d.ts
|
|
4
|
+
declare const createPlugin: <P extends Omit<Plugin, keyof Mod<string>>>(options: P) => Plugin & P;
|
|
5
|
+
declare const createTransport: <T extends Omit<Transport, keyof Mod<string>>>(options: T) => Transport & T;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { createPlugin, createTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>({...e,_tag:`plugin`}),t=e=>({...e,_tag:`transport`});export{e as createPlugin,t as createTransport};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/lib/utils.d.ts
|
|
2
|
+
declare const supportsTTY: boolean;
|
|
3
|
+
declare const isAzurePipeline: boolean;
|
|
4
|
+
declare const isCI: boolean;
|
|
5
|
+
declare const isModernTerminal: () => boolean;
|
|
6
|
+
declare const isWindowsCmd: boolean;
|
|
7
|
+
declare const supportsUnicode: () => boolean;
|
|
8
|
+
declare const supportsColors: () => boolean;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { isAzurePipeline, isCI, isModernTerminal, isWindowsCmd, supportsColors, supportsTTY, supportsUnicode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=typeof process<`u`&&`stdout`in process&&`isTTY`in process.stdout&&process.stdout.isTTY,t=typeof process<`u`&&`env`in process&&`TF_BUILD`in process.env&&`AGENT_NAME`in process.env,n=typeof process<`u`&&`env`in process&&`CI`in process.env,r=()=>{if(typeof process>`u`||!(`env`in process))return!1;let{TERM_PROGRAM:e,COLORTERM:t,TERM:n}=process.env,r=new Set([`iTerm.app`,`Apple_Terminal`,`Hyper`,`vscode`,`Windows Terminal`,`Alacritty`,`Tabby`,`WezTerm`]),i=new Set([`truecolor`,`24bit`]),a=e&&r.has(e),o=t&&i.has(t.toLowerCase()),s=n&&/xterm-256color|screen-256color|tmux-256color/.test(n);return a||o||s||!1},i=typeof process<`u`&&`platform`in process&&process.platform===`win32`,a=()=>i?r():!0,o=()=>e||n||t?!0:r();export{t as isAzurePipeline,n as isCI,r as isModernTerminal,i as isWindowsCmd,o as supportsColors,e as supportsTTY,a as supportsUnicode};
|
package/dist/package.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`@padosoft/logger`,t=`1.3.2`;export{e as name,t as version};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from "../types/mods.mjs";
|
|
2
|
+
import { Logger } from "../core/logger.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/plugins/context.d.ts
|
|
5
|
+
type Context = Record<string, unknown>;
|
|
6
|
+
declare module ".." {
|
|
7
|
+
interface LogEntry {
|
|
8
|
+
ctx?: Context;
|
|
9
|
+
}
|
|
10
|
+
interface Logger {
|
|
11
|
+
setContext?<C extends Context>(ctx: Partial<C>): void;
|
|
12
|
+
clearContext?(): void;
|
|
13
|
+
getContext?<C extends Context>(): C;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface ContextPluginOptions {
|
|
17
|
+
initial: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
declare const contextPlugin: (options: ContextPluginOptions) => Plugin<Logger>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Context, ContextPluginOptions, contextPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createPlugin as e}from"../lib/mods.mjs";import"../lib/index.mjs";const t=t=>{let n={...t.initial};return e({name:`context`,transformEntry(e,t){let r={...n,...t.ctx};return{...t,ctx:r}},enrichLogger(e){return e.setContext=e=>{n=e},e.clearContext=()=>{n={}},e.getContext=()=>n,e}})};export{t as contextPlugin};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LogLevel } from "../lib/levels.mjs";
|
|
2
|
+
import { Plugin } from "../types/mods.mjs";
|
|
3
|
+
import { Logger } from "../core/logger.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/metrics.d.ts
|
|
6
|
+
interface Metrics extends Partial<Record<LogLevel, number>> {
|
|
7
|
+
plugins: number;
|
|
8
|
+
transports: number;
|
|
9
|
+
}
|
|
10
|
+
declare module ".." {
|
|
11
|
+
interface Logger {
|
|
12
|
+
getMetrics?(): Metrics;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
interface MetricsPluginOptions {
|
|
16
|
+
countLevels?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const metricsPlugin: (options: MetricsPluginOptions) => Plugin<Logger>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Metrics, MetricsPluginOptions, metricsPlugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createPlugin as e}from"../lib/mods.mjs";import"../lib/index.mjs";const t=t=>{let n,r,i,a={plugins:0,transports:0};return e({name:`metrics`,enrichLogger(e){return a.plugins=e.plugins.length,a.transports=e.transports.length,n=e.emit.bind(e),r=e.addPlugin.bind(e),i=e.addTransport.bind(e),e.emit=t.countLevels?(e,t)=>(a[e]=(a[e]??0)+1,n(e,t)):n,e.addPlugin=e=>(a.plugins++,r(e)),e.addTransport=e=>(a.transports++,i(e)),e.getMetrics=()=>a,e}})};export{t as metricsPlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createPlugin as e}from"../lib/mods.mjs";const t=t=>{let n,r=0;return e({name:`rate-limiter`,enrichLogger(e){return n=e.emit.bind(e),e.emit=(i,a)=>{let o=Date.now();return o-r<t?e:(r=o,n(i,a))},e},teardown(e){return e.emit=n,e}})};export{t as rateLimiterPlugin};
|
package/dist/shared.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Logger as e}from"./core/logger.mjs";const t=new e;export{t as logger};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Transport } from "../../types/mods.mjs";
|
|
2
|
+
import { TimestampType } from "../../types/format.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/console/index.d.ts
|
|
5
|
+
interface ConsoleTransportOptions {
|
|
6
|
+
timestamp?: TimestampType;
|
|
7
|
+
symbols?: boolean;
|
|
8
|
+
colors?: boolean;
|
|
9
|
+
level?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const consoleTransport: (options?: ConsoleTransportOptions) => Transport;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ConsoleTransportOptions, consoleTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{makeTimestamp as e}from"../../lib/format.mjs";import{createTransport as t}from"../../lib/mods.mjs";import{colors as n,getLevelColor as r}from"./lib/colors.mjs";import{symbolize as i}from"./lib/symbols.mjs";import{consoleMethods as a}from"./lib/utils.mjs";const o=(o={timestamp:`local`,colors:!0,symbols:!0,level:!0})=>{let s=(e,t)=>o.colors?e(t):t,c=e(o.timestamp??`local`),l=(e,t)=>{let a=o.symbols??!0?i(e):null,l=r(e),u=new Date,d=[s(n.gray,c(u)),a?s(l,a):``];return(o.level??!0)&&d.push(`[${s(l,e.toUpperCase())}]`),[d.filter(e=>e.length).join(` `),...t]};return t({name:`console`,send:(e,t)=>{let n=l(t.level,t.data),r=a[t.level]||`log`,i=console[r];return i(...n)},batch(e,t){Promise.all(t.map(t=>this.send(e,t)))}})};export{o as consoleTransport};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LogLevel } from "../../../lib/levels.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/console/lib/colors.d.ts
|
|
4
|
+
declare const SUPPORTS_COLORS: boolean;
|
|
5
|
+
declare const colorize: (code: number, str: string) => string;
|
|
6
|
+
declare const getLevelColor: (level: LogLevel) => ColorFn;
|
|
7
|
+
declare const colors: {
|
|
8
|
+
readonly gray: (s: string) => string;
|
|
9
|
+
readonly red: (s: string) => string;
|
|
10
|
+
readonly green: (s: string) => string;
|
|
11
|
+
readonly yellow: (s: string) => string;
|
|
12
|
+
readonly blue: (s: string) => string;
|
|
13
|
+
readonly purple: (s: string) => string;
|
|
14
|
+
};
|
|
15
|
+
type Colors = typeof colors;
|
|
16
|
+
type Color = keyof Colors;
|
|
17
|
+
type ColorFn = Colors[Color];
|
|
18
|
+
declare const colorMap: Partial<Record<LogLevel, ColorFn>>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { Color, ColorFn, Colors, SUPPORTS_COLORS, colorMap, colorize, colors, getLevelColor };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{supportsColors as e}from"../../../lib/utils.mjs";const t=e(),n=(e,n)=>t?`\x1b[${e}m${n}\x1b[0m`:n,r=e=>a[e]??i.gray,i={gray:e=>n(90,e),red:e=>n(31,e),green:e=>n(32,e),yellow:e=>n(33,e),blue:e=>n(34,e),purple:e=>n(34,e)},a={error:i.red,warn:i.yellow,success:i.green,debug:i.purple,fatal:i.red,info:i.blue,trace:i.gray};export{t as SUPPORTS_COLORS,a as colorMap,n as colorize,i as colors,r as getLevelColor};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LogLevel } from "../../../lib/levels.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/console/lib/symbols.d.ts
|
|
4
|
+
type Symbols = Partial<Record<LogLevel | (string & {}), string>>;
|
|
5
|
+
declare const symbols: {
|
|
6
|
+
readonly success: "✔";
|
|
7
|
+
readonly error: "✖";
|
|
8
|
+
readonly warn: "⚠";
|
|
9
|
+
readonly info: "i";
|
|
10
|
+
readonly arrow: "➜";
|
|
11
|
+
};
|
|
12
|
+
declare const SUPPORTS_SYMBOLS: boolean;
|
|
13
|
+
declare const symbolize: (level: LogLevel) => string;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { SUPPORTS_SYMBOLS, Symbols, symbolize, symbols };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{supportsUnicode as e}from"../../../lib/utils.mjs";const t={success:`✔`,error:`✖`,warn:`⚠`,info:`i`,arrow:`➜`},n=e(),r=e=>n&&e in t?t[e]:``;export{n as SUPPORTS_SYMBOLS,r as symbolize,t as symbols};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LogLevel } from "../../../lib/levels.mjs";
|
|
2
|
+
import { ConsoleMethods } from "../types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/console/lib/utils.d.ts
|
|
5
|
+
declare const consoleMethods: Partial<Record<LogLevel, ConsoleMethods>>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { consoleMethods };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={info:`info`,warn:`warn`,error:`error`,debug:`debug`,success:`log`};export{e as consoleMethods};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Transport } from "../../types/mods.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/discord/index.d.ts
|
|
4
|
+
interface DiscordTransportOptions {
|
|
5
|
+
webhookUrl: string;
|
|
6
|
+
}
|
|
7
|
+
declare const discordTransport: (options: DiscordTransportOptions) => Transport;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DiscordTransportOptions, discordTransport };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createTransport as e}from"../../lib/mods.mjs";import{httpTransport as t}from"../http.mjs";const n=n=>{let r=t({endpoint:n.webhookUrl,method:`POST`,headers:{"Content-Type":`application/json`},transformBody:e=>{let t={username:`Logger`,embeds:[{title:`Log Entries`,description:e.map(e=>`**[${e.level.toUpperCase()}]** ${e.data.join(` `)}`).join(`
|
|
2
|
+
`),color:5814783,timestamp:new Date().toISOString(),footer:{text:`Total Entries: ${e.length}`}}]};return JSON.stringify(t)}});return e({name:`discord`,send(...e){return r.send(...e)},batch(...e){return r.batch?.(...e)}})};export{n as discordTransport};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transport } from "../../types/mods.mjs";
|
|
2
|
+
import { TimestampType } from "../../types/format.mjs";
|
|
3
|
+
import { FileLogger } from "./lib/file-logger.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/transports/expo-fs/index.d.ts
|
|
6
|
+
declare let expoFileLogger: FileLogger | null;
|
|
7
|
+
interface ExpoFileSystemTransportOptions {
|
|
8
|
+
filename?: string;
|
|
9
|
+
timestamp?: TimestampType;
|
|
10
|
+
raw?: boolean;
|
|
11
|
+
cleanOnStart?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const expoFileSystemTransport: (options?: ExpoFileSystemTransportOptions) => Transport;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ExpoFileSystemTransportOptions, expoFileLogger, expoFileSystemTransport };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{makeTimestamp as e}from"../../lib/format.mjs";import{createTransport as t}from"../../lib/mods.mjs";import"./lib/constants.mjs";import{FileLogger as n}from"./lib/file-logger.mjs";let r=null;const i=(i={timestamp:`local`})=>{let a=i.filename??`app.log`,o=e(i.timestamp??`local`);r=new n({filename:a}),r.open();let s=e=>{if(i.raw)try{return JSON.stringify(e)}catch{return String(e)}return[[o(e.time),`[${e.level.toUpperCase()}]`].filter(e=>e.trim().length).join(` `),...e.data?.map?.(e=>{if(!e)return``;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return e.toString().trim();try{return JSON.stringify(e)}catch{return String(e)}})].filter(e=>e.trim().length).join(` `)};return t({name:`expo-fs`,send:(e,t)=>{let n=s(t);r?.append(n)},batch(e,t){let n=t.map(e=>s(e)).join(`
|
|
2
|
+
`);r?.append(n)},[Symbol.dispose](){r?.close()},async[Symbol.asyncDispose](){r?.close()}})};export{r as expoFileLogger,i as expoFileSystemTransport};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/transports/expo-fs/lib/file-logger.d.ts
|
|
2
|
+
interface FileLoggerOptions {
|
|
3
|
+
filename: string;
|
|
4
|
+
cleanOnStart?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare class FileLogger {
|
|
7
|
+
private file;
|
|
8
|
+
private handle;
|
|
9
|
+
private readonly cleanOnStart;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
constructor(options: FileLoggerOptions);
|
|
12
|
+
open(): void;
|
|
13
|
+
append(line: string): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
readBytes(length: number): Uint8Array<ArrayBuffer>;
|
|
16
|
+
readString(length: number): string;
|
|
17
|
+
readLogEntries(): Promise<string[]>;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { FileLogger, FileLoggerOptions };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import"./constants.mjs";import{applicationName as e}from"expo-application";import{File as t,Paths as n}from"expo-file-system";var r=class{file=null;handle=null;cleanOnStart=!1;path;constructor(t){let r=n.join(n.cache,e||`padosoft`,t.filename);this.path=r,this.cleanOnStart=t.cleanOnStart??!1}open(){this.handle||=(this.file=new t(this.path),this.cleanOnStart&&this.file.delete(),this.file.create({intermediates:!0,overwrite:!0}),this.file.open())}append(e){if(!this.handle)throw Error(`Log file not open`);let t=new TextEncoder().encode(`${e}
|
|
2
|
+
`);this.handle.writeBytes(t)}close(){this.handle&&=(this.handle.close(),null)}readBytes(e){if(!this.handle)throw Error(`Log file not open`);return this.handle.readBytes(e)}readString(e){if(!this.handle)throw Error(`Log file not open`);let t=this.handle.readBytes(e);return new TextDecoder().decode(t)}async readLogEntries(){if(!this.handle)throw Error(`Log file not open`);let e=await this.file?.text();return e?e.split(`
|
|
3
|
+
`).filter(e=>e.trim().length>0):[]}};export{r as FileLogger};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Transport } from "../types/mods.mjs";
|
|
2
|
+
import { OpenMode } from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/file.d.ts
|
|
5
|
+
interface FileTransportOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Full path to the log file.
|
|
8
|
+
*/
|
|
9
|
+
filePath: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional flag to append to file (default is true).
|
|
12
|
+
*/
|
|
13
|
+
append?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Optional flag to write data in mode different than appen/write
|
|
16
|
+
*/
|
|
17
|
+
writeMode?: OpenMode;
|
|
18
|
+
}
|
|
19
|
+
declare const fileTransport: (options: FileTransportOptions) => Transport;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { FileTransportOptions, fileTransport };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createTransport as e}from"../lib/mods.mjs";import{mkdir as t,open as n}from"node:fs/promises";import*as r from"node:path";const i=i=>{let a=i.writeMode??(i.append?`a`:`w`),o=null,s=e=>JSON.stringify(e)+`
|
|
2
|
+
`;return(async()=>(o||=(await t(r.dirname(i.filePath),{recursive:!0}),await n(i.filePath,a)),o))(),e({name:`file`,send(e,t){o?.write(s(t))},batch(e,t){let n=t.map(s).join(``);o?.write(n)},async teardown(){o?.close()},[Symbol.dispose](){this.teardown()},async[Symbol.asyncDispose](){await this.teardown()}})};export{i as fileTransport};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Transport } from "../types/mods.mjs";
|
|
2
|
+
import { LogEntry } from "../types/logger.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/http.d.ts
|
|
5
|
+
interface HttpTransportOptions {
|
|
6
|
+
/** Endpoint URL to send logs to */
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
/** HTTP method (default: POST) */
|
|
9
|
+
method?: string;
|
|
10
|
+
/** Optional headers */
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
transformBody?: (body: LogEntry[]) => string;
|
|
13
|
+
/** Custom fetch function (default: global fetch) */
|
|
14
|
+
fetchFn?: (batch: LogEntry[]) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
declare const httpTransport: (options: HttpTransportOptions) => Transport;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { HttpTransportOptions, httpTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createTransport as e}from"../lib/mods.mjs";const t=t=>{let n=t.method??`POST`,r={"Content-Type":`application/json`,...t.headers},i=t.fetchFn??(async e=>{if(!t.endpoint)throw Error(`httpTransport: no endpoint or fetchFn provided`);let i=t.transformBody?t.transformBody(e):JSON.stringify(e);return globalThis.fetch(t.endpoint,{method:n,headers:r,body:i})});return e({name:`http`,send(e,t){i([t])},batch(e,t){i(t)}})};export{t as httpTransport};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Transport } from "../../types/mods.mjs";
|
|
2
|
+
import { OpenTelemetryTransportOptions } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/otel/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* OpenTelemetry transport (portable: Node + Edge + RN).
|
|
7
|
+
*/
|
|
8
|
+
declare const openTelemetryTransport: (options: OpenTelemetryTransportOptions) => Transport;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { openTelemetryTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createTransport as e}from"../../lib/mods.mjs";import{name as t,version as n}from"../../package.mjs";import{createLogProcessor as r,mapLevelToSeverity as i}from"./utils.mjs";import{DiagConsoleLogger as a,DiagLogLevel as o,context as s,diag as c,trace as l}from"@opentelemetry/api";import{logs as u}from"@opentelemetry/api-logs";import{OTLPLogExporter as d}from"@opentelemetry/exporter-logs-otlp-http";import{detectResources as f,envDetector as p,hostDetector as m,osDetector as h,processDetector as g,resourceFromAttributes as _,serviceInstanceIdDetector as v}from"@opentelemetry/resources";import{LoggerProvider as y}from"@opentelemetry/sdk-logs";import{ATTR_SERVICE_NAME as b,ATTR_SERVICE_VERSION as x}from"@opentelemetry/semantic-conventions";const S=S=>{let C=S.service?.name||t,w=S.service?.version||n;S.debug&&c.setLogger(new a,o.DEBUG);let T=f({detectors:[p,m,h,g,v]}),E=_({[b]:C,[x]:w,"deployment.environment":S.environment??`unknown`}),D=_(S.resources||{}),O=T.merge(E).merge(D),k=new d({concurrencyLimit:10,...S.httpExporterOptions}),A=S.exporters.map(e=>r(e,S.processor))||[r(k,S.processor)],j=S.loggerProvider??new y({resource:O,processors:A});u.setGlobalLoggerProvider(j);let M=j.getLogger(C,w);return e({name:`opentelemetry`,async send(e,t){let n=i(t.level),r=t.data.join(` `),a={args:t.data,time:t.time.toISOString()},o=s.active(),c=l.getSpan(o)?.spanContext();c&&(a.trace_id=c.traceId,a.span_id=c.spanId,a.trace_flags=c.traceFlags),M.emit({body:r,timestamp:t.time,severityNumber:n,severityText:t.level.toUpperCase(),attributes:a,context:o})},async batch(e,t){await Promise.allSettled(t.map(t=>this.send(e,t)))},async teardown(){await Promise.allSettled(A.map(e=>e.shutdown())),u.disable()}})};export{S as openTelemetryTransport};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LoggerProvider } from "@opentelemetry/api-logs";
|
|
2
|
+
import { DetectedResourceAttributes } from "@opentelemetry/resources";
|
|
3
|
+
import { LogRecordExporter, LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
4
|
+
import { OTLPExporterNodeConfigBase } from "@opentelemetry/otlp-exporter-base";
|
|
5
|
+
|
|
6
|
+
//#region src/transports/otel/types.d.ts
|
|
7
|
+
interface OTELServiceOptions {
|
|
8
|
+
name?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
}
|
|
11
|
+
type OTELLogProcessor = (_exporter: LogRecordExporter) => LogRecordProcessor;
|
|
12
|
+
interface OpenTelemetryTransportOptions {
|
|
13
|
+
service?: OTELServiceOptions;
|
|
14
|
+
environment?: string;
|
|
15
|
+
loggerProvider: LoggerProvider;
|
|
16
|
+
processor?: "batch" | "simple" | OTELLogProcessor;
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
httpExporterOptions?: OTLPExporterNodeConfigBase;
|
|
19
|
+
resources?: DetectedResourceAttributes;
|
|
20
|
+
exporters: LogRecordExporter[];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { OTELLogProcessor, OTELServiceOptions, OpenTelemetryTransportOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LogEntry } from "../../types/logger.mjs";
|
|
2
|
+
import { OpenTelemetryTransportOptions } from "./types.mjs";
|
|
3
|
+
import { SeverityNumber } from "@opentelemetry/api-logs";
|
|
4
|
+
import { LogRecordExporter, LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
5
|
+
|
|
6
|
+
//#region src/transports/otel/utils.d.ts
|
|
7
|
+
declare const levelToSeverity: Record<LogEntry["level"], SeverityNumber>;
|
|
8
|
+
declare const mapLevelToSeverity: (level: LogEntry["level"]) => SeverityNumber;
|
|
9
|
+
declare const createLogProcessor: (exporter: LogRecordExporter, type?: OpenTelemetryTransportOptions["processor"]) => LogRecordProcessor;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { createLogProcessor, levelToSeverity, mapLevelToSeverity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SeverityNumber as e}from"@opentelemetry/api-logs";import{BatchLogRecordProcessor as t,SimpleLogRecordProcessor as n}from"@opentelemetry/sdk-logs";const r={fatal:e.FATAL,error:e.ERROR,warn:e.WARN,info:e.INFO,success:e.INFO,debug:e.DEBUG,trace:e.TRACE},i=t=>r[t]??e.UNSPECIFIED,a=(e,r=`batch`)=>typeof r==`function`?r(e):new{batch:t,simple:n}[r](e);export{a as createLogProcessor,r as levelToSeverity,i as mapLevelToSeverity};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Transport } from "../types/mods.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/ws.d.ts
|
|
4
|
+
interface WebSocketTransportOptions {
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
declare const webSocketTransport: (options: WebSocketTransportOptions) => Transport;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { WebSocketTransportOptions, webSocketTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createTransport as e}from"../lib/mods.mjs";import"../lib/index.mjs";const t=t=>{let n=new WebSocket(t.url);return e({name:`ws`,send(e,t){n.send(JSON.stringify([t]))},batch(e,t){n.send(JSON.stringify(t))},teardown(){n.close()}})};export{t as webSocketTransport};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LogEntry } from "./logger.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/batching.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options that control batching behavior in the Logger.
|
|
6
|
+
*/
|
|
7
|
+
interface BatchingOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Flush when buffer reaches this size.
|
|
10
|
+
* @example 10
|
|
11
|
+
*/
|
|
12
|
+
maxBatchSize: number;
|
|
13
|
+
/**
|
|
14
|
+
* Also flush after this many milliseconds (if > 0).
|
|
15
|
+
* Disabled if `0` or undefined.
|
|
16
|
+
* @example 2000
|
|
17
|
+
*/
|
|
18
|
+
maxIntervalMs?: number | 0;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to flush remaining logs automatically on dispose/close.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
flushOnDispose?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Drop the newest log when buffer is full instead of flushing immediately.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
dropIfBufferFull?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Internal batching state, maintained per Logger.
|
|
32
|
+
*/
|
|
33
|
+
interface BatchingState {
|
|
34
|
+
/**
|
|
35
|
+
* Current buffer of entries waiting to be flushed.
|
|
36
|
+
*/
|
|
37
|
+
buf: LogEntry[];
|
|
38
|
+
/**
|
|
39
|
+
* Reference to the currently scheduled timer, if any.
|
|
40
|
+
*/
|
|
41
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { BatchingOptions, BatchingState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LogLevel } from "../lib/levels.mjs";
|
|
2
|
+
import { Plugin, Transport } from "./mods.mjs";
|
|
3
|
+
import { BatchingOptions } from "./batching.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/types/logger.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Represents a single log entry created by the Logger.
|
|
8
|
+
*/
|
|
9
|
+
interface LogEntry {
|
|
10
|
+
/**
|
|
11
|
+
* Timestamp when the entry was created.
|
|
12
|
+
*/
|
|
13
|
+
time: Date;
|
|
14
|
+
/**
|
|
15
|
+
* Severity level of the entry.
|
|
16
|
+
*/
|
|
17
|
+
level: LogLevel;
|
|
18
|
+
/**
|
|
19
|
+
* Arbitrary data passed by the user.
|
|
20
|
+
*/
|
|
21
|
+
data: unknown[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options passed to the Logger constructor or clone.
|
|
25
|
+
*/
|
|
26
|
+
interface LoggerOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Minimum severity level to emit.
|
|
29
|
+
* @default LogLevels.INFO
|
|
30
|
+
*/
|
|
31
|
+
level?: LogLevel;
|
|
32
|
+
/**
|
|
33
|
+
* Destination transports where log entries will be delivered.
|
|
34
|
+
*/
|
|
35
|
+
transports?: Transport[];
|
|
36
|
+
/**
|
|
37
|
+
* Plugins that can enrich logger or transform log entries.
|
|
38
|
+
*/
|
|
39
|
+
plugins?: Plugin[];
|
|
40
|
+
/**
|
|
41
|
+
* Optional batching configuration.
|
|
42
|
+
*/
|
|
43
|
+
batching?: BatchingOptions;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { LogEntry, LoggerOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { LogEntry } from "./logger.mjs";
|
|
2
|
+
import { Logger } from "../core/logger.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/types/mods.d.ts
|
|
5
|
+
interface Mod<Tag extends string> {
|
|
6
|
+
readonly _tag: Tag;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A plugin can extend the Logger with transformations or enrichments.
|
|
10
|
+
*/
|
|
11
|
+
interface Plugin<EnrichedLogger extends Logger = Logger> extends Mod<"plugin"> {
|
|
12
|
+
/**
|
|
13
|
+
* Unique plugin name.
|
|
14
|
+
* @example "rate-limiter"
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Transform a log entry before it is emitted.
|
|
19
|
+
*/
|
|
20
|
+
transformEntry?(logger: EnrichedLogger, entry: LogEntry): LogEntry | Promise<LogEntry>;
|
|
21
|
+
/**
|
|
22
|
+
* Enrich the Logger instance with additional methods or props.
|
|
23
|
+
* May return sync or async.
|
|
24
|
+
*/
|
|
25
|
+
enrichLogger?(logger: Logger): EnrichedLogger | Promise<EnrichedLogger>;
|
|
26
|
+
/**
|
|
27
|
+
* Cleanup called when logger closes.
|
|
28
|
+
* @property
|
|
29
|
+
*/
|
|
30
|
+
teardown?(logger: EnrichedLogger): Logger;
|
|
31
|
+
/**
|
|
32
|
+
* Optional dispose hook (sync).
|
|
33
|
+
*/
|
|
34
|
+
[Symbol.dispose]?(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Optional dispose hook (async).
|
|
37
|
+
*/
|
|
38
|
+
[Symbol.asyncDispose]?(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A transport is responsible for delivering log entries to a destination
|
|
42
|
+
* (console, file, remote API, etc.).
|
|
43
|
+
*/
|
|
44
|
+
interface Transport extends Mod<"transport"> {
|
|
45
|
+
/**
|
|
46
|
+
* Unique transport name.
|
|
47
|
+
* @example "websocket"
|
|
48
|
+
*/
|
|
49
|
+
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* Send a single log entry.
|
|
52
|
+
* Called immediately unless batching is enabled.
|
|
53
|
+
*/
|
|
54
|
+
send(logger: Logger, entry: LogEntry): void | Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Send a batch of log entries at once.
|
|
57
|
+
* Used if available when batching is enabled.
|
|
58
|
+
*/
|
|
59
|
+
batch?(logger: Logger, batch: LogEntry[]): void | Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Optional cleanup invoked during logger shutdown.
|
|
62
|
+
*/
|
|
63
|
+
teardown?(logger: Logger): void | Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Optional sync dispose hook.
|
|
66
|
+
*/
|
|
67
|
+
[Symbol.dispose]?(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Optional async dispose hook.
|
|
70
|
+
*/
|
|
71
|
+
[Symbol.asyncDispose]?(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { Mod, Plugin, Transport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@padosoft/logger",
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./dist/index.d.mts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"url": "git+https://github.com/padosoft/ts-support.git"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsdown",
|
|
18
|
+
"ts:check": "tsc --noEmit"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@padosoft/config": "workspace:^",
|
|
22
|
+
"@opentelemetry/api": "^1.9.1",
|
|
23
|
+
"@opentelemetry/api-logs": "^0.219.0",
|
|
24
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.219.0",
|
|
25
|
+
"@opentelemetry/resources": "^2.8.0",
|
|
26
|
+
"@opentelemetry/sdk-logs": "^0.219.0",
|
|
27
|
+
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
28
|
+
"expo-file-system": "^56.0.8",
|
|
29
|
+
"expo-application": "^56.0.3"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@opentelemetry/api": "*",
|
|
34
|
+
"@opentelemetry/api-logs": "*",
|
|
35
|
+
"@opentelemetry/exporter-logs-otlp-http": "*",
|
|
36
|
+
"@opentelemetry/resources": "*",
|
|
37
|
+
"@opentelemetry/sdk-logs": "*",
|
|
38
|
+
"@opentelemetry/semantic-conventions": "*",
|
|
39
|
+
"expo-file-system": "*",
|
|
40
|
+
"expo-application": "*"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@opentelemetry/api": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"@opentelemetry/api-logs": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@opentelemetry/resources": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@opentelemetry/exporter-logs-otlp-http": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@opentelemetry/sdk-logs": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@opentelemetry/semantic-conventions": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"expo-file-system": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"exports": {
|
|
66
|
+
".": {
|
|
67
|
+
"default": "./dist/index.mjs",
|
|
68
|
+
"types": "./dist/index.d.mts"
|
|
69
|
+
},
|
|
70
|
+
"./adapters/drizzle": {
|
|
71
|
+
"default": "./dist/adapters/drizzle.mjs",
|
|
72
|
+
"types": "./dist/adapters/drizzle.d.mts"
|
|
73
|
+
},
|
|
74
|
+
"./adapters/hono": {
|
|
75
|
+
"default": "./dist/adapters/hono.mjs",
|
|
76
|
+
"types": "./dist/adapters/hono.d.mts"
|
|
77
|
+
},
|
|
78
|
+
"./core/logger": {
|
|
79
|
+
"default": "./dist/core/logger.mjs",
|
|
80
|
+
"types": "./dist/core/logger.d.mts"
|
|
81
|
+
},
|
|
82
|
+
"./lib": {
|
|
83
|
+
"default": "./dist/lib/index.mjs",
|
|
84
|
+
"types": "./dist/lib/index.d.mts"
|
|
85
|
+
},
|
|
86
|
+
"./lib/format": {
|
|
87
|
+
"default": "./dist/lib/format.mjs",
|
|
88
|
+
"types": "./dist/lib/format.d.mts"
|
|
89
|
+
},
|
|
90
|
+
"./lib/levels": {
|
|
91
|
+
"default": "./dist/lib/levels.mjs",
|
|
92
|
+
"types": "./dist/lib/levels.d.mts"
|
|
93
|
+
},
|
|
94
|
+
"./lib/mods": {
|
|
95
|
+
"default": "./dist/lib/mods.mjs",
|
|
96
|
+
"types": "./dist/lib/mods.d.mts"
|
|
97
|
+
},
|
|
98
|
+
"./lib/utils": {
|
|
99
|
+
"default": "./dist/lib/utils.mjs",
|
|
100
|
+
"types": "./dist/lib/utils.d.mts"
|
|
101
|
+
},
|
|
102
|
+
"./plugins/context": {
|
|
103
|
+
"default": "./dist/plugins/context.mjs",
|
|
104
|
+
"types": "./dist/plugins/context.d.mts"
|
|
105
|
+
},
|
|
106
|
+
"./plugins/metrics": {
|
|
107
|
+
"default": "./dist/plugins/metrics.mjs",
|
|
108
|
+
"types": "./dist/plugins/metrics.d.mts"
|
|
109
|
+
},
|
|
110
|
+
"./plugins/rate-limiter": {
|
|
111
|
+
"default": "./dist/plugins/rate-limiter.mjs",
|
|
112
|
+
"types": "./dist/plugins/rate-limiter.d.mts"
|
|
113
|
+
},
|
|
114
|
+
"./shared": {
|
|
115
|
+
"default": "./dist/shared.mjs",
|
|
116
|
+
"types": "./dist/shared.d.mts"
|
|
117
|
+
},
|
|
118
|
+
"./transports/console": {
|
|
119
|
+
"default": "./dist/transports/console/index.mjs",
|
|
120
|
+
"types": "./dist/transports/console/index.d.mts"
|
|
121
|
+
},
|
|
122
|
+
"./transports/console/lib/colors": {
|
|
123
|
+
"default": "./dist/transports/console/lib/colors.mjs",
|
|
124
|
+
"types": "./dist/transports/console/lib/colors.d.mts"
|
|
125
|
+
},
|
|
126
|
+
"./transports/console/lib/symbols": {
|
|
127
|
+
"default": "./dist/transports/console/lib/symbols.mjs",
|
|
128
|
+
"types": "./dist/transports/console/lib/symbols.d.mts"
|
|
129
|
+
},
|
|
130
|
+
"./transports/console/lib/utils": {
|
|
131
|
+
"default": "./dist/transports/console/lib/utils.mjs",
|
|
132
|
+
"types": "./dist/transports/console/lib/utils.d.mts"
|
|
133
|
+
},
|
|
134
|
+
"./transports/console/types": {
|
|
135
|
+
"default": "./dist/transports/console/types.mjs",
|
|
136
|
+
"types": "./dist/transports/console/types.d.mts"
|
|
137
|
+
},
|
|
138
|
+
"./transports/discord": {
|
|
139
|
+
"default": "./dist/transports/discord/index.mjs",
|
|
140
|
+
"types": "./dist/transports/discord/index.d.mts"
|
|
141
|
+
},
|
|
142
|
+
"./transports/expo-fs": {
|
|
143
|
+
"default": "./dist/transports/expo-fs/index.mjs",
|
|
144
|
+
"types": "./dist/transports/expo-fs/index.d.mts"
|
|
145
|
+
},
|
|
146
|
+
"./transports/expo-fs/lib/constants": {
|
|
147
|
+
"default": "./dist/transports/expo-fs/lib/constants.mjs",
|
|
148
|
+
"types": "./dist/transports/expo-fs/lib/constants.d.mts"
|
|
149
|
+
},
|
|
150
|
+
"./transports/expo-fs/lib/file-logger": {
|
|
151
|
+
"default": "./dist/transports/expo-fs/lib/file-logger.mjs",
|
|
152
|
+
"types": "./dist/transports/expo-fs/lib/file-logger.d.mts"
|
|
153
|
+
},
|
|
154
|
+
"./transports/file": {
|
|
155
|
+
"default": "./dist/transports/file.mjs",
|
|
156
|
+
"types": "./dist/transports/file.d.mts"
|
|
157
|
+
},
|
|
158
|
+
"./transports/http": {
|
|
159
|
+
"default": "./dist/transports/http.mjs",
|
|
160
|
+
"types": "./dist/transports/http.d.mts"
|
|
161
|
+
},
|
|
162
|
+
"./transports/otel": {
|
|
163
|
+
"default": "./dist/transports/otel/index.mjs",
|
|
164
|
+
"types": "./dist/transports/otel/index.d.mts"
|
|
165
|
+
},
|
|
166
|
+
"./transports/otel/types": {
|
|
167
|
+
"default": "./dist/transports/otel/types.mjs",
|
|
168
|
+
"types": "./dist/transports/otel/types.d.mts"
|
|
169
|
+
},
|
|
170
|
+
"./transports/otel/utils": {
|
|
171
|
+
"default": "./dist/transports/otel/utils.mjs",
|
|
172
|
+
"types": "./dist/transports/otel/utils.d.mts"
|
|
173
|
+
},
|
|
174
|
+
"./transports/ws": {
|
|
175
|
+
"default": "./dist/transports/ws.mjs",
|
|
176
|
+
"types": "./dist/transports/ws.d.mts"
|
|
177
|
+
},
|
|
178
|
+
"./types": {
|
|
179
|
+
"default": "./dist/types/index.mjs",
|
|
180
|
+
"types": "./dist/types/index.d.mts"
|
|
181
|
+
},
|
|
182
|
+
"./types/batching": {
|
|
183
|
+
"default": "./dist/types/batching.mjs",
|
|
184
|
+
"types": "./dist/types/batching.d.mts"
|
|
185
|
+
},
|
|
186
|
+
"./types/format": {
|
|
187
|
+
"default": "./dist/types/format.mjs",
|
|
188
|
+
"types": "./dist/types/format.d.mts"
|
|
189
|
+
},
|
|
190
|
+
"./types/logger": {
|
|
191
|
+
"default": "./dist/types/logger.mjs",
|
|
192
|
+
"types": "./dist/types/logger.d.mts"
|
|
193
|
+
},
|
|
194
|
+
"./types/mods": {
|
|
195
|
+
"default": "./dist/types/mods.mjs",
|
|
196
|
+
"types": "./dist/types/mods.d.mts"
|
|
197
|
+
},
|
|
198
|
+
"./package.json": "./package.json"
|
|
199
|
+
}
|
|
200
|
+
}
|