Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j-hoplin/nestjs-custom-extendedlogger
[Deprecated] 📝 Customed NestJS Logging module. Compatible with NestJS builtin logger
https://github.com/j-hoplin/nestjs-custom-extendedlogger
logger nestjs nestjs-logger
Last synced: about 1 month ago
JSON representation
[Deprecated] 📝 Customed NestJS Logging module. Compatible with NestJS builtin logger
- Host: GitHub
- URL: https://github.com/j-hoplin/nestjs-custom-extendedlogger
- Owner: J-Hoplin
- Created: 2023-07-05T03:33:07.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-07-10T04:09:43.000Z (over 1 year ago)
- Last Synced: 2024-12-01T21:11:38.511Z (about 1 month ago)
- Topics: logger, nestjs, nestjs-logger
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@hoplin/nestjs-logger
- Size: 398 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
A progressive Node.js framework for building efficient and scalable server-side applications.
## Install with npm or yarn```
npm i @hoplin/nestjs-loggeryarn add @hoplin/nestjs-logger
```## NestJS custom logger
Extended NestJS Logger, Based on NestJS common logger. Log messages also follow Nest embedded style
- Support logfile
- Able to use logger with Dependency Injection
- Compatible with existing logging module
- Global request flow## Start logger
To use this logger, you need to import `LoggerModule` to `app.module.ts` via `.forRoot()` method.
```typescript
import { LoggerModule } from '@hoplin/nestjs-logger';@Module({
imports: [
LoggerModule.forRoot({
applicationName: 'Logger Test',
logfileDirectory: `${__dirname}/../`,
saveAsFile: true,
levelNTimestamp: {
logLevels: ['log'],
timestamp: true,
},
}),
],...
````forRoot()` require some options. You can give two types of options, and each options refer to description under below
- `applicationName` - string
- Name of application to be printed in the log message
- `saveAsFile` (optional) - boolean
- `true` if you want to save log as logfile. **If it's `true`, option `logfileDirectory` is not optional**
- `logfileDirectory` (optional) - string
- Directory where logfile will be saved.
- `levelNTimestamp`
- `logLevels`(optional) - LogLevel[]
- log level array. This work as same as NestJS Logger
- `timestamp`(optional) - boolean
- Check if logger print timestamp. `timestamp` mean, between current and previous log message.For log level please refer json underbelow
```javascript
{
verbose: 0,
debug: 1,
log: 2,
warn: 3,
error: 4,
};
```after initialize logger with `.forRoot()`, You can import `LoggerModule` from other Moduels throgh `forFeature()` and make DI to Injectable object
```typescript
import { LoggerModule } from '@hoplin/nestjs-logger';// example.module.ts
@Module({
imports: [LoggerModule.forFeature()]...
import { Logger } from '@hoplin/nestjs-logger';// example.service.ts
@Injectable()
export class ExampleService {
constructor(private readonly logger: Logger) {}
```## Global request / response flow interceptor
If you want to log to console about every request, use [`FlowInterceptor`](./src/logger/logger.interceptor.ts). You can both register globally or you can use it with `@UseInterceptor()` decorator, which NestJS provide
```typescript
// main.ts
import { FlowInterceptor } from '@hoplin/nestjs-logger';async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalInterceptors(new FlowInterceptor());
...
```## Example Log Message
- Enable Flow Interceptor globally
![img](./img/logger.png)