@cto.af/log 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +15 -6
- package/lib/index.js +1 -1
- package/package.json +5 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pino from 'pino';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface CtoLogOptions {
|
|
4
4
|
/**
|
|
5
5
|
* Increase (or decrease if negative) log verbosity by this much.
|
|
6
6
|
* -3: fatal, -2: error, -1: warn, 0: info, 1: debug, 2: trace.
|
|
7
|
-
* Useful for -qqqvvvv option processing.
|
|
7
|
+
* Useful for -qqqvvvv option processing. Default: 0.
|
|
8
8
|
*/
|
|
9
9
|
logLevel?: number;
|
|
10
10
|
/** If a string, create this log file and write to it. */
|
|
@@ -18,7 +18,15 @@ interface LogOptions extends pino.LoggerOptions<never, false> {
|
|
|
18
18
|
* to stdout. Default: 'pid,hostname,name,host,port'.
|
|
19
19
|
*/
|
|
20
20
|
prettyIgnore?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Log instance, created by the first layer to call createLog. Alternative
|
|
23
|
+
* to getLog for times when multiple loggers are needed.
|
|
24
|
+
*/
|
|
25
|
+
log?: Logger | null;
|
|
21
26
|
}
|
|
27
|
+
declare const DEFAULT_LOG_OPTIONS: Required<CtoLogOptions>;
|
|
28
|
+
declare const LOG_OPTIONS_NAMES: Set<keyof CtoLogOptions | Set<keyof pino.LoggerOptions<never, false>>>;
|
|
29
|
+
type LogOptions = CtoLogOptions & pino.LoggerOptions<never, false>;
|
|
22
30
|
type Logger = pino.Logger;
|
|
23
31
|
/**
|
|
24
32
|
* Create a new log instance. Mostly useful for testing.
|
|
@@ -30,12 +38,13 @@ type Logger = pino.Logger;
|
|
|
30
38
|
declare function createLog(opts?: LogOptions, bindings?: pino.Bindings): Logger;
|
|
31
39
|
/**
|
|
32
40
|
* Get a singleton logging object. Opts and bindings are used the first time,
|
|
33
|
-
* and ignored thereafter.
|
|
41
|
+
* and ignored thereafter. Ideally the highest-level layer will call this
|
|
42
|
+
* first before any lower layer.
|
|
34
43
|
*
|
|
35
44
|
* @param opts Logging options.
|
|
36
45
|
* @param bindings Extra fields to put into every log item.
|
|
37
46
|
* @returns Singleton logging object.
|
|
38
47
|
*/
|
|
39
|
-
declare function getLog(opts
|
|
48
|
+
declare function getLog(opts?: LogOptions, bindings?: pino.Bindings): Logger;
|
|
40
49
|
|
|
41
|
-
export { type LogOptions, type Logger, createLog, getLog };
|
|
50
|
+
export { type CtoLogOptions, DEFAULT_LOG_OPTIONS, LOG_OPTIONS_NAMES, type LogOptions, type Logger, createLog, getLog };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{assertDisjoint as f,nameSet as d,select as L}from"@cto.af/utils";import{Writable as c}from"stream";import r from"pino";import p from"pino-pretty";var a={log:null,logFile:null,logLevel:0,mute:!1,prettyIgnore:"pid,hostname,name,host,port",sync:!1},m=d(a),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"]);f(m,u);var S=new Set([...m,u]),g=class extends c{_write(i,e,o){o(null)}};function O(n={},i){let[e,o]=L(n,a);if(e.log)return e.log;if(e.logLevel!==void 0){let t=Math.round(3-e.logLevel);t<1?t=1:t>6&&(t=6),o.level=r.levels.labels[t*10]}let l;if(e.mute&&!e.logFile)l=r(o,new g);else if(e.logFile){let t=r.destination({dest:e.logFile,sync:e.sync,append:!0,mkdir:!0});e.mute?l=r(o,t):l=r(o,r.multistream([{level:o.level,stream:t},{level:o.level,stream:p({ignore:e.prettyIgnore})}]))}else l=r(o,p({ignore:e.prettyIgnore}));return i&&l.setBindings(i),n.log=l,l}var s;function I(n,i={}){return n?.log?n.log:(s||(s=O(n,i)),s)}export{a as DEFAULT_LOG_OPTIONS,S as LOG_OPTIONS_NAMES,O as createLog,I as getLog};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cto.af/log",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"decription": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"url": "https://github.com/cto-af/log/issues"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"pino
|
|
22
|
+
"@cto.af/utils": "1.3.1",
|
|
23
|
+
"pino": "9.9.0",
|
|
24
|
+
"pino-pretty": "13.1.1"
|
|
24
25
|
},
|
|
25
|
-
"packageManager": "pnpm@10.
|
|
26
|
+
"packageManager": "pnpm@10.15.0",
|
|
26
27
|
"engines": {
|
|
27
28
|
"node": ">=20"
|
|
28
29
|
}
|