https://github.com/byndyusoft/node-pino-logger-factory
:evergreen_tree: logger factory for pino :evergreen_tree:
https://github.com/byndyusoft/node-pino-logger-factory
logger nodejs pino
Last synced: 4 months ago
JSON representation
:evergreen_tree: logger factory for pino :evergreen_tree:
- Host: GitHub
- URL: https://github.com/byndyusoft/node-pino-logger-factory
- Owner: Byndyusoft
- License: apache-2.0
- Created: 2021-05-24T07:25:37.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T12:26:04.000Z (6 months ago)
- Last Synced: 2024-10-24T19:25:32.828Z (6 months ago)
- Topics: logger, nodejs, pino
- Language: TypeScript
- Homepage:
- Size: 291 KB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-pino-logger-factory
[](https://www.npmjs.com/package/@byndyusoft/pino-logger-factory)
[](https://github.com/Byndyusoft/node-pino-logger-factory/actions/workflows/test.yaml)
[](https://github.com/prettier/prettier)
[](https://github.com/semantic-release/semantic-release):evergreen_tree: logger factory for pino :evergreen_tree:
## Requirements
- Node.js v14 LTS or later
- npm or yarn## Install
```bash
npm install @byndyusoft/pino-logger-factory pino pino-http && npm install -D pino-pretty
```or
```bash
yarn add @byndyusoft/pino-logger-factory pino pino-http && yarn add -D pino-pretty
```## Environment
You must initialize `process.env` before creating pino logger:
```typescript
process.env.npm_package_name;
process.env.npm_package_version;
process.env.CONFIG_ENV ?? process.env.NODE_ENV;
process.env["BUILD_*"];
```## Usage
Create pino logger:
```typescript
import { PinoLoggerFactory } from "@byndyusoft/pino-logger-factory";const logger = new PinoLoggerFactory().create();
```Create pino-http logger:
```typescript
import { PinoHttpLoggerFactory } from "@byndyusoft/pino-logger-factory";const httpLogger = new PinoHttpLoggerFactory().create();
```### Usage with nestjs-pino
Import and configure modules:
```typescript
import {
PinoHttpLoggerOptionsBuilder,
PinoLoggerFactory,
} from "@byndyusoft/pino-logger-factory";
import { Module } from "@nestjs/common";
import { LoggerModule } from "nestjs-pino";@Module({
imports: [
LoggerModule.forRootAsync({
useFactory: () => ({
pinoHttp: new PinoHttpLoggerOptionsBuilder()
.withLogger(new PinoLoggerFactory().create())
.build(),
}),
}),
],
})
export class InfrastructureModule {}
```### Custom serializers
- debugObjectSerializer
Under the hood uses [util.inspect()](https://nodejs.org/api/util.html#utilinspectobject-options) for return human-readable a string representation values of object
- jsonDebugObjectSerializer
Return JSON string representation values of object
### Usage custom serializers
Configure modules
```typescript
import {
PinoHttpLoggerOptionsBuilder,
PinoLoggerFactory,
debugObjectSerializer,
jsonDebugObjectSerializer,
} from "@byndyusoft/pino-logger-factory";
import { Module } from "@nestjs/common";
import { LoggerModule } from "nestjs-pino";@Module({
imports: [
LoggerModule.forRootAsync({
useFactory: () => ({
pinoHttp: new PinoHttpLoggerOptionsBuilder()
.withLogger(new PinoLoggerFactory().create())
.withSerializers({
// you can use any name for key
debugData: debugObjectSerializer,
debugJsonData: jsonDebugObjectSerializer,
})
.build(),
}),
}),
],
})
export class InfrastructureModule {}
``````typescript
logger.info({
msg: "some message",
// the object whose fields you want to serialize to human-readable string representation
debugData: {
entity: {
id: 1,
orders: [1, 2],
},
},
// the object whose fields you want to serialize to JSON string representation
debugJsonData: {
entity: {
id: 1,
orders: [1, 2],
},
},
});
```## Maintainers
- [@Byndyusoft/owners](https://github.com/orgs/Byndyusoft/teams/owners) <>
- [@Byndyusoft/team](https://github.com/orgs/Byndyusoft/teams/team)
- [@KillWolfVlad](https://github.com/KillWolfVlad)## License
This repository is released under version 2.0 of the
[Apache License](https://www.apache.org/licenses/LICENSE-2.0).