@cto.af/log 1.3.5 → 1.3.7
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/lib/{index.d.ts → index.d.mts} +26 -25
- package/lib/index.mjs +1 -0
- package/package.json +6 -12
- package/lib/index.js +0 -1
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import pino from
|
|
1
|
+
import pino from "pino";
|
|
2
2
|
|
|
3
|
+
//#region src/index.d.ts
|
|
3
4
|
interface CtoLogOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Increase (or decrease if negative) log verbosity by this much.
|
|
7
|
+
* -3: fatal, -2: error, -1: warn, 0: info, 1: debug, 2: trace.
|
|
8
|
+
* Useful for -qqqvvvv option processing. Default: 0.
|
|
9
|
+
*/
|
|
10
|
+
logLevel?: number;
|
|
11
|
+
/** If a string, create this log file and write to it. */
|
|
12
|
+
logFile?: string | null;
|
|
13
|
+
/** If true, do not log to stdout. */
|
|
14
|
+
mute?: boolean;
|
|
15
|
+
/** If logFile is set, write synchronously if true (for testing). */
|
|
16
|
+
sync?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Ignore this set of comma-separated fields when pretty printing logs
|
|
19
|
+
* to stdout. Default: 'pid,hostname,name,host,port'.
|
|
20
|
+
*/
|
|
21
|
+
prettyIgnore?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Log instance, created by the first layer to call createLog. Alternative
|
|
24
|
+
* to getLog for times when multiple loggers are needed.
|
|
25
|
+
*/
|
|
26
|
+
log?: Logger | null;
|
|
26
27
|
}
|
|
27
28
|
declare const DEFAULT_LOG_OPTIONS: Required<CtoLogOptions>;
|
|
28
29
|
declare const LOG_OPTIONS_NAMES: Set<keyof CtoLogOptions | keyof pino.LoggerOptions<never, false>>;
|
|
@@ -54,5 +55,5 @@ declare function getLog(opts?: LogOptions, bindings?: pino.Bindings): Logger;
|
|
|
54
55
|
* @returns Initialized logger instance.
|
|
55
56
|
*/
|
|
56
57
|
declare function childLogger(opts?: LogOptions, bindings?: pino.Bindings): Logger;
|
|
57
|
-
|
|
58
|
-
export {
|
|
58
|
+
//#endregion
|
|
59
|
+
export { CtoLogOptions, DEFAULT_LOG_OPTIONS, LOG_OPTIONS_NAMES, LogOptions, Logger, childLogger, createLog, getLog };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{assertDisjoint as e,nameSet as t,select as n}from"@cto.af/utils";import r from"pino";import i from"pino-pretty";const a={log:null,logFile:null,logLevel:0,mute:!1,prettyIgnore:`pid,hostname,name,host,port,ns`,sync:!1},o=t(a),s=new Set(`base.browser.crlf.customLevels.depthLimit.edgeLimit.enabled.errorKey.formatters.hooks.level.levelComparison.levelVal.messageKey.mixin.mixinMergeStrategy.msgPrefix.name.nestedKey.onChild.redact.safe.serializers.timestamp.transport.useOnlyCustomLevels`.split(`.`));e(o,s);const c=new Set([...o,...s]);var l=class{write(e){}};function u(e={},t){let[o,s]=n(e,a);if(o.log)return o.log;let c=globalThis.process?.env?.CTOAF_LOG_LEVEL;if(typeof c==`string`){let e=parseInt(c,10);isNaN(e)||(o.logLevel=e)}let u=Math.round(3-o.logLevel);u<1?u=1:u>6&&(u=6),s.level=r.levels.labels[u*10];let d;if(o.mute&&!o.logFile)d=r(s,new l);else if(o.logFile){let e=r.destination({dest:o.logFile,sync:o.sync,append:!0,mkdir:!0});d=o.mute?r(s,e):r(s,r.multistream([{level:s.level,stream:e},{level:s.level,stream:i({ignore:o.prettyIgnore})}]))}else d=r(s,i({ignore:o.prettyIgnore}));return t&&d.setBindings(t),e.log=d,d}let d;function f(e,t={}){return e?.log?e.log:(d||=u(e,t),d)}function p(e={},t={}){return f(e).child(t)}export{a as DEFAULT_LOG_OPTIONS,c as LOG_OPTIONS_NAMES,p as childLogger,u as createLog,f as getLog};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/log",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"decription": "",
|
|
5
|
-
"main": "lib/index.
|
|
5
|
+
"main": "lib/index.mjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/*"
|
|
8
8
|
],
|
|
@@ -19,17 +19,11 @@
|
|
|
19
19
|
"url": "https://github.com/cto-af/log/issues"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@cto.af/utils": "1.4.
|
|
23
|
-
"pino": "10.3.1",
|
|
24
|
-
"pino-pretty": "13.1.3"
|
|
25
|
-
},
|
|
26
|
-
"packageManager": "pnpm@10.30.3",
|
|
27
|
-
"pnpm": {
|
|
28
|
-
"overrides": {
|
|
29
|
-
"typedoc@0.28.17>minimatch": "10.2.4",
|
|
30
|
-
"c8@11.0.0>yargs": "18.0.0"
|
|
31
|
-
}
|
|
22
|
+
"@cto.af/utils": "~1.4.2",
|
|
23
|
+
"pino": "~10.3.1",
|
|
24
|
+
"pino-pretty": "~13.1.3"
|
|
32
25
|
},
|
|
26
|
+
"packageManager": "pnpm@10.33.0",
|
|
33
27
|
"engines": {
|
|
34
28
|
"node": ">=20"
|
|
35
29
|
}
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{assertDisjoint as c,nameSet as d,select as O}from"@cto.af/utils";import r from"pino";import L from"pino-pretty";var m={log:null,logFile:null,logLevel:0,mute:!1,prettyIgnore:"pid,hostname,name,host,port,ns",sync:!1},f=d(m),u=new Set(["base","browser","crlf","customLevels","depthLimit","edgeLimit","enabled","errorKey","formatters","hooks","level","levelComparison","levelVal","messageKey","mixin","mixinMergeStrategy","msgPrefix","name","nestedKey","onChild","redact","safe","serializers","timestamp","transport","useOnlyCustomLevels"]);c(f,u);var S=new Set([...f,...u]),p=class{write(t){}};function v(o={},t){let[e,n]=O(o,m);if(e.log)return e.log;let a=globalThis.process?.env?.CTOAF_LOG_LEVEL;if(typeof a=="string"){let s=parseInt(a,10);isNaN(s)||(e.logLevel=s)}let i=Math.round(3-e.logLevel);i<1?i=1:i>6&&(i=6),n.level=r.levels.labels[i*10];let l;if(e.mute&&!e.logFile)l=r(n,new p);else if(e.logFile){let s=r.destination({dest:e.logFile,sync:e.sync,append:!0,mkdir:!0});e.mute?l=r(n,s):l=r(n,r.multistream([{level:n.level,stream:s},{level:n.level,stream:L({ignore:e.prettyIgnore})}]))}else l=r(n,L({ignore:e.prettyIgnore}));return t&&l.setBindings(t),o.log=l,l}var g;function y(o,t={}){return o?.log?o.log:(g||(g=v(o,t)),g)}function I(o={},t={}){return y(o).child(t)}export{m as DEFAULT_LOG_OPTIONS,S as LOG_OPTIONS_NAMES,I as childLogger,v as createLog,y as getLog};
|