0.0.0-dev.2 • Published 2 years ago
@yaupon/logger v0.0.0-dev.2
🪵 Logger
Well-designed abstraction for logging compatible with major HTTP frameworks and logging libraries,
including: winston, pino, bunyan and log4js. It provides a simple and consistent API for
logging in yaupon ecosystem.
Features
- Various formats of logs including:
pretty,ndjson,syslog - Easy integration into existing apps with OOB support for log metadata such as User's ID, Request ID, etc.
API
Logger(options?: LoggerOptions): Logger- creates a new logger instance.createLogger(options?: LoggerOptions): Logger- creates a new logger instance.- each logger instance has the following methods:
trace(message: string, meta?: Record<string, any>): voiddebug(message: string, meta?: Record<string, any>): voidinfo(message: string, meta?: Record<string, any>): voidwarn(message: string, meta?: Record<string, any>): voiderror(message: string, meta?: Record<string, any>): voidfatal(message: string, meta?: Record<string, any>): voidchild(meta: Record<string, any>): Logger- creates a child logger with the provided metadata.
setContext(meta: Record<string, any>): void- sets the global context for the logger.setGlobalLogger(logger: Logger): void- sets the global logger for the application. (Overrides console.log and console.error)@logthis- decorator for logging class methods and fuctions for debugging purposes, in future this will be replaced with@yaupon/debugpackage with@debugdecorator.log.<level>('message')- logs a message with the global logger.
Tasklist
- Replaceable structure of logs metadata which would provide type-safety and consistency for produced logs.
- Add easy interface to integrate popular tools such as
NewRelic,OpenTelemetryand so on, all this should be provided as separate package which will be imported intoLoggerOptions.integrationsfield by using default export from integration package ex.import newrelic from '@yaupon/logger-provider-newrelic'. - Self-linting which will include warnings for every log message that was malformed or have insufficient information (and such linting shouldn't apply to logs from global logger which replaced console.log and console.error).
@yaupon/logger-provider-native-yauponlibrary which will provide native integration withyauponecosystem, this will apply additional overrides which will allow parsing information from structures in application likeRequest,Response,Contextand so on, leading to more simplified and consistent logging. Eventually usage would look likelogger.info(event)and the detailed logs will be automatically mapped and structured.Add support for
@yaupon/debugpackage.- Add support for
@yaupon/auditpackage. - Add support for
@yaupon/monitoringpackage. - Add support for
@yaupon/telemetrypackage. - Add support for
@yaupon/tracingpackage.
Usage
import { Logger, createLogger, log } from '@yaupon/logger';
const logger: Logger = createLogger();
logger.info('Hello, world!');
logger.child({requestId: '123' }).info('Hello, world!');
log("Smth, happended")
log("Look this is a function", createLogger)
@logthis
class MyClass {
@logthis
public myMethod() {
return 'Hello, world!';
}
}