Gathering detailed insights and metrics for nestjs-pretty-logger
Gathering detailed insights and metrics for nestjs-pretty-logger
Gathering detailed insights and metrics for nestjs-pretty-logger
Gathering detailed insights and metrics for nestjs-pretty-logger
🌟 Elevate NestJS logging with stylish, file-redirected, and real-time capable logging based on consola. Compact, powerful, and easy to integrate.
npm install nestjs-pretty-logger
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
17 Stars
26 Commits
1 Forks
2 Watching
2 Branches
1 Contributors
Updated on 14 Oct 2024
TypeScript (99.32%)
JavaScript (0.57%)
Shell (0.11%)
Cumulative downloads
Total Downloads
Last day
53.8%
20
Compared to previous day
Last week
-43.4%
64
Compared to previous week
Last month
48.6%
468
Compared to previous month
Last year
1,834.9%
16,447
Compared to previous year
"NestJS Pretty Logger" is a versatile and visually appealing global Logger module for NestJS applications. This module extends the functionality of the default NestJS logger by utilizing the consola library for enhanced aesthetics and includes features like file redirection and real-time logging capabilities.
stdout
to files, allowing for organized log management.stdout.write
functionalities.onData()
hook for real-time logging implementations, such as custom log recorders or WebSocket real-time log streaming.To install, run the following command:
1npm i @innei/pretty-logger-nestjs
In your main.ts
:
1// main.ts 2import { Logger } from '@innei/pretty-logger-nestjs' 3 4import { NestFactory } from '@nestjs/core' 5 6import { AppModule } from './app.module' 7 8async function bootstrap() { 9 const app = await NestFactory.create(AppModule) 10 app.useLogger(app.get(Logger)) 11 await app.listen(3000) 12} 13bootstrap()
In your app.module.ts
:
1// app.module.ts 2import { LoggerModule } from '@innei/pretty-logger-nestjs' 3 4import { Module } from '@nestjs/common' 5 6import { AppController, AppService } from './app.controller' 7 8@Module({ 9 imports: [LoggerModule], 10 controllers: [AppController], 11 providers: [AppService], 12}) 13export class AppModule {}
Configure and utilize advanced features:
1// Custom Logger Setup 2import path from 'path' 3import { createLogger, Logger } from '@innei/pretty-logger-nestjs' 4 5import { NestFactory } from '@nestjs/core' 6 7import { AppModule } from './app.module' 8 9const customLogger = createLogger({ 10 writeToFile: { 11 loggerDir: path.resolve(__dirname, './logs'), 12 }, 13}) 14 15// Wrap all console and stdout.write with customLogger 16customLogger.wrapAll() 17 18// Implement onData hook for real-time logging or custom actions 19customLogger.onData((data) => { 20 // Your custom implementation here 21}) 22 23// Only error log 24customLogger.onStdErr((data) => { 25 // Your custom implementation here 26}) 27 28// Only non-error log 29customLogger.onStdOut((data) => { 30 // Your custom implementation here 31}) 32 33async function bootstrap() { 34 const app = await NestFactory.create(AppModule) 35 Logger.setLoggerInstance(customLogger) 36 app.useLogger(app.get(Logger)) 37 await app.listen(3000) 38} 39bootstrap()
Note: After invoking wrapAll()
, avoid using console.log
or similar stdout functions within onData()
to prevent potential infinite loops.
The createLogger
method includes the FileReporterConfig
interface for file redirection:
1interface FileReporterConfig { 2 loggerDir: string // Required: Log file directory 3 stdoutFileFormat?: string // Optional: Default 'stdout_%d%.log' 4 stderrFileFormat?: string // Optional: Default 'error.log' 5 cron?: string // Optional: Default '0 0 * * *' for daily log rotation 6}
This configuration is crucial for directing stdout
to log files, with loggerDir
being mandatory for specifying the log directory. The other parameters are optional, offering defaults for file formats and log rotation, which can be changed through the cron
setting.
Contributions to "NestJS Pretty Logger" are highly appreciated. Whether it's through pull requests or issue discussions, your feedback and contributions are valuable to the project.
2024 © Innei, MIT License.
Personal Site · GitHub @Innei
No vulnerabilities found.
No security vulnerabilities found.