@cto.af/log 0.0.1
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.md +19 -0
- package/README.md +45 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +1 -0
- package/package.json +29 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright® 2025 The @cto.af/log Authors and Contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @cto.af/log
|
|
2
|
+
|
|
3
|
+
A thin wrapper around [Pino](https://getpino.io/#/) to insulate multiple
|
|
4
|
+
projects from the dependency, and to normalize a common pattern in those
|
|
5
|
+
projects.
|
|
6
|
+
|
|
7
|
+
In particular:
|
|
8
|
+
|
|
9
|
+
- Singleton log object.
|
|
10
|
+
- Write pretty output to stdout, JSON to a file, both, or neither.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @cto.af/log
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
Full [API documentation](http://cto-af.github.io/log/) is available. Options
|
|
21
|
+
are the Pino [options](https://getpino.io/#/docs/api?id=options) plus:
|
|
22
|
+
|
|
23
|
+
- logLevel: Suitable for -v and -q CLI arguments:
|
|
24
|
+
- -3: fatal
|
|
25
|
+
- -2: error
|
|
26
|
+
- -1: warn
|
|
27
|
+
- 0: info
|
|
28
|
+
- 1: debug
|
|
29
|
+
- 2: trace.
|
|
30
|
+
- logFile: Write to this file, creating the directory if needed.
|
|
31
|
+
- mute: Disable stdout logging if true.
|
|
32
|
+
- prettyIgnore: Ignore these comma-separated fields in the stdout.
|
|
33
|
+
Default: 'pid,hostname,name,host,port'
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const log = getLog();
|
|
39
|
+
log.info('foo');
|
|
40
|
+
log.warn({clientId: 17}, 'Client %d did things', 17);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
[](https://github.com/cto-af/log/actions?query=workflow%3ATests)
|
|
45
|
+
[](https://codecov.io/github/cto-af/log)
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { pino } from 'pino';
|
|
2
|
+
|
|
3
|
+
interface LogOptions extends pino.LoggerOptions<never, false> {
|
|
4
|
+
/**
|
|
5
|
+
* Increase (or decrease if negative) log verbosity by this much.
|
|
6
|
+
* -3: fatal, -2: error, -1: warn, 0: info, 1: debug, 2: trace.
|
|
7
|
+
* Useful for -qqqvvvv option processing.
|
|
8
|
+
*/
|
|
9
|
+
logLevel?: number;
|
|
10
|
+
/** If a string, create this log file and write to it. */
|
|
11
|
+
logFile?: string | null;
|
|
12
|
+
/** If true, do not log to stdout. */
|
|
13
|
+
mute?: boolean;
|
|
14
|
+
/** If logFile is set, write synchronously if true (for testing). */
|
|
15
|
+
sync?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Ignore this set of comma-separated fields when pretty printing logs
|
|
18
|
+
* to stdout. Default: 'pid,hostname,name,host,port'.
|
|
19
|
+
*/
|
|
20
|
+
prettyIgnore?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new log instance. Mostly useful for testing.
|
|
24
|
+
*
|
|
25
|
+
* @param opts Logging options.
|
|
26
|
+
* @param bindings Extra fields to put into every log item.
|
|
27
|
+
* @returns Logging object.
|
|
28
|
+
*/
|
|
29
|
+
declare function createLog(opts?: LogOptions, bindings?: pino.Bindings): pino.Logger;
|
|
30
|
+
/**
|
|
31
|
+
* Get a singleton logging object. Opts and bindings are used the first time,
|
|
32
|
+
* and ignored thereafter.
|
|
33
|
+
*
|
|
34
|
+
* @param opts Logging options.
|
|
35
|
+
* @param bindings Extra fields to put into every log item.
|
|
36
|
+
* @returns Singleton logging object.
|
|
37
|
+
*/
|
|
38
|
+
declare function getLog(opts: LogOptions, bindings?: pino.Bindings): pino.Logger;
|
|
39
|
+
|
|
40
|
+
export { type LogOptions, createLog, getLog };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Writable as m}from"node:stream";import{pino as o}from"pino";import u from"pino-pretty";var p=class extends m{_write(i,s,r){r(null)}};function c(l={},i){let{logLevel:s,logFile:r,mute:d=!1,sync:a=!1,prettyIgnore:f="pid,hostname,name,host,port",...n}=l;if(s!==void 0){let e=Math.round(3-s);e<1?e=1:e>6&&(e=6),n.level=o.levels.labels[e*10]}let t;if(d&&!r)t=o(n,new p);else if(r){let e=o.destination({dest:r,sync:a,append:!0,mkdir:!0});d?t=o(n,e):t=o(n,o.multistream([{level:n.level,stream:e},{level:n.level,stream:u({ignore:f})}]))}else t=o(n,u({ignore:f}));return i&&t.setBindings(i),t}var g;function y(l,i={}){return g||(g=c(l,i)),g}export{c as createLog,y as getLog};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cto.af/log",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"decription": "",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/*"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "Joe Hildebrand <joe-github@cursive.net>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/cto-af/log.git"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/cto-af/log#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/cto-af/log/issues"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"pino": "9.6.0",
|
|
23
|
+
"pino-pretty": "13.0.0"
|
|
24
|
+
},
|
|
25
|
+
"packageManager": "pnpm@10.4.1",
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.13 >=19.1"
|
|
28
|
+
}
|
|
29
|
+
}
|