https://github.com/neo9/n9-node-log
  
  
    Logging node module for json or classic logging with levels. 
    https://github.com/neo9/n9-node-log
  
log logger logging nodejs
        Last synced: 4 months ago 
        JSON representation
    
Logging node module for json or classic logging with levels.
- Host: GitHub
- URL: https://github.com/neo9/n9-node-log
- Owner: neo9
- License: gpl-3.0
- Created: 2017-08-29T16:12:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-14T17:28:59.000Z (almost 2 years ago)
- Last Synced: 2025-04-21T01:10:31.054Z (6 months ago)
- Topics: log, logger, logging, nodejs
- Language: TypeScript
- Homepage:
- Size: 832 KB
- Stars: 5
- Watchers: 8
- Forks: 4
- Open Issues: 3
- 
            Metadata Files:
            - Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
 
Awesome Lists containing this project
README
          # n9-node-log
Logging node module based on Pino.
[](https://www.npmjs.com/package/@neo9/n9-node-log)
[](https://travis-ci.org/neo9/n9-node-log)
[](https://codecov.io/gh/neo9/n9-node-log)
[](https://github.com/neo9/n9-node-log/blob/master/LICENSE)
## Requirements
- NodeJS >= 10.0.0
## Installation
```bash
npm install --save @neo9/n9-node-log
```
## Usage
```ts
import n9Log from '@neo9/n9-node-log';
const log = n9Log('my-app-name');
// Write on stdout
log.trace('This is a trace message');
log.debug('This is a debug message');
log.info('This is an information message');
log.warn('Warning, this feature will be removed soon');
// Write on stderr
log.error('An error appened');
```
```console
2017-05-12T15:57:14.474Z - info: [my-app-name] This is an information message
2017-05-12T15:57:14.689Z - warn: [my-app-name] Warning, this feature will be removed soon
2017-05-12T15:57:14.974Z - error: [my-app-name] An error appened
```
## Metadata
```ts
log.info('Log with metadata', { anything: 'this is metadata' });
log.error('Here an error', new Error('hello'));
```
```console
2017-05-12T15:57:14.474Z - info: [my-app-name] Log with metadata anything=this is metadata
2017-05-12T15:57:14.785Z - error: [node-ts-skeleton] Here an error Error: hello
     err: {
      "type": "Error",
      "message": "something-went-wrong",
      "stack":
          Error: something-went-wrong
              at /home/bdaniel/projects/neo9/n9-libs/n9-node-log/test/index.ts:110:29
    }
```
## Prefixing
```ts
const logUsers = log.module('users');
logUsers.info('Log specific to users module');
```
```console
2017-05-12T15:57:14.474Z - info: [my-app-name:users] Log specific to users module
```
## Profiling
```ts
log.profile('test');
setTimeout(() => log.profile('test'), 1000);
```
```console
2017-05-12T15:57:14.474Z - info: [my-app-name] test {"durationMs":1000}
```
## Log level
You can filter the list of logs on startup with the `N9LOG` environment or with the `level` option.
Possible values:
- `trace`: Display all logs
- `debug`: Display debug + info + warn + error logs
- `info`: Display info + warn + error logs
- `warn`: Display warn + error logs
- `error`: Display only error logs
Default value: `info`
Example: `N9LOG=error node server.js` will display only error logs.
For performance matter, you can check if you need to compute your log data :
```js
if (log.isLevelEnabled('debug')) {
	log.debug('My debug log', { complexDataAsOneField: JSON.stringify(data) });
}
```
# Breaking changes from V3 to V4
- Log level verbose renamed to log level trace
- JSON Format is enabled by default, it wasn't before
- Remove transports features
- Filters function change their signatures