Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Write logs in the best manner, based on winston, integrated with logstash

NotificationsYou must be signed in to change notification settings

Enigmatis/polaris-logs

Repository files navigation

Polaris-logo

polaris-logs

Build StatusNPM version

Write your logs easily in a standardized manner!

Ever wanted your logs to look pretty, to contain all the data you need in order to monitor your system, and to be written in an extremely easy way? You can now do this, using this library.

LoggerConfiguration

Through this interface you should set the following configuration to thePolarisLogger:

  • loggerLevel (LoggerLevel) - The level the logger is listening on, can be one of the following levels:fatal /error /warn /info /debug /trace.
  • logstashConfigurations (LogstashConfiguration[] - optional) - Through this property you can set multiple logstashhosts, ports and protocols (Notice that you can useTCP/UDP orDYNAMIC for each logstash config).UseDYNAMIC to make polaris-logs decide which protocol to use according to the size of the log.
  • writeToConsole (boolean - optional) - Determines if the logger should write the logs to the console.
  • writeFullMessageToConsole (boolean - optional) - Set this property totrue, if you decide to write fulldetailed logs to the console, since only thetimestamp accompanied by thelog level,message andthrowable will be written by default.
  • customTransports (Transport[] - optional) - Array of custom transports you can provide to the winston logger.

ApplicationProperties

This interface represents the application configurable log properties.

Those properties are:

  • id
  • name
  • version
  • environment
  • component

PolarisLogProperties

This interface represents the log properties that will be logged through thePolarisLogger.

Those properties are:

  • throwable: The throwable object, if an error occurred.any | Optional
  • elapsedTime: You can provide an elapsed execution time of the operation.number | Optional
  • logId: You can provide a unique log id for each log.string | Optional
  • customProperties: You can provide custom properties, and it will be piped to the log.any | Optional
  • response: The response sent to the client.any | Optional
  • messageId: A unique identifier of the request/operation process. Something like a transaction id of a process.string | Optional
  • recordId: A unique identifier of the log(generated automatically).string | Optional
  • eventKind: The kind of event that happened. An event id.string | Optional
  • eventKindDescription: A description of the event kind that occurred.EventKindDescription | Optional
  • reality: You can provide The reality which the operation took place in.Reality | Optional
  • request: The request sent by the client.Request | Optional
  • entity: You can provide an entity of your query you want to record. Note that in case you log both entity and entities properties, entity will merged into entities and only entities will be logged.Entity | Optional
  • entities: You can provide entities of your query you want to record. Note that in case you log both entity and entities properties, entity will merged into entities and only entities will be logged.Entity[] | Optional
  • upn: The user identifier that executed the operation.string | Optional
  • ip: The ip address of the server that the request came from.string | Optional
  • host: The server/container name where the event occurred.string | Optional
  • groupId: The attributes that defines the relation between the entities to the event that occurred.GroupId | Optional

PolarisLogger

This class interacts with the actual winston logger and responsible for logging provided properties.

Example

import{ApplicationProperties,LoggerConfiguration,LoggerLevel,LogstashConfiguration,LogstashProtocol,PolarisLogger,}from'@enigmatis/polaris-logs';constappProps:ApplicationProperties={id:'p0laris-l0gs',name:'polaris-logs',version:'v1',environment:'environment',component:'component',};constlogstashConf:LogstashConfiguration[]=[{host:'127.0.0.1',port:3000,protocol:LogstashProtocol.TCP,},{host:'8.8.8.8',port:6000,protocol:LogstashProtocol.UDP,},{host:'127.0.0.1',port:3000,protocol:LogstashProtocol.DYNAMIC,}];constlogConf:LoggerConfiguration={loggerLevel:LoggerLevel.TRACE,logstashConfigurations:logstashConf,writeToConsole:true,writeFullMessageToConsole:true,};constlogger=newPolarisLogger(logConf,appProps);logger.fatal('fatal message',{elapsedTime:500,eventKind:'foo'});logger.error('error message',{elapsedTime:15000,throwable:newError('oops')});logger.warn('warn message');logger.info('info message');logger.debug('debug message');logger.trace('trace message');

For any additional help and requests, feel free to contact us 😄

About

Write logs in the best manner, based on winston, integrated with logstash

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp