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.
Through this interface you should set the following configuration to the PolarisLogger
:
- 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 logstash
hosts, ports and protocols (Notice that you can use
TCP
/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 to
true
, if you decide to write full detailed 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.
This interface represents the application configurable log properties.
Those properties are:
- id
- name
- version
- environment
- component
This interface represents the log properties that will be logged through the PolarisLogger
.
Those properties are:
throwable
: The throwable object, if an error occurred. any | OptionalelapsedTime
: You can provide an elapsed execution time of the operation. number | OptionallogId
: You can provide a unique log id for each log. string | OptionalcustomProperties
: You can provide custom properties, and it will be piped to the log. any | Optionalresponse
: The response sent to the client. any | OptionalmessageId
: A unique identifier of the request/operation process. Something like a transaction id of a process. string | OptionalrecordId
: A unique identifier of the log(generated automatically). string | OptionaleventKind
: The kind of event that happened. An event id. string | OptionaleventKindDescription
: A description of the event kind that occurred. EventKindDescription | Optionalreality
: You can provide The reality which the operation took place in. Reality | Optionalrequest
: The request sent by the client. Request | Optionalentity
: 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 | Optionalentities
: 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[] | Optionalupn
: The user identifier that executed the operation. string | Optionalip
: The ip address of the server that the request came from. string | Optionalhost
: The server/container name where the event occurred. string | OptionalgroupId
: The attributes that defines the relation between the entities to the event that occurred. GroupId | Optional
This class interacts with the actual winston logger and responsible for logging provided properties.
import {
ApplicationProperties,
LoggerConfiguration,
LoggerLevel,
LogstashConfiguration,
LogstashProtocol,
PolarisLogger,
} from '@enigmatis/polaris-logs';
const appProps: ApplicationProperties = {
id: 'p0laris-l0gs',
name: 'polaris-logs',
version: 'v1',
environment: 'environment',
component: 'component',
};
const logstashConf: 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,
}
];
const logConf: LoggerConfiguration = {
loggerLevel: LoggerLevel.TRACE,
logstashConfigurations: logstashConf,
writeToConsole: true,
writeFullMessageToConsole: true,
};
const logger = new PolarisLogger(logConf, appProps);
logger.fatal('fatal message', { elapsedTime: 500, eventKind: 'foo' });
logger.error('error message', { elapsedTime: 15000, throwable: new Error('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 😄