tim-logger 0.0.20
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 +7 -0
- package/README.md +0 -0
- package/dist/client.cjs.js +2 -0
- package/dist/client.cjs.js.map +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.es.js +37 -0
- package/dist/client.es.js.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +17 -0
- package/dist/index.es.js.map +1 -0
- package/dist/server.cjs.js +3 -0
- package/dist/server.cjs.js.map +1 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.es.js +134 -0
- package/dist/server.es.js.map +1 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2022 [these people](https://github.com/dht/typing-base/graphs/contributors)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=["console"],f=(o,r,l,e)=>typeof o=="string"?{message:o,level:r,source:l,data:e}:{...o,level:o.level??r,source:o.source??l,data:o.data??e},i=(o={})=>{const r=o.transports?.length?o.transports:w;let l=!1;const e=async(n,t)=>{const u=f(n,"info",o.source,t),c=u.level??"info",d={...u,level:c},a=[];r.includes("console")&&(c==="error"?console.error:c==="warn"?console.warn:console.log)(d),r.includes("custom")&&(o.addLog?a.push(Promise.resolve(o.addLog(d))):l||(l=!0,console.warn("[tim-logger] Custom transport requested without addLog handler."))),a.length&&await Promise.all(a)};return{log:e,info:async(n,t)=>e({message:n,level:"info",data:t,source:o.source}),warn:async(n,t)=>e({message:n,level:"warn",data:t,source:o.source}),error:async(n,t)=>e({message:n,level:"error",data:t,source:o.source})}};let s=i();const g=(o={})=>(s=i(o),s),m=(o,r)=>s.log(o,r),L=(o,r)=>s.info(o,r),p=(o,r)=>s.warn(o,r),y=(o,r)=>s.error(o,r);exports.createClientLogger=i;exports.error=y;exports.info=L;exports.init=g;exports.log=m;exports.warn=p;
|
|
2
|
+
//# sourceMappingURL=client.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.cjs.js","sources":["../src/client.ts"],"sourcesContent":["import type {\n ClientLoggerConfig,\n ClientTransport,\n Json,\n LogEvent,\n LogLevel,\n Logger,\n} from './types';\n\nconst DEFAULT_CLIENT_TRANSPORTS: ClientTransport[] = ['console'];\n\nconst normalizeEvent = (\n eventOrMessage: LogEvent | string,\n level?: LogLevel,\n source?: string,\n data?: Json\n): LogEvent => {\n if (typeof eventOrMessage === 'string') {\n return {\n message: eventOrMessage,\n level,\n source,\n data,\n };\n }\n\n return {\n ...eventOrMessage,\n level: eventOrMessage.level ?? level,\n source: eventOrMessage.source ?? source,\n data: eventOrMessage.data ?? data,\n };\n};\n\nexport const createClientLogger = (config: ClientLoggerConfig = {}): Logger => {\n const transports = config.transports?.length\n ? config.transports\n : DEFAULT_CLIENT_TRANSPORTS;\n let warnedMissingCustom = false;\n\n const log = async (eventOrMessage: LogEvent | string, data?: Json) => {\n const event = normalizeEvent(\n eventOrMessage,\n 'info',\n config.source,\n data\n );\n const resolvedLevel = event.level ?? 'info';\n const payload = { ...event, level: resolvedLevel };\n\n const tasks: Promise<void>[] = [];\n\n if (transports.includes('console')) {\n const consoleMethod =\n resolvedLevel === 'error'\n ? console.error\n : resolvedLevel === 'warn'\n ? console.warn\n : console.log;\n consoleMethod(payload);\n }\n\n if (transports.includes('custom')) {\n if (config.addLog) {\n tasks.push(Promise.resolve(config.addLog(payload)));\n } else if (!warnedMissingCustom) {\n warnedMissingCustom = true;\n console.warn(\n '[tim-logger] Custom transport requested without addLog handler.'\n );\n }\n }\n\n if (tasks.length) {\n await Promise.all(tasks);\n }\n };\n\n const info = async (message: string, data?: Json) =>\n log({ message, level: 'info', data, source: config.source });\n const warn = async (message: string, data?: Json) =>\n log({ message, level: 'warn', data, source: config.source });\n const error = async (message: string, data?: Json) =>\n log({ message, level: 'error', data, source: config.source });\n\n return { log, info, warn, error };\n};\n\nlet defaultLogger = createClientLogger();\n\nexport const init = (config: ClientLoggerConfig = {}) => {\n defaultLogger = createClientLogger(config);\n return defaultLogger;\n};\n\nexport const log = (eventOrMessage: LogEvent | string, data?: Json) =>\n defaultLogger.log(eventOrMessage, data);\nexport const info = (message: string, data?: Json) =>\n defaultLogger.info(message, data);\nexport const warn = (message: string, data?: Json) =>\n defaultLogger.warn(message, data);\nexport const error = (message: string, data?: Json) =>\n defaultLogger.error(message, data);\n"],"names":["DEFAULT_CLIENT_TRANSPORTS","normalizeEvent","eventOrMessage","level","source","data","createClientLogger","config","transports","warnedMissing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AO,QAAS,KAAAV,EAAM,OAAQE,EAAO,OAAQ,CAEtCS,CAC9B,EAEA,IAAIC,EAAgBX,EAAA,EAEb,MAAMY,EAAO,CAACX,EAA6B,MAC9CU,EAAgBX,EAAmBC,CAAM,EAClCU,GAGEP,EAAM,CAACR,EAAmCG,IACnDY,EAAc,IAAIf,EAAgBG,CAAI,EAC7Bc,EAAO,CAACJ,EAAiBV,IAClCY,EAAc,KAAKF,EAASV,CAAI,EACvBe,EAAO,CAACL,EAAiBV,IAClCY,EAAc,KAAKF,EAASV,CAAI,EACvBW,EAAQ,CAACD,EAAiBV,IACnCY,EAAc,MAAMF,EAASV,CAAI"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ClientLoggerConfig, Json, LogEvent, Logger } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const createClientLogger: (config?: ClientLoggerConfig) => Logger;
|
|
4
|
+
export declare const init: (config?: ClientLoggerConfig) => Logger;
|
|
5
|
+
export declare const log: (eventOrMessage: LogEvent | string, data?: Json) => Promise<void>;
|
|
6
|
+
export declare const info: (message: string, data?: Json) => Promise<void>;
|
|
7
|
+
export declare const warn: (message: string, data?: Json) => Promise<void>;
|
|
8
|
+
export declare const error: (message: string, data?: Json) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,kBAAkB,EAElB,IAAI,EACJ,QAAQ,EAER,MAAM,EACT,MAAM,SAAS,CAAC;AA2BjB,eAAO,MAAM,kBAAkB,GAAI,SAAQ,kBAAuB,KAAG,MAoDpE,CAAC;AAIF,eAAO,MAAM,IAAI,GAAI,SAAQ,kBAAuB,WAGnD,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,gBAAgB,QAAQ,GAAG,MAAM,EAAE,OAAO,IAAI,kBACvB,CAAC;AAC5C,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC;AACtC,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC;AACtC,eAAO,MAAM,KAAK,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const w = ["console"], f = (o, r, l, e) => typeof o == "string" ? {
|
|
2
|
+
message: o,
|
|
3
|
+
level: r,
|
|
4
|
+
source: l,
|
|
5
|
+
data: e
|
|
6
|
+
} : {
|
|
7
|
+
...o,
|
|
8
|
+
level: o.level ?? r,
|
|
9
|
+
source: o.source ?? l,
|
|
10
|
+
data: o.data ?? e
|
|
11
|
+
}, d = (o = {}) => {
|
|
12
|
+
const r = o.transports?.length ? o.transports : w;
|
|
13
|
+
let l = !1;
|
|
14
|
+
const e = async (n, s) => {
|
|
15
|
+
const u = f(
|
|
16
|
+
n,
|
|
17
|
+
"info",
|
|
18
|
+
o.source,
|
|
19
|
+
s
|
|
20
|
+
), c = u.level ?? "info", i = { ...u, level: c }, a = [];
|
|
21
|
+
r.includes("console") && (c === "error" ? console.error : c === "warn" ? console.warn : console.log)(i), r.includes("custom") && (o.addLog ? a.push(Promise.resolve(o.addLog(i))) : l || (l = !0, console.warn(
|
|
22
|
+
"[tim-logger] Custom transport requested without addLog handler."
|
|
23
|
+
))), a.length && await Promise.all(a);
|
|
24
|
+
};
|
|
25
|
+
return { log: e, info: async (n, s) => e({ message: n, level: "info", data: s, source: o.source }), warn: async (n, s) => e({ message: n, level: "warn", data: s, source: o.source }), error: async (n, s) => e({ message: n, level: "error", data: s, source: o.source }) };
|
|
26
|
+
};
|
|
27
|
+
let t = d();
|
|
28
|
+
const h = (o = {}) => (t = d(o), t), v = (o, r) => t.log(o, r), y = (o, r) => t.info(o, r), C = (o, r) => t.warn(o, r), T = (o, r) => t.error(o, r);
|
|
29
|
+
export {
|
|
30
|
+
d as createClientLogger,
|
|
31
|
+
T as error,
|
|
32
|
+
y as info,
|
|
33
|
+
h as init,
|
|
34
|
+
v as log,
|
|
35
|
+
C as warn
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=client.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.es.js","sources":["../src/client.ts"],"sourcesContent":["import type {\n ClientLoggerConfig,\n ClientTransport,\n Json,\n LogEvent,\n LogLevel,\n Logger,\n} from './types';\n\nconst DEFAULT_CLIENT_TRANSPORTS: ClientTransport[] = ['console'];\n\nconst normalizeEvent = (\n eventOrMessage: LogEvent | string,\n level?: LogLevel,\n source?: string,\n data?: Json\n): LogEvent => {\n if (typeof eventOrMessage === 'string') {\n return {\n message: eventOrMessage,\n level,\n source,\n data,\n };\n }\n\n return {\n ...eventOrMessage,\n level: eventOrMessage.level ?? level,\n source: eventOrMessage.source ?? source,\n data: eventOrMessage.data ?? data,\n };\n};\n\nexport const createClientLogger = (config: ClientLoggerConfig = {}): Logger => {\n const transports = config.transports?.length\n ? config.transports\n : DEFAULT_CLIENT_TRANSPORTS;\n let warnedMissingCustom = false;\n\n const log = async (eventOrMessage: LogEvent | string, data?: Json) => {\n const event = normalizeEvent(\n eventOrMessage,\n 'info',\n config.source,\n data\n );\n const resolvedLevel = event.level ?? 'info';\n const payload = { ...event, level: resolvedLevel };\n\n const tasks: Promise<void>[] = [];\n\n if (transports.includes('console')) {\n const consoleMethod =\n resolvedLevel === 'error'\n ? console.error\n : resolvedLevel === 'warn'\n ? console.warn\n : console.log;\n consoleMethod(payload);\n }\n\n if (transports.includes('custom')) {\n if (config.addLog) {\n tasks.push(Promise.resolve(config.addLog(payload)));\n } else if (!warnedMissingCustom) {\n warnedMissingCustom = true;\n console.warn(\n '[tim-logger] Custom transport requested without addLog handler.'\n );\n }\n }\n\n if (tasks.length) {\n await Promise.all(tasks);\n }\n };\n\n const info = async (message: string, data?: Json) =>\n log({ message, level: 'info', data, source: config.source });\n const warn = async (message: string, data?: Json) =>\n log({ message, level: 'warn', data, source: config.source });\n const error = async (message: string, data?: Json) =>\n log({ message, level: 'error', data, source: config.source });\n\n return { log, info, warn, error };\n};\n\nlet defaultLogger = createClientLogger();\n\nexport const init = (config: ClientLoggerConfig = {}) => {\n defaultLogger = createClientLogger(config);\n return defaultLogger;\n};\n\nexport const log = (eventOrMessage: LogEvent | string, data?: Json) =>\n defaultLogger.log(eventOrMessage, data);\nexport const info = (message: string, data?: Json) =>\n defaultLogger.info(message, data);\nexport const warn = (message: string, data?: Json) =>\n defaultLogger.warn(message, data);\nexport const error = (message: string, data?: Json) =>\n defaultLogger.error(message, data);\n"],"names":["DEFAULT_CLIENT_TRANSPORTS","normalizeEvent","eventOrMessage","level","source","data","createClientLogger","config","transports","warnedMissingCustom","log","event","resolvedLevel","payload","tasks","message","error","defaultLogger","init","info","warn"],"mappings":"AASA,MAAMA,IAA+C,CAAC,SAAS,GAEzDC,IAAiB,CACnBC,GACAC,GACAC,GACAC,MAEI,OAAOH,KAAmB,WACnB;AAAA,EACH,SAASA;AAAA,EACT,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,MAAAC;AAAA,IAID;AAAA,EACH,GAAGH;AAAA,EACH,OAAOA,EAAe,SAASC;AAAA,EAC/B,QAAQD,EAAe,UAAUE;AAAA,EACjC,MAAMF,EAAe,QAAQG;AAAA,GAIxBC,IAAqB,CAACC,IAA6B,OAAe;AAC3E,QAAMC,IAAaD,EAAO,YAAY,SAChCA,EAAO,aACPP;AACN,MAAIS,IAAsB;AAE1B,QAAMC,IAAM,OAAOR,GAAmCG,MAAgB;AAClE,UAAMM,IAAQV;AAAA,MACVC;AAAA,MACA;AAAA,MACAK,EAAO;AAAA,MACPF;AAAA,IAAA,GAEEO,IAAgBD,EAAM,SAAS,QAC/BE,IAAU,EAAE,GAAGF,GAAO,OAAOC,EAAA,GAE7BE,IAAyB,CAAA;AAE/B,IAAIN,EAAW,SAAS,SAAS,MAEzBI,MAAkB,UACZ,QAAQ,QACRA,MAAkB,SAChB,QAAQ,OACR,QAAQ,KACNC,CAAO,GAGrBL,EAAW,SAAS,QAAQ,MACxBD,EAAO,SACPO,EAAM,KAAK,QAAQ,QAAQP,EAAO,OAAOM,CAAO,CAAC,CAAC,IAC1CJ,MACRA,IAAsB,IACtB,QAAQ;AAAA,MACJ;AAAA,IAAA,KAKRK,EAAM,UACN,MAAM,QAAQ,IAAIA,CAAK;AAAA,EAE/B;AASA,SAAO,EAAE,KAAAJ,GAAK,MAPD,OAAOK,GAAiBV,MACjCK,EAAI,EAAE,SAAAK,GAAS,OAAO,QAAQ,MAAAV,GAAM,QAAQE,EAAO,QAAQ,GAM3C,MALP,OAAOQ,GAAiBV,MACjCK,EAAI,EAAE,SAAAK,GAAS,OAAO,QAAQ,MAAAV,GAAM,QAAQE,EAAO,QAAQ,GAIrC,OAHZ,OAAOQ,GAAiBV,MAClCK,EAAI,EAAE,SAAAK,GAAS,OAAO,SAAS,MAAAV,GAAM,QAAQE,EAAO,QAAQ,EAEtCS;AAC9B;AAEA,IAAIC,IAAgBX,EAAA;AAEb,MAAMY,IAAO,CAACX,IAA6B,QAC9CU,IAAgBX,EAAmBC,CAAM,GAClCU,IAGEP,IAAM,CAACR,GAAmCG,MACnDY,EAAc,IAAIf,GAAgBG,CAAI,GAC7Bc,IAAO,CAACJ,GAAiBV,MAClCY,EAAc,KAAKF,GAASV,CAAI,GACvBe,IAAO,CAACL,GAAiBV,MAClCY,EAAc,KAAKF,GAASV,CAAI,GACvBW,IAAQ,CAACD,GAAiBV,MACnCY,EAAc,MAAMF,GAASV,CAAI;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./client.cjs.js"),r=require("./server.cjs.js");exports.clientError=e.error;exports.clientInfo=e.info;exports.clientLog=e.log;exports.clientWarn=e.warn;exports.createClientLogger=e.createClientLogger;exports.initClientLogger=e.init;exports.createServerLogger=r.createServerLogger;exports.initServerLogger=r.init;exports.serverError=r.error;exports.serverInfo=r.info;exports.serverLog=r.log;exports.serverWarn=r.warn;
|
|
2
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { error as clientError, info as clientInfo, log as clientLog, warn as clientWarn, createClientLogger, init as initClientLogger, } from './client';
|
|
2
|
+
export { createServerLogger, init as initServerLogger, error as serverError, info as serverInfo, log as serverLog, warn as serverWarn, } from './server';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export type { LogEvent } from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,IAAI,WAAW,EACpB,IAAI,IAAI,UAAU,EAClB,GAAG,IAAI,SAAS,EAChB,IAAI,IAAI,UAAU,EAClB,kBAAkB,EAClB,IAAI,IAAI,gBAAgB,GAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,kBAAkB,EAClB,IAAI,IAAI,gBAAgB,EACxB,KAAK,IAAI,WAAW,EACpB,IAAI,IAAI,UAAU,EAClB,GAAG,IAAI,SAAS,EAChB,IAAI,IAAI,UAAU,GACrB,MAAM,UAAU,CAAC;AAClB,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { error as o, info as n, log as a, warn as i, createClientLogger as s, init as t } from "./client.es.js";
|
|
2
|
+
import { createServerLogger as l, init as c, error as f, info as v, log as L, warn as m } from "./server.es.js";
|
|
3
|
+
export {
|
|
4
|
+
o as clientError,
|
|
5
|
+
n as clientInfo,
|
|
6
|
+
a as clientLog,
|
|
7
|
+
i as clientWarn,
|
|
8
|
+
s as createClientLogger,
|
|
9
|
+
l as createServerLogger,
|
|
10
|
+
t as initClientLogger,
|
|
11
|
+
c as initServerLogger,
|
|
12
|
+
f as serverError,
|
|
13
|
+
v as serverInfo,
|
|
14
|
+
L as serverLog,
|
|
15
|
+
m as serverWarn
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("kleur"),a=require("winston"),$=a.format.combine(a.format.timestamp({format:()=>new Date().toISOString()}),a.format.printf(o=>{const t=o.logEvent??{},c=new Date().toISOString(),r=String(t.source??"LOG"),e=String(t.message??o.message??""),n=t.data??{},s=n&&typeof n=="object"&&Object.keys(n).length?` | ${JSON.stringify(n)}`:"";return`[${c}] ${r.padStart(12)}: ${e}${s}`})),b=["console"],L=(o,t,c,r)=>typeof o=="string"?{message:o,level:t,source:c,data:r}:{...o,level:o.level??t,source:o.source??c,data:o.data??r},h=o=>{if(!o)return"";try{return JSON.stringify(o)}catch{return"[unserializable data]"}},v=a.format.combine(a.format.timestamp(),a.format.errors({stack:!0}),a.format.colorize({all:!0}),a.format.printf(o=>{const{timestamp:t,level:c="info",message:r="",stack:e,logEvent:n}=o,s=n??{},d=s.source??"LOG",y=s.verb??c?.toUpperCase?.()??"LOG",i=[s.machineId,s.sessionId].filter(Boolean),l=i.length?u.gray(` [${i.join(" ")}]`):"",m=s.data?u.gray(` ${h(s.data)}`):"",p=typeof s.duration=="number"?u.yellow(` ${s.duration}ms`):"",g=`${t} ${u.bold(`[${d}]`)} ${u.cyan(y)} ${r}${p}${l}${m}`;return e?`${g}
|
|
2
|
+
${e}`:g})),w=(o={})=>{const t=o.transports?.length?o.transports:b;let c=!1;const r=[];t.includes("console")&&r.push(new a.transports.Console({format:v})),t.includes("fs")&&r.push(new a.transports.File({filename:o.fsPath??"log.txt",options:{flags:"a"},format:$}));const e=a.createLogger({level:"info",transports:r.length?r:[new a.transports.Console]}),n=async(i,l)=>{const m=L(i,"info",o.source,l),p=m.level??"info",g={...m,level:p,timestamp:m.timestamp??Date.now()};e.log({level:p,message:g.message,logEvent:g}),t.includes("custom")&&(o.addLog?await Promise.resolve(o.addLog(g)):c||(c=!0,console.warn("[tim-logger] Custom transport requested without addLog handler.")))};return{log:n,info:async(i,l)=>n({message:i,level:"info",data:l,source:o.source}),warn:async(i,l)=>n({message:i,level:"warn",data:l,source:o.source}),error:async(i,l)=>n({message:i,level:"error",data:l,source:o.source})}};let f=w();const E=(o={})=>(f=w(o),f),C=(o,t)=>f.log(o,t),O=(o,t)=>f.info(o,t),j=(o,t)=>f.warn(o,t),k=(o,t)=>f.error(o,t),S=["log","info","warn","error"],D=o=>{if(typeof o=="string")return o;if(o instanceof Error)return o.stack||o.message||o.toString();try{return JSON.stringify(o)}catch{return String(o)}},P=(o,t={})=>{const{defaults:c={}}=t,r={log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console)};return S.forEach(e=>{console[e]=(...n)=>{const s=e==="warn"?"warn":e==="error"?"error":"info",d=n.map(D).join(" ");o.log({message:d,level:s,...c})}}),()=>{S.forEach(e=>{console[e]=r[e]})}};exports.createServerLogger=w;exports.error=k;exports.info=O;exports.init=E;exports.interceptConsoleLogs=P;exports.log=C;exports.warn=j;
|
|
3
|
+
//# sourceMappingURL=server.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.cjs.js","sources":["../src/server.ts"],"sourcesContent":["import kleur from 'kleur';\nimport type { TransformableInfo } from 'logform';\nimport {\n createLogger as createWinstonLogger,\n format,\n transports,\n} from 'winston';\nimport type TransportStream from 'winston-transport';\nimport type {\n ConsoleInterceptOptions,\n Json,\n LogEvent,\n LogLevel,\n Logger,\n ServerLoggerConfig,\n ServerTransport,\n} from './types';\n\ntype FileInfo = TransformableInfo & {\n logEvent?: Partial<LogEvent>;\n};\n\nconst fileLineFormat = format.combine(\n format.timestamp({ format: () => new Date().toISOString() }),\n format.printf((info: FileInfo) => {\n const entry = info.logEvent ?? {};\n\n const timestamp = new Date().toISOString();\n\n // \"name\" in your desired output = source (fallback to LOG)\n const name = String(entry.source ?? 'LOG');\n\n // \"text\" in your desired output = message\n const text = String(entry.message ?? info.message ?? '');\n\n // \"data\" in your desired output = entry.data (fallback {})\n const data = (entry.data ?? {}) as Record<string, unknown>;\n const dataString =\n data && typeof data === 'object' && Object.keys(data).length\n ? ` | ${JSON.stringify(data)}`\n : '';\n\n return `[${timestamp}] ${name.padStart(12)}: ${text}${dataString}`;\n })\n);\nconst DEFAULT_SERVER_TRANSPORTS: ServerTransport[] = ['console'];\n\ntype ConsoleInfo = TransformableInfo & {\n timestamp?: string;\n stack?: string;\n logEvent?: Partial<LogEvent>;\n};\n\nconst normalizeEvent = (\n eventOrMessage: LogEvent | string,\n level?: LogLevel,\n source?: string,\n data?: Json\n): LogEvent => {\n if (typeof eventOrMessage === 'string') {\n return {\n message: eventOrMessage,\n level,\n source,\n data,\n } as LogEvent;\n }\n\n return {\n ...eventOrMessage,\n level: eventOrMessage.level ?? level,\n source: eventOrMessage.source ?? source,\n data: eventOrMessage.data ?? data,\n };\n};\n\nconst stringifyData = (data?: Json) => {\n if (!data) return '';\n try {\n return JSON.stringify(data);\n } catch {\n return '[unserializable data]';\n }\n};\n\nconst consoleFormat = format.combine(\n format.timestamp(),\n format.errors({ stack: true }),\n format.colorize({ all: true }),\n format.printf((info: ConsoleInfo) => {\n const {\n timestamp,\n level = 'info',\n message = '',\n stack,\n logEvent,\n } = info;\n\n const entry: Partial<LogEvent> = logEvent ?? {};\n const source = entry.source ?? 'LOG';\n const verb = entry.verb ?? level?.toUpperCase?.() ?? 'LOG';\n\n const contextParts = [entry.machineId, entry.sessionId].filter(Boolean);\n const ctx = contextParts.length\n ? kleur.gray(` [${contextParts.join(' ')}]`)\n : '';\n\n const data = entry.data\n ? kleur.gray(` ${stringifyData(entry.data)}`)\n : '';\n\n const duration =\n typeof entry.duration === 'number'\n ? kleur.yellow(` ${entry.duration}ms`)\n : '';\n\n const base = `${timestamp} ${kleur.bold(`[${source}]`)} ${kleur.cyan(\n verb\n )} ${message}${duration}${ctx}${data}`;\n\n return stack ? `${base}\\n${stack}` : base;\n })\n);\n\n// renamed to avoid clashing with winston's createLogger\nexport const createServerLogger = (config: ServerLoggerConfig = {}): Logger => {\n const transportsArr = config.transports?.length\n ? config.transports\n : DEFAULT_SERVER_TRANSPORTS;\n let warnedMissingCustom = false;\n\n const winstonTransports: TransportStream[] = [];\n\n if (transportsArr.includes('console')) {\n winstonTransports.push(\n new transports.Console({\n format: consoleFormat,\n })\n );\n }\n\n if (transportsArr.includes('fs')) {\n // Winston's types allow `options?: object` on File transport. :contentReference[oaicite:2]{index=2}\n winstonTransports.push(\n new transports.File({\n filename: config.fsPath ?? 'log.txt',\n options: { flags: 'a' },\n format: fileLineFormat,\n })\n );\n }\n\n const baseLogger = createWinstonLogger({\n level: 'info',\n transports: winstonTransports.length\n ? winstonTransports\n : [new transports.Console()],\n });\n\n const log = async (eventOrMessage: LogEvent | string, data?: Json) => {\n const event = normalizeEvent(\n eventOrMessage,\n 'info',\n config.source,\n data\n );\n const resolvedLevel = event.level ?? 'info';\n\n const payload = {\n ...event,\n level: resolvedLevel,\n timestamp: event.timestamp ?? Date.now(),\n };\n\n baseLogger.log({\n level: resolvedLevel,\n message: payload.message,\n logEvent: payload,\n });\n\n if (transportsArr.includes('custom')) {\n if (config.addLog) {\n await Promise.resolve(config.addLog(payload));\n } else if (!warnedMissingCustom) {\n warnedMissingCustom = true;\n console.warn(\n '[tim-logger] Custom transport requested without addLog handler.'\n );\n }\n }\n };\n\n const info = async (message: string, data?: Json) =>\n log({\n message,\n level: 'info',\n data,\n source: config.source,\n } as LogEvent);\n\n const warn = async (message: string, data?: Json) =>\n log({\n message,\n level: 'warn',\n data,\n source: config.source,\n } as LogEvent);\n\n const error = async (message: string, data?: Json) =>\n log({\n message,\n level: 'error',\n data,\n source: config.source,\n } as LogEvent);\n\n return { log, info, warn, error };\n};\n\nlet defaultLogger = createServerLogger();\n\nexport const init = (config: ServerLoggerConfig = {}) => {\n defaultLogger = createServerLogger(config);\n return defaultLogger;\n};\n\nexport const log = (eventOrMessage: LogEvent | string, data?: Json) =>\n defaultLogger.log(eventOrMessage, data);\nexport const info = (message: string, data?: Json) =>\n defaultLogger.info(message, data);\nexport const warn = (message: string, data?: Json) =>\n defaultLogger.warn(message, data);\nexport const error = (message: string, data?: Json) =>\n defaultLogger.error(message, data);\n\nconst consoleMethods = ['log', 'info', 'warn', 'error'] as const;\ntype ConsoleMethod = (typeof consoleMethods)[number];\n\nconst serializeConsoleValue = (value: unknown) => {\n if (typeof value === 'string') return value;\n if (value instanceof Error)\n return value.stack || value.message || value.toString();\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nexport const interceptConsoleLogs = (\n logger: Logger,\n options: ConsoleInterceptOptions = {}\n) => {\n const { defaults = {} } = options;\n\n const originals: Record<ConsoleMethod, (...args: any[]) => void> = {\n log: console.log.bind(console),\n info: console.info.bind(console),\n warn: console.warn.bind(console),\n error: console.error.bind(console),\n };\n\n consoleMethods.forEach((method) => {\n console[method] = (...args: any[]) => {\n const level: LogLevel =\n method === 'warn'\n ? 'warn'\n : method === 'error'\n ? 'error'\n : 'info';\n\n const message = args.map(serializeConsoleValue).join(' ');\n void logger.log({ message, level, ...defaults });\n };\n });\n\n return () => {\n consoleMethods.forEach((method) => {\n console[method] = originals[method];\n });\n };\n};\n"],"names":["fileLineFormat","format","info","entry","timestamp","name","text","data","dataString","DEFAULT_SERVER_TRANSPORTS","normalizeEvent","eventOrMessage","level","source","stringifyData","consoleFormat","message","stack","logEvent","verb","contextParts","ctx","kleur","duration","base","createServerLogger","config","transportsArr","warnedMissingCustom","winstonTransports","transports","baseLogger","createWinstonLogger","log","event","resolvedLevel","payload","error","defaultLogger","init","warn","consoleMethods","serializeConsoleValue","value","interceptConsoleLogs","logger","options","defaults","originals","method","args"],"mappings":"8HAsBMA,EAAiBC,EAAAA,OAAO,QAC1BA,SAAO,UAAU,CAAE,OAAQ,QAAU,KAAA,EAAO,YAAA,EAAe,EAC3DA,SAAO,OAAQC,GAAmB,CAC9B,MAAMC,EAAQD,EAAK,UAAY,CAAA,EAEzBE,EAAY,IAAI,KAAA,EAAO,YAAA,EAGvBC,EAAO,OAAOF,EAAM,QAAU,KAAK,EAGnCG,EAAO,OAAOH,EAAM,SAAWD,EAAK,SAAW,EAAE,EAGjDK,EAAQJ,EAAM,MAAQ,CAAA,EACtBK,EACFD,GAAQ,OAAOA,GAAS,UAAY,OAAO,KAAKA,CAAI,EAAE,OAChD,MAAM,KAAK,UAAUA,CAAI,CAAC,GAC1B,GAEV,MAAO,IAAIH,CAAS,KAAKC,EAAK,SAAS,EAAE,CAAC,KAAKC,CAAI,GAAGE,CAAU,EACpE,CAAC,CACL,EACMC,EAA+C,CAAC,SAAS,EAQzDC,EAAiB,CACnBC,EACAC,EACAC,EACAN,IAEI,OAAOI,GAAmB,SACnB,CACH,QAASA,EACT,MAAAC,EACA,OAAAC,EACA,KAAAN,CAAA,EAID,CACH,GAAGI,EACH,MAAOA,EAAe,OAASC,EAC/B,OAAQD,EAAe,QAAUE,EACjC,KAAMF,EAAe,MAAQJ,CAAA,EAI/BO,EAAiBP,GAAgB,CACnC,GAAI,CAACA,EAAM,MAAO,GAClB,GAAI,CACA,OAAO,KAAK,UAAUA,CAAI,CAC9B,MAAQ,CACJ,MAAO,uBACX,CACJ,EAEMQ,EAAgBd,EAAAA,OAAO,QACzBA,EAAAA,OAAO,UAAA,EACPA,EAAAA,OAAO,OAAO,CAAE,MAAO,GAAM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AAQ,CAACrB,EAAiBT,IACnC+B,EAAc,MAAMtB,EAAST,CAAI,EAE/BkC,EAAiB,CAAC,MAAO,OAAQ,OAAQ,OAAO,EAGhDC,EAAyBC,GAAmB,CAC9C,GAAI,OAAOA,GAAU,SAAU,OAAOA,EACtC,GAAIA,aAAiB,MACjB,OAAOA,EAAM,OAASA,EAAM,SAAWA,EAAM,SAAA,EACjD,GAAI,CACA,OAAO,KAAK,UAAUA,CAAK,CAC/B,MAAQ,CACJ,OAAO,OAAOA,CAAK,CACvB,CACJ,EAEaC,EAAuB,CAChCC,EACAC,EAAmC,KAClC,CACD,KAAM,CAAE,SAAAC,EAAW,CAAA,CAAC,EAAMD,EAEpBE,EAA6D,CAC/D,IAAK,QAAQ,IAAI,KAAK,OAAO,EAC7B,KAAM,QAAQ,KAAK,KAAK,OAAO,EAC/B,KAAM,QAAQ,KAAK,KAAK,OAAO,EAC/B,MAAO,QAAQ,MAAM,KAAK,OAAO,CAAA,EAGrC,OAAAP,EAAe,QAASQ,GAAW,CAC/B,QAAQA,CAAM,EAAI,IAAIC,IAAgB,CAClC,MAAMtC,EACFqC,IAAW,OACL,OACAA,IAAW,QACT,QACA,OAENjC,EAAUkC,EAAK,IAAIR,CAAqB,EAAE,KAAK,GAAG,EACnDG,EAAO,IAAI,CAAE,QAAA7B,EAAS,MAAAJ,EAAO,GAAGmC,EAAU,CACnD,CACJ,CAAC,EAEM,IAAM,CACTN,EAAe,QAASQ,GAAW,CAC/B,QAAQA,CAAM,EAAID,EAAUC,CAAM,CACtC,CAAC,CACL,CACJ"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConsoleInterceptOptions, Json, LogEvent, Logger, ServerLoggerConfig } from './types';
|
|
2
|
+
|
|
3
|
+
export declare const createServerLogger: (config?: ServerLoggerConfig) => Logger;
|
|
4
|
+
export declare const init: (config?: ServerLoggerConfig) => Logger;
|
|
5
|
+
export declare const log: (eventOrMessage: LogEvent | string, data?: Json) => Promise<void>;
|
|
6
|
+
export declare const info: (message: string, data?: Json) => Promise<void>;
|
|
7
|
+
export declare const warn: (message: string, data?: Json) => Promise<void>;
|
|
8
|
+
export declare const error: (message: string, data?: Json) => Promise<void>;
|
|
9
|
+
export declare const interceptConsoleLogs: (logger: Logger, options?: ConsoleInterceptOptions) => () => void;
|
|
10
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,uBAAuB,EACvB,IAAI,EACJ,QAAQ,EAER,MAAM,EACN,kBAAkB,EAErB,MAAM,SAAS,CAAC;AA6GjB,eAAO,MAAM,kBAAkB,GAAI,SAAQ,kBAAuB,KAAG,MA4FpE,CAAC;AAIF,eAAO,MAAM,IAAI,GAAI,SAAQ,kBAAuB,WAGnD,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,gBAAgB,QAAQ,GAAG,MAAM,EAAE,OAAO,IAAI,kBACvB,CAAC;AAC5C,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC;AACtC,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC;AACtC,eAAO,MAAM,KAAK,GAAI,SAAS,MAAM,EAAE,OAAO,IAAI,kBACZ,CAAC;AAgBvC,eAAO,MAAM,oBAAoB,GAC7B,QAAQ,MAAM,EACd,UAAS,uBAA4B,eA8BxC,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import u from "kleur";
|
|
2
|
+
import { format as l, transports as w, createLogger as b } from "winston";
|
|
3
|
+
const L = l.combine(
|
|
4
|
+
l.timestamp({ format: () => (/* @__PURE__ */ new Date()).toISOString() }),
|
|
5
|
+
l.printf((o) => {
|
|
6
|
+
const t = o.logEvent ?? {}, a = (/* @__PURE__ */ new Date()).toISOString(), r = String(t.source ?? "LOG"), n = String(t.message ?? o.message ?? ""), e = t.data ?? {}, s = e && typeof e == "object" && Object.keys(e).length ? ` | ${JSON.stringify(e)}` : "";
|
|
7
|
+
return `[${a}] ${r.padStart(12)}: ${n}${s}`;
|
|
8
|
+
})
|
|
9
|
+
), h = ["console"], v = (o, t, a, r) => typeof o == "string" ? {
|
|
10
|
+
message: o,
|
|
11
|
+
level: t,
|
|
12
|
+
source: a,
|
|
13
|
+
data: r
|
|
14
|
+
} : {
|
|
15
|
+
...o,
|
|
16
|
+
level: o.level ?? t,
|
|
17
|
+
source: o.source ?? a,
|
|
18
|
+
data: o.data ?? r
|
|
19
|
+
}, E = (o) => {
|
|
20
|
+
if (!o) return "";
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(o);
|
|
23
|
+
} catch {
|
|
24
|
+
return "[unserializable data]";
|
|
25
|
+
}
|
|
26
|
+
}, C = l.combine(
|
|
27
|
+
l.timestamp(),
|
|
28
|
+
l.errors({ stack: !0 }),
|
|
29
|
+
l.colorize({ all: !0 }),
|
|
30
|
+
l.printf((o) => {
|
|
31
|
+
const {
|
|
32
|
+
timestamp: t,
|
|
33
|
+
level: a = "info",
|
|
34
|
+
message: r = "",
|
|
35
|
+
stack: n,
|
|
36
|
+
logEvent: e
|
|
37
|
+
} = o, s = e ?? {}, d = s.source ?? "LOG", y = s.verb ?? a?.toUpperCase?.() ?? "LOG", c = [s.machineId, s.sessionId].filter(Boolean), i = c.length ? u.gray(` [${c.join(" ")}]`) : "", m = s.data ? u.gray(` ${E(s.data)}`) : "", p = typeof s.duration == "number" ? u.yellow(` ${s.duration}ms`) : "", g = `${t} ${u.bold(`[${d}]`)} ${u.cyan(
|
|
38
|
+
y
|
|
39
|
+
)} ${r}${p}${i}${m}`;
|
|
40
|
+
return n ? `${g}
|
|
41
|
+
${n}` : g;
|
|
42
|
+
})
|
|
43
|
+
), S = (o = {}) => {
|
|
44
|
+
const t = o.transports?.length ? o.transports : h;
|
|
45
|
+
let a = !1;
|
|
46
|
+
const r = [];
|
|
47
|
+
t.includes("console") && r.push(
|
|
48
|
+
new w.Console({
|
|
49
|
+
format: C
|
|
50
|
+
})
|
|
51
|
+
), t.includes("fs") && r.push(
|
|
52
|
+
new w.File({
|
|
53
|
+
filename: o.fsPath ?? "log.txt",
|
|
54
|
+
options: { flags: "a" },
|
|
55
|
+
format: L
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
const n = b({
|
|
59
|
+
level: "info",
|
|
60
|
+
transports: r.length ? r : [new w.Console()]
|
|
61
|
+
}), e = async (c, i) => {
|
|
62
|
+
const m = v(
|
|
63
|
+
c,
|
|
64
|
+
"info",
|
|
65
|
+
o.source,
|
|
66
|
+
i
|
|
67
|
+
), p = m.level ?? "info", g = {
|
|
68
|
+
...m,
|
|
69
|
+
level: p,
|
|
70
|
+
timestamp: m.timestamp ?? Date.now()
|
|
71
|
+
};
|
|
72
|
+
n.log({
|
|
73
|
+
level: p,
|
|
74
|
+
message: g.message,
|
|
75
|
+
logEvent: g
|
|
76
|
+
}), t.includes("custom") && (o.addLog ? await Promise.resolve(o.addLog(g)) : a || (a = !0, console.warn(
|
|
77
|
+
"[tim-logger] Custom transport requested without addLog handler."
|
|
78
|
+
)));
|
|
79
|
+
};
|
|
80
|
+
return { log: e, info: async (c, i) => e({
|
|
81
|
+
message: c,
|
|
82
|
+
level: "info",
|
|
83
|
+
data: i,
|
|
84
|
+
source: o.source
|
|
85
|
+
}), warn: async (c, i) => e({
|
|
86
|
+
message: c,
|
|
87
|
+
level: "warn",
|
|
88
|
+
data: i,
|
|
89
|
+
source: o.source
|
|
90
|
+
}), error: async (c, i) => e({
|
|
91
|
+
message: c,
|
|
92
|
+
level: "error",
|
|
93
|
+
data: i,
|
|
94
|
+
source: o.source
|
|
95
|
+
}) };
|
|
96
|
+
};
|
|
97
|
+
let f = S();
|
|
98
|
+
const O = (o = {}) => (f = S(o), f), j = (o, t) => f.log(o, t), z = (o, t) => f.info(o, t), F = (o, t) => f.warn(o, t), I = (o, t) => f.error(o, t), $ = ["log", "info", "warn", "error"], k = (o) => {
|
|
99
|
+
if (typeof o == "string") return o;
|
|
100
|
+
if (o instanceof Error)
|
|
101
|
+
return o.stack || o.message || o.toString();
|
|
102
|
+
try {
|
|
103
|
+
return JSON.stringify(o);
|
|
104
|
+
} catch {
|
|
105
|
+
return String(o);
|
|
106
|
+
}
|
|
107
|
+
}, N = (o, t = {}) => {
|
|
108
|
+
const { defaults: a = {} } = t, r = {
|
|
109
|
+
log: console.log.bind(console),
|
|
110
|
+
info: console.info.bind(console),
|
|
111
|
+
warn: console.warn.bind(console),
|
|
112
|
+
error: console.error.bind(console)
|
|
113
|
+
};
|
|
114
|
+
return $.forEach((n) => {
|
|
115
|
+
console[n] = (...e) => {
|
|
116
|
+
const s = n === "warn" ? "warn" : n === "error" ? "error" : "info", d = e.map(k).join(" ");
|
|
117
|
+
o.log({ message: d, level: s, ...a });
|
|
118
|
+
};
|
|
119
|
+
}), () => {
|
|
120
|
+
$.forEach((n) => {
|
|
121
|
+
console[n] = r[n];
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export {
|
|
126
|
+
S as createServerLogger,
|
|
127
|
+
I as error,
|
|
128
|
+
z as info,
|
|
129
|
+
O as init,
|
|
130
|
+
N as interceptConsoleLogs,
|
|
131
|
+
j as log,
|
|
132
|
+
F as warn
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=server.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.es.js","sources":["../src/server.ts"],"sourcesContent":["import kleur from 'kleur';\nimport type { TransformableInfo } from 'logform';\nimport {\n createLogger as createWinstonLogger,\n format,\n transports,\n} from 'winston';\nimport type TransportStream from 'winston-transport';\nimport type {\n ConsoleInterceptOptions,\n Json,\n LogEvent,\n LogLevel,\n Logger,\n ServerLoggerConfig,\n ServerTransport,\n} from './types';\n\ntype FileInfo = TransformableInfo & {\n logEvent?: Partial<LogEvent>;\n};\n\nconst fileLineFormat = format.combine(\n format.timestamp({ format: () => new Date().toISOString() }),\n format.printf((info: FileInfo) => {\n const entry = info.logEvent ?? {};\n\n const timestamp = new Date().toISOString();\n\n // \"name\" in your desired output = source (fallback to LOG)\n const name = String(entry.source ?? 'LOG');\n\n // \"text\" in your desired output = message\n const text = String(entry.message ?? info.message ?? '');\n\n // \"data\" in your desired output = entry.data (fallback {})\n const data = (entry.data ?? {}) as Record<string, unknown>;\n const dataString =\n data && typeof data === 'object' && Object.keys(data).length\n ? ` | ${JSON.stringify(data)}`\n : '';\n\n return `[${timestamp}] ${name.padStart(12)}: ${text}${dataString}`;\n })\n);\nconst DEFAULT_SERVER_TRANSPORTS: ServerTransport[] = ['console'];\n\ntype ConsoleInfo = TransformableInfo & {\n timestamp?: string;\n stack?: string;\n logEvent?: Partial<LogEvent>;\n};\n\nconst normalizeEvent = (\n eventOrMessage: LogEvent | string,\n level?: LogLevel,\n source?: string,\n data?: Json\n): LogEvent => {\n if (typeof eventOrMessage === 'string') {\n return {\n message: eventOrMessage,\n level,\n source,\n data,\n } as LogEvent;\n }\n\n return {\n ...eventOrMessage,\n level: eventOrMessage.level ?? level,\n source: eventOrMessage.source ?? source,\n data: eventOrMessage.data ?? data,\n };\n};\n\nconst stringifyData = (data?: Json) => {\n if (!data) return '';\n try {\n return JSON.stringify(data);\n } catch {\n return '[unserializable data]';\n }\n};\n\nconst consoleFormat = format.combine(\n format.timestamp(),\n format.errors({ stack: true }),\n format.colorize({ all: true }),\n format.printf((info: ConsoleInfo) => {\n const {\n timestamp,\n level = 'info',\n message = '',\n stack,\n logEvent,\n } = info;\n\n const entry: Partial<LogEvent> = logEvent ?? {};\n const source = entry.source ?? 'LOG';\n const verb = entry.verb ?? level?.toUpperCase?.() ?? 'LOG';\n\n const contextParts = [entry.machineId, entry.sessionId].filter(Boolean);\n const ctx = contextParts.length\n ? kleur.gray(` [${contextParts.join(' ')}]`)\n : '';\n\n const data = entry.data\n ? kleur.gray(` ${stringifyData(entry.data)}`)\n : '';\n\n const duration =\n typeof entry.duration === 'number'\n ? kleur.yellow(` ${entry.duration}ms`)\n : '';\n\n const base = `${timestamp} ${kleur.bold(`[${source}]`)} ${kleur.cyan(\n verb\n )} ${message}${duration}${ctx}${data}`;\n\n return stack ? `${base}\\n${stack}` : base;\n })\n);\n\n// renamed to avoid clashing with winston's createLogger\nexport const createServerLogger = (config: ServerLoggerConfig = {}): Logger => {\n const transportsArr = config.transports?.length\n ? config.transports\n : DEFAULT_SERVER_TRANSPORTS;\n let warnedMissingCustom = false;\n\n const winstonTransports: TransportStream[] = [];\n\n if (transportsArr.includes('console')) {\n winstonTransports.push(\n new transports.Console({\n format: consoleFormat,\n })\n );\n }\n\n if (transportsArr.includes('fs')) {\n // Winston's types allow `options?: object` on File transport. :contentReference[oaicite:2]{index=2}\n winstonTransports.push(\n new transports.File({\n filename: config.fsPath ?? 'log.txt',\n options: { flags: 'a' },\n format: fileLineFormat,\n })\n );\n }\n\n const baseLogger = createWinstonLogger({\n level: 'info',\n transports: winstonTransports.length\n ? winstonTransports\n : [new transports.Console()],\n });\n\n const log = async (eventOrMessage: LogEvent | string, data?: Json) => {\n const event = normalizeEvent(\n eventOrMessage,\n 'info',\n config.source,\n data\n );\n const resolvedLevel = event.level ?? 'info';\n\n const payload = {\n ...event,\n level: resolvedLevel,\n timestamp: event.timestamp ?? Date.now(),\n };\n\n baseLogger.log({\n level: resolvedLevel,\n message: payload.message,\n logEvent: payload,\n });\n\n if (transportsArr.includes('custom')) {\n if (config.addLog) {\n await Promise.resolve(config.addLog(payload));\n } else if (!warnedMissingCustom) {\n warnedMissingCustom = true;\n console.warn(\n '[tim-logger] Custom transport requested without addLog handler.'\n );\n }\n }\n };\n\n const info = async (message: string, data?: Json) =>\n log({\n message,\n level: 'info',\n data,\n source: config.source,\n } as LogEvent);\n\n const warn = async (message: string, data?: Json) =>\n log({\n message,\n level: 'warn',\n data,\n source: config.source,\n } as LogEvent);\n\n const error = async (message: string, data?: Json) =>\n log({\n message,\n level: 'error',\n data,\n source: config.source,\n } as LogEvent);\n\n return { log, info, warn, error };\n};\n\nlet defaultLogger = createServerLogger();\n\nexport const init = (config: ServerLoggerConfig = {}) => {\n defaultLogger = createServerLogger(config);\n return defaultLogger;\n};\n\nexport const log = (eventOrMessage: LogEvent | string, data?: Json) =>\n defaultLogger.log(eventOrMessage, data);\nexport const info = (message: string, data?: Json) =>\n defaultLogger.info(message, data);\nexport const warn = (message: string, data?: Json) =>\n defaultLogger.warn(message, data);\nexport const error = (message: string, data?: Json) =>\n defaultLogger.error(message, data);\n\nconst consoleMethods = ['log', 'info', 'warn', 'error'] as const;\ntype ConsoleMethod = (typeof consoleMethods)[number];\n\nconst serializeConsoleValue = (value: unknown) => {\n if (typeof value === 'string') return value;\n if (value instanceof Error)\n return value.stack || value.message || value.toString();\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n};\n\nexport const interceptConsoleLogs = (\n logger: Logger,\n options: ConsoleInterceptOptions = {}\n) => {\n const { defaults = {} } = options;\n\n const originals: Record<ConsoleMethod, (...args: any[]) => void> = {\n log: console.log.bind(console),\n info: console.info.bind(console),\n warn: console.warn.bind(console),\n error: console.error.bind(console),\n };\n\n consoleMethods.forEach((method) => {\n console[method] = (...args: any[]) => {\n const level: LogLevel =\n method === 'warn'\n ? 'warn'\n : method === 'error'\n ? 'error'\n : 'info';\n\n const message = args.map(serializeConsoleValue).join(' ');\n void logger.log({ message, level, ...defaults });\n };\n });\n\n return () => {\n consoleMethods.forEach((method) => {\n console[method] = originals[method];\n });\n };\n};\n"],"names":["fileLineFormat","format","info","entry","timestamp","name","text","data","dataString","DEFAULT_SERVER_TRANSPORTS","normalizeEvent","eventOrMessage","level","source","stringifyData","consoleFormat","message","stack","logEvent","verb","contextParts","ctx","kleur","duration","base","createServerLogger","config","transportsArr","warnedMissingCustom","winstonTransports","transports","baseLogger","createWinstonLogger","log","event","resolvedLevel","payload","error","defaultLogger","init","warn","consoleMethods","serializeConsoleValue","value","interceptConsoleLogs","logger","options","defaults","originals","method","args"],"mappings":";;AAsBA,MAAMA,IAAiBC,EAAO;AAAA,EAC1BA,EAAO,UAAU,EAAE,QAAQ,2BAAU,KAAA,GAAO,YAAA,GAAe;AAAA,EAC3DA,EAAO,OAAO,CAACC,MAAmB;AAC9B,UAAMC,IAAQD,EAAK,YAAY,CAAA,GAEzBE,KAAY,oBAAI,KAAA,GAAO,YAAA,GAGvBC,IAAO,OAAOF,EAAM,UAAU,KAAK,GAGnCG,IAAO,OAAOH,EAAM,WAAWD,EAAK,WAAW,EAAE,GAGjDK,IAAQJ,EAAM,QAAQ,CAAA,GACtBK,IACFD,KAAQ,OAAOA,KAAS,YAAY,OAAO,KAAKA,CAAI,EAAE,SAChD,MAAM,KAAK,UAAUA,CAAI,CAAC,KAC1B;AAEV,WAAO,IAAIH,CAAS,KAAKC,EAAK,SAAS,EAAE,CAAC,KAAKC,CAAI,GAAGE,CAAU;AAAA,EACpE,CAAC;AACL,GACMC,IAA+C,CAAC,SAAS,GAQzDC,IAAiB,CACnBC,GACAC,GACAC,GACAN,MAEI,OAAOI,KAAmB,WACnB;AAAA,EACH,SAASA;AAAA,EACT,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,MAAAN;AAAA,IAID;AAAA,EACH,GAAGI;AAAA,EACH,OAAOA,EAAe,SAASC;AAAA,EAC/B,QAAQD,EAAe,UAAUE;AAAA,EACjC,MAAMF,EAAe,QAAQJ;AAAA,GAI/BO,IAAgB,CAACP,MAAgB;AACnC,MAAI,CAACA,EAAM,QAAO;AAClB,MAAI;AACA,WAAO,KAAK,UAAUA,CAAI;AAAA,EAC9B,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ,GAEMQ,IAAgBd,EAAO;AAAA,EACzBA,EAAO,UAAA;AAAA,EACPA,EAAO,OAAO,EAAE,OAAO,IAAM;AAAA,EAC7BA,EAAO,SAAS,EAAE,KAAK,IAAM;AAAA,EAC7BA,EA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,MAAW;AAC/B,cAAQA,CAAM,IAAID,EAAUC,CAAM;AAAA,IACtC,CAAC;AAAA,EACL;AACJ;"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type Json = Record<string, any>;
|
|
2
|
+
export type LogLevel = 'info' | 'warn' | 'error';
|
|
3
|
+
export type LogEvent = {
|
|
4
|
+
id?: string;
|
|
5
|
+
message: string;
|
|
6
|
+
verb?: string;
|
|
7
|
+
source?: string;
|
|
8
|
+
data?: Json;
|
|
9
|
+
level?: LogLevel;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
duration?: number;
|
|
12
|
+
machineId?: string;
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ConsoleInterceptOptions = {
|
|
16
|
+
defaults?: Partial<LogEvent>;
|
|
17
|
+
};
|
|
18
|
+
export type ClientTransport = 'console' | 'custom';
|
|
19
|
+
export type ServerTransport = 'console' | 'fs' | 'custom';
|
|
20
|
+
export type BaseLoggerConfig = {
|
|
21
|
+
source?: string;
|
|
22
|
+
transports?: string[];
|
|
23
|
+
addLog?: (event: LogEvent) => Promise<void> | void;
|
|
24
|
+
};
|
|
25
|
+
export type ClientLoggerConfig = BaseLoggerConfig & {
|
|
26
|
+
transports?: ClientTransport[];
|
|
27
|
+
};
|
|
28
|
+
export type ServerLoggerConfig = BaseLoggerConfig & {
|
|
29
|
+
transports?: ServerTransport[];
|
|
30
|
+
fsPath?: string;
|
|
31
|
+
};
|
|
32
|
+
export type Logger = {
|
|
33
|
+
log: (event: LogEvent | string, data?: Json) => Promise<void>;
|
|
34
|
+
info: (message: string, data?: Json) => Promise<void>;
|
|
35
|
+
warn: (message: string, data?: Json) => Promise<void>;
|
|
36
|
+
error: (message: string, data?: Json) => Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"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,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACjB,GAAG,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tim-logger",
|
|
3
|
+
"version": "0.0.20",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"watch": "vite build --watch",
|
|
10
|
+
"test": "jest"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@tim/types": "workspace:^",
|
|
14
|
+
"kleur": "^4.1.5",
|
|
15
|
+
"logform": "^2.7.0",
|
|
16
|
+
"winston": "^3.18.3",
|
|
17
|
+
"winston-transport": "^4.9.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/react": "^18.0.25",
|
|
21
|
+
"@types/react-dom": "^19.2.0",
|
|
22
|
+
"typescript": "^5.4.4",
|
|
23
|
+
"vite": "^5.0.3",
|
|
24
|
+
"vite-plugin-dts": "^3.7.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/index.cjs.js",
|
|
30
|
+
"module": "./dist/index.es.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.es.js",
|
|
36
|
+
"require": "./dist/index.cjs.js",
|
|
37
|
+
"default": "./dist/index.es.js"
|
|
38
|
+
},
|
|
39
|
+
"./client": {
|
|
40
|
+
"types": "./dist/client.d.ts",
|
|
41
|
+
"import": "./dist/client.es.js",
|
|
42
|
+
"require": "./dist/client.cjs.js",
|
|
43
|
+
"default": "./dist/client.es.js"
|
|
44
|
+
},
|
|
45
|
+
"./server": {
|
|
46
|
+
"types": "./dist/server.d.ts",
|
|
47
|
+
"import": "./dist/server.es.js",
|
|
48
|
+
"require": "./dist/server.cjs.js",
|
|
49
|
+
"default": "./dist/server.es.js"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|