{"id":15020874,"url":"https://github.com/nest-x/nestx-log4js","last_synced_at":"2025-04-09T23:21:06.549Z","repository":{"id":37049900,"uuid":"242742109","full_name":"nest-x/nestx-log4js","owner":"nest-x","description":"nestjs log4js-node module","archived":false,"fork":false,"pushed_at":"2025-04-04T11:01:33.000Z","size":15241,"stargazers_count":29,"open_issues_count":14,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T12:20:00.454Z","etag":null,"topics":["log4js","nestjs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nest-x.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-24T13:22:53.000Z","updated_at":"2025-04-03T02:12:09.000Z","dependencies_parsed_at":"2023-09-23T05:37:17.867Z","dependency_job_id":"d0e9c918-f5fe-4097-a0dc-77525c989243","html_url":"https://github.com/nest-x/nestx-log4js","commit_stats":{"total_commits":1332,"total_committers":6,"mean_commits":222.0,"dds":0.4519519519519519,"last_synced_commit":"807d78cbb124309534713520b7ac554cf1a00d32"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nest-x%2Fnestx-log4js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nest-x%2Fnestx-log4js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nest-x%2Fnestx-log4js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nest-x%2Fnestx-log4js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nest-x","download_url":"https://codeload.github.com/nest-x/nestx-log4js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126360,"owners_count":21051909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["log4js","nestjs","typescript"],"created_at":"2024-09-24T19:55:47.479Z","updated_at":"2025-04-09T23:21:06.530Z","avatar_url":"https://github.com/nest-x.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nestx-log4js\n\n[![Github Workflow Status](https://github.com/nest-x/nestx-log4js/workflows/ci/badge.svg)](https://github.com/nest-x/nestx-log4js)\n[![Codecov](https://codecov.io/gh/nest-x/nestx-log4js/branch/master/graph/badge.svg)](https://codecov.io/gh/nest-x/nestx-log4js)\n[![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n\n\nProvide log4js module as NestJS module\n\nThis is root of `@nestx-log4js` monorepo.\n\nTo Get Started, please read [`@nestx-log4js/core` Documentation](./packages/core/)\n\n\n## Core Module Documentation\n\n`log4js` as NestJS Module.\n\n\u003cbr/\u003e\n\n## Features\n\n- Provide `log4js` wrapper as NestJS Global Module\n- Provide `Log4jsLogger` instance for replacement logger usage\n\n\u003cbr/\u003e\n\n\n## Installation\n\n```shell\nyarn add @nestx-log4js/core\n```\n\n\u003cbr/\u003e\n\n\n## Usage\n\n\n### Just want to use `log4js`?\n\n\u003e Since logger is a special service in NestJS, we suppose\n\u003e import `Log4jsModule` and manual call `app.useLogger(app.get(Log4jsLogger))`\n\n\n**app.module.ts**\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { Log4jsModule } from '@nestx-log4js/core';\n\n\n@Module({\n  imports: [\n    Log4jsModule.forRoot()\n  ]\n})\nexport class AppModule {}\n```\n\n**bootstrap.ts**\n\n```typescript\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module'; \nimport { Log4jsLogger } from '@nestx-log4js/core';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  \n  app.useLogger(app.get(Log4jsLogger));\n  await app.listen(3000);\n}\nbootstrap();\n```\n\n\u003e For more details, you can refer unit tests in source code\n\n\n### Initial `Log4jsModule` with AsyncOptions (Production Usage)\n\n\u003e You might want to use different appender (e.g. file/dateFile appender)\n\u003e in real production usage and initial in your ConfigService/LoggerOnlyConfigService\n\n\n**app.module.ts**\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { Log4jsModule } from '@nestx-log4js/core';\n\n// import your ConfigService/LoggerConfigService\n\n@Module({\n  imports: [\n    Log4js.forRootAsync({\n      inject: [ConfigService],\n      useFactory: (config: ConfigService) =\u003e config.getLog4jsOptions() // config.getLog4jsOptions should return valid Log4jsOptions\n    })\n  ]\n})\nexport class AppModule {}\n```\n\n\n## Bundled Layout \u0026 Appenders\n\nWhen using `Log4jsModule.forRoot()` and no spec any appenders and layouts,\n\nIt will use default below layouts:\n\n```typescript\nexport const LOG4JS_DEFAULT_LAYOUT = {\n  type: 'pattern',\n  // log4js default pattern %d{yyyy-MM-dd HH:mm:ss:SSS} [%thread] %-5level %logger{36} - %msg%n\n  // we use process id instead thread id\n  pattern: '%[%d{yyyy-MM-dd hh:mm:ss:SSS} %p --- [%15.15x{name}]%] %40.40f{3}  : %m',\n  tokens: {\n    name: (logEvent) =\u003e {\n      return (logEvent.context \u0026\u0026 logEvent.context['name']) || '-';\n    }\n  }\n};\n\nexport const LOG4JS_NO_COLOUR_DEFAULT_LAYOUT = {\n  type: 'pattern',\n  // log4js default pattern %d{yyyy-MM-dd HH:mm:ss:SSS} [%thread] %-5level %logger{36} - %msg%n\n  // we use process id instead thread id\n  pattern: '%d{yyyy-MM-dd hh:mm:ss:SSS} %p --- [%15.15x{name}] %40.40f{3}  : %m',\n  tokens: {\n    name: (logEvent) =\u003e {\n      return (logEvent.context \u0026\u0026 logEvent.context['name']) || '-';\n    }\n  }\n};\n\n\n\nexport const LOG4JS_DEFAULT_CONFIG: Configuration = {\n  appenders: {\n    stdout: {\n      type: 'stdout',\n      layout: LOG4JS_DEFAULT_LAYOUT\n    },\n    file: {\n      type: 'file',\n      filename: './logs/application.log',\n      maxLogSize: 20 * 1024 * 1024, // maxLogSize use bytes ad unit\n      backups: 10,     // default use 5 so 1KB file size total rotating\n      layout: LOG4JS_NO_COLOUR_DEFAULT_LAYOUT\n    }\n  },\n  categories: {\n    default: {\n      enableCallStack: true,\n      appenders: ['stdout', 'file'],\n      level: 'debug'\n    }\n  }\n};\n\n```\n\nIt will use default below layouts (from spring boot default log pattern without process id)\n\nYou can refer to [SpringBoot logging features](https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-logging.html)\n\n```\n\n2020-11-14 15:47:24:486 INFO --- [         NestJS]               core/src/log4js.classes.ts  : log using nestjs as category\n2020-11-14 15:47:24:486 INFO --- [              -]               core/src/log4js.classes.ts  : log using none as category\n2020-11-14 15:47:24:490 INFO --- [         NestJS]               core/src/log4js.classes.ts  : log using nestjs as category\n2020-11-14 15:47:24:490 WARN --- [              -]      src/__tests__/log4js.module.test.ts  : log using none as category\n\n```\n\n\n\n\n\u003e Tips: You are using grok pattern via filebeat/other sidecar log agent? You can use below grok pattern:\n\u003e %{TIMESTAMP_ISO8601:server_time}\\s*%{LOGLEVEL:level}\\s*---\\s*\\[\\s*%{NOTSPACE:context}\\]\\s*%{NOTSPACE:file_path}\\s*:\\s*%{GREEDYDATA:content}\n\u003e\n\u003e It will split to friendly format (you can update alias yourself via grok document)\n\u003e - server_time\n\u003e - level\n\u003e - context\n\u003e - file_path\n\u003e - content\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnest-x%2Fnestx-log4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnest-x%2Fnestx-log4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnest-x%2Fnestx-log4js/lists"}