Skip to content

Commit

Permalink
Remove pino (#1)
Browse files Browse the repository at this point in the history
* scaffold

* finally rm pino

* consistent target

* rm comment
  • Loading branch information
Enity authored May 14, 2024
1 parent 05c580d commit 6f91ffb
Show file tree
Hide file tree
Showing 23 changed files with 512 additions and 466 deletions.
116 changes: 13 additions & 103 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
"@nestjs/platform-fastify": "^10.0.0",
"@nestjs/swagger": "^7.0.0",
"class-validator": "0.13.2",
"nestjs-pino": "^4.0.0",
"pino-http": "^9.0.0",
"pino-pretty": "^10.0.0",
"nestjs-cls": "^4.3.0",
"prom-client": "^15.0.0"
},
"jest": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './modules/actuator';
export * from './modules/config';
export * from './modules/healthcheck';
export * from './modules/prometheus';
export * from './modules/logging';
4 changes: 2 additions & 2 deletions src/modules/graceful-shutdown/fastify-gs-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Logger } from '@nestjs/common';
import type { LoggerService } from '@nestjs/common';
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
import type { FastifyInstance, FastifyRequest } from 'fastify';
import { debounce, type DebouncedFunction } from './debounce';
Expand All @@ -8,7 +8,7 @@ import { debounce, type DebouncedFunction } from './debounce';

export async function setupGracefulShutdown(
app: NestFastifyApplication,
logger: Logger,
logger: LoggerService,
) {
// eslint-disable-next-line @typescript-eslint/require-await
async function fastifyGracefulShutdownPlugin(fastify: FastifyInstance) {
Expand Down
9 changes: 3 additions & 6 deletions src/modules/logging/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ export enum LOG_LEVEL {
WARN = 'warn',
INFO = 'info',
DEBUG = 'debug',
TRACE = 'trace',
VERBOSE = 'verbose',
}

export type LoggerModuleConfig = {
export type LoggingModuleConfig = {
prettyMode: boolean;
level: LOG_LEVEL;

enableHttpTracing: boolean;
enableHttpRequestContext: boolean;
};

export type LoggerModuleOpts = {
config: LoggerModuleConfig;
config: LoggingModuleConfig;

dependencies: {
meterRegistry?: MeterRegistryType;
Expand Down
53 changes: 0 additions & 53 deletions src/modules/logging/create-pino-http-opts.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/logging/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './toplevel-hack/toplevel-logger';
export * from './create-pino-http-opts';
export * from './config';
export * from './nestjs-logger-fork/structured-logger';
export * from './logging.module';
12 changes: 12 additions & 0 deletions src/modules/logging/logging.module-def.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ConfigurableModuleBuilder } from '@nestjs/common';
import type { LoggerModuleOpts } from './config';

export const {
ConfigurableModuleClass,
MODULE_OPTIONS_TOKEN,
OPTIONS_TYPE,
ASYNC_OPTIONS_TYPE,
} = new ConfigurableModuleBuilder<LoggerModuleOpts>()
.setExtras({ isGlobal: true })
.setClassMethodName('forRoot')
.build();
10 changes: 10 additions & 0 deletions src/modules/logging/logging.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Global, Module } from '@nestjs/common';
import { ConfigurableModuleClass } from './logging.module-def';
import { StructuredLogger } from './nestjs-logger-fork/structured-logger';

@Module({
providers: [StructuredLogger],
exports: [StructuredLogger],
})
@Global()
export class LoggingModule extends ConfigurableModuleClass {}
18 changes: 18 additions & 0 deletions src/modules/logging/nestjs-logger-fork/cli-colors.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type ColorTextFn = (text: string) => string;

const isColorAllowed = () => process.env.NO_COLOR !== 'true';
const colorIfAllowed = (colorFn: ColorTextFn) => (text: string) =>
isColorAllowed() ? colorFn(text) : text;

export const clc = {
bold: colorIfAllowed((text: string) => `\x1B[1m${text}\x1B[0m`),
green: colorIfAllowed((text: string) => `\x1B[32m${text}\x1B[39m`),
yellow: colorIfAllowed((text: string) => `\x1B[33m${text}\x1B[39m`),
red: colorIfAllowed((text: string) => `\x1B[31m${text}\x1B[39m`),
magentaBright: colorIfAllowed((text: string) => `\x1B[95m${text}\x1B[39m`),
cyanBright: colorIfAllowed((text: string) => `\x1B[96m${text}\x1B[39m`),
};

export const yellow = colorIfAllowed(
(text: string) => `\x1B[38;5;3m${text}\x1B[39m`,
);
Loading

0 comments on commit 6f91ffb

Please sign in to comment.