{"id":15184603,"url":"https://github.com/yuxblank/rnglogger","last_synced_at":"2026-01-29T09:16:25.852Z","repository":{"id":143801745,"uuid":"373116306","full_name":"yuxblank/RNgLogger","owner":"yuxblank","description":"The Reactive Angular Logging framework you wanted!","archived":false,"fork":false,"pushed_at":"2022-01-09T13:45:46.000Z","size":721,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-24T11:41:55.453Z","etag":null,"topics":["angular","angular-2","angular-cli","angular-universal","logger","reactive","rxjs"],"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/yuxblank.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2021-06-02T09:52:16.000Z","updated_at":"2022-01-09T13:44:32.000Z","dependencies_parsed_at":"2023-04-04T09:21:33.720Z","dependency_job_id":null,"html_url":"https://github.com/yuxblank/RNgLogger","commit_stats":{"total_commits":43,"total_committers":2,"mean_commits":21.5,"dds":0.06976744186046513,"last_synced_commit":"801cede0fe390b55d68efc797406b54fa0e1b7da"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/yuxblank/RNgLogger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuxblank%2FRNgLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuxblank%2FRNgLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuxblank%2FRNgLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuxblank%2FRNgLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuxblank","download_url":"https://codeload.github.com/yuxblank/RNgLogger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuxblank%2FRNgLogger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259370652,"owners_count":22847372,"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":["angular","angular-2","angular-cli","angular-universal","logger","reactive","rxjs"],"created_at":"2024-09-27T17:20:52.676Z","updated_at":"2026-01-29T09:16:25.806Z","avatar_url":"https://github.com/yuxblank.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](https://coveralls.io/repos/github/yuxblank/RNgLogger/badge.svg?branch=master\u0026kill_cache=1)](https://coveralls.io/github/yuxblank/RNgLogger?branch=master\u0026kill_cache=1)\n\n# RNgLogger\nThe Reactive Angular Logging framework you wanted!\n\n`RNgLogger` is a **logging API** that abstract the log stream from the actual log handler, allowing supporting multiple log targets at the same time within your Angular Application.\n\nEasily switch between platforms (browser, server) with different logging handlers using the same API.\n\nThis library does not enforce to adhere to any rigid system, you're free to react and interact with logs \nyour way.\n\nStraightforward replace for console usage!\n\nFrom `console.info(\"message\")` To  `LoggerFactory().info(\"message\")`\n\n## Features\n- Simple logger interface as a reduced set of window.console\n- Opt-in replacement for your un-wanted console.log statements\n- Configurable level filtering and Log retention\n- RX.JS based log stream handler allow multiple targets at the same time (console, FileSystem, Http Endpoints etc...)\n- Angular Platform Logger allow to use the logger interface by Injection and via LoggerFactory() as most of the Logging frameworks\n- No operation Logger (NOP) is provided by default when the logger it's not provided or cannot be resolved. (can be configured to throw error)\n- Logger can be used anywhere, **libraries included**, and when the application does not register it's just a NOP implementation\n- Typescript decorators for contextual logging hooks\n- Straightforward testing\n- A built-in window.console handler for Platform browser apps!\n\n\n## Getting started\n\n`RNgLogger` is an Angular platform tool, to use it you must register the required providers at platform level.\n\nNPM install:\n\n`npm i rng-logger`\n\n\n### Register the platform Logger\n\n_In your Angular application entry (usually `main.ts` file), add the `RNgPlatformLogger` factory call._\n```typescript\nimport {LogLevel, PLATFORM_CONSOLE_LOGGER, RNgPlatformLogger} from \"rng-logger\";\n\nif (environment.production) {\n  enableProdMode();\n}\n\nplatformBrowserDynamic(\n    RNgPlatformLogger(), // platForm\n).bootstrapModule(AppModule)\n  .catch(err =\u003e console.error(err));\n\n```\n\n`RNgPlatformLogger` is a factory that returns the providers required for the platform, and accept a configuration if needed.\n\n_To Change the default configuration, you can apply like this:_\n\n```typescript\nimport {LogLevel, PLATFORM_CONSOLE_LOGGER, RNgPlatformLogger} from \"rng-logger\";\n\nRNgPlatformLogger({\n      level: environment.production ? LogLevel.ERROR : LogLevel.TRACE, // log level\n      maxBuffer: 100, // max items to retain\n      nonResolvedStrategy: \"ERROR\" // strategy when Logger is not resolved\n})\n```\n\n\n### Register a handler or create your own\n\nA handler is an object that subscribe to the logger stream to produce an effect, for instance logging with the console.\n\n_To use the provided console logger (browser only), just add the provider to the platform:_\n\n```typescript\nimport {LogLevel, PLATFORM_CONSOLE_LOGGER, RNgPlatformLogger} from \"rng-logger\";\n\nplatformBrowserDynamic([\n    ...RNgPlatformLogger(),\n    PLATFORM_CONSOLE_LOGGER // PLATORM CONSOLE LOGGER \n  ]\n).bootstrapModule(AppModule)\n  .catch(err =\u003e console.error(err));\n```\n\n`PLATFORM_CONSOLE_LOGGER` uses window.console to output the log stream.\n\n\nYou can supply multiple Handlers via `PLATFORM_INITIALIZER` (by registering at platform creation) or `APP_INITIALIZER` (in App modules).\nAlso, creating an instance of the handler in the module instantiation is possible, not recommended tough.\n\n_An example function of a log handler is like this:_\n```typescript\nexport function myHttpLogHandler(handler: LogStreamHandler, httpClient: HttpClient) {\n  return () =\u003e {\n    handler.last$()\n      .pipe(switchMap(e =\u003e {\n        return httpClient.post(`/api/log-service/${e.time.getTime()}`, {event: e.message, data: e.options})\n      }))\n      .subscribe(next =\u003e {})\n  }\n}\n\nexport const MY_HTTP_LOG_HANDLER: StaticProvider = {\n  provide: APP_INITIALIZER,\n  multi: true,\n  useFactory: myHttpLogHandler,\n  deps: [LogStreamHandler, HttpClient]\n};\n\n@NgModule({\n  providers: [\n    MY_HTTP_LOG_HANDLER\n  ]\n})\nexport class MyAppModule {}\n```\n### Using the logger\n`RNgLogger` can be used via injection or by using the `LoggerFactory`.\n\nThe factory is a quite common pattern if you come from `SLF4J`, `Log4j` and many others.\n\nThe factory can return the root logger (Platform) directly when used with no-args, or an injector logger by providing the injector.\n\n*Example of the Platform logger factory:*\n```typescript\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss']\n})\nexport class AppComponent implements OnInit{\n  private readonly logger: Logger = LoggerFactory(); // get platform logger\n  constructor() {}\n  ngOnInit(): void {\n    this.logger.info(\"App started\");\n  }\n}\n```\n\n*Example of injected logger:*\n```typescript\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss']\n})\nexport class AppComponent implements OnInit{\n  constructor(private logger: Logger) {}\n  ngOnInit(): void {\n    this.logger.info(\"App started\");\n  }\n}\n```\n\n*Example of logger factory via Injector:*\n```typescript\n@Directive({\n  selector: 'my-directive',\n})\nexport class MyDirective implements OnInit{\n  constructor(private viewRef: ViewContainerRef) {}\n  ngOnInit(): void {\n    LoggerFactory(this.viewRef.injector).warn(\"Injector factory\")\n  }\n}\n```\n\n### Using decorators\n\n`RNgLogger` comes with handy decorators to allow your Components or Services methods to being logged when called.\n\nThe `@Log` decorator can be applied to class methods, and the log output takes care of including the originating class, method, arguments and custom message.\n\n*Example of using `@Log` in component methods*\n```typescript\nexport class MyLoggedComponent implements OnInit{\n  private toggle = false;\n  constructor(){}\n\n  @Log()\n  ngOnInit(): void {}\n\n  @Log({\n    message: \"Toggled!\",\n    level: LogLevel.INFO\n  })\n  toggle() {\n    this.toggle = !this.toggle;\n  }\n\n  @Log({\n    level: LogLevel.WARN\n  })\n  warning(message: MessageObject, scopes: Scope[]): void {}\n\n}\n```\nThese `@Log` decorated methods will emit logs messages in the format below for the appropriate level:\n```log\nMyLoggedComponent::ngOnInit\n\nMyLoggedComponent::toggle Toggled!\n\nMyLoggedComponent::warning  {...}, [...] // values not represented here\n```\n\n\n### For libraries creators\n\nWhen creating a library only want to add RngLoggerModule as an import to use the `Logger` interface.\nIt's then the consumer of your library to decide if, when and how to log your library.\nIf you provide rng-logger as a logging dependency, make sure your readme contains the link to this documentation to allow the user to configure the logger.\n\n### Versions \nrng-logger major version follows to the Angular major version, if there's no target for the release just open an issue.\n\n## Known Limitations\n- LoggerFactory cannot be referenced as a static member because the Angular Platform is not available and any call to getPlatform will return null.\n    - use `private readonly logger: Logger = LoggerFactory();` and not `private static readonly logger: Logger = LoggerFactory();`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuxblank%2Frnglogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuxblank%2Frnglogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuxblank%2Frnglogger/lists"}