ngx-cho-logging
v0.0.5
Published
This library provides a flexible logging system for CHO Angular applications with multiple output sinks and configurable log levels.
Readme
NgxChoLogging
This library provides a flexible logging system for CHO Angular applications with multiple output sinks and configurable log levels.
Generated with Angular CLI version 17.3.0.
Overview
NgxChoLogging includes:
LoggerService- Main logging service with configurable sinksConsoleLoggerSink- Output logs to browser consoleServerLoggerSink- Send logs to server endpointsLoggermodel with log levels and metadata- Configurable logging pipeline with multiple outputs
Dependencies
This library has no dependencies on other workspace libraries and can be built independently.
Installation
npm install ngx-cho-loggingBuild
This library can be built independently:
ng build ngx-cho-loggingBuild artifacts will be stored in the dist/ngx-cho-logging directory.
Development
Code Scaffolding
ng generate component component-name --project ngx-cho-logging
ng generate service service-name --project ngx-cho-loggingNote: Always include
--project ngx-cho-loggingor the component will be added to the default project.
Running Tests
ng test ngx-cho-loggingPublishing
- Update version in
projects/ngx-cho-logging/package.json - Build the library:
ng build ngx-cho-logging --configuration production - Publish to npm:
cd dist/ngx-cho-logging npm publish
Configuration
Configure logging sinks and levels in your application:
import { LoggerService, ConsoleLoggerSink, ServerLoggerSink } from 'ngx-cho-logging';
// In your app.module.ts or service
providers: [
LoggerService,
{
provide: 'LOGGER_SINKS',
useFactory: () => [
new ConsoleLoggerSink(),
new ServerLoggerSink('https://your-logging-endpoint.com/api/logs')
]
}
]Usage
import { LoggerService } from 'ngx-cho-logging';
export class MyComponent {
constructor(private logger: LoggerService) {}
someMethod() {
this.logger.info('User action completed', { userId: 123, action: 'login' });
this.logger.error('An error occurred', { error: 'Network timeout' });
this.logger.debug('Debug information', { debugData: 'some value' });
}
}Log Levels
The library supports standard log levels:
DEBUG- Detailed information for debuggingINFO- General information messagesWARN- Warning messages for potential issuesERROR- Error messages for failuresFATAL- Critical errors that may cause application failure
Custom Sinks
Create custom logging sinks by implementing the ILoggerSink interface:
import { ILoggerSink, Logger } from 'ngx-cho-logging';
export class CustomLoggerSink implements ILoggerSink {
log(logger: Logger): void {
// Your custom logging implementation
console.log(`[${logger.level}] ${logger.message}`, logger.metadata);
}
}