@smartocto/so_logger

0.0.3 • Public • Published

##smartocto

{{@smartocto/so_logger}}

{{so_logger}} logger is simple library that use winston logger as core library and it could be extended for all kind of adapters.

Getting Started

In the root of the project in which you plan to use the helper, in the command line run:

npm i @smartocto/so_logger --save

Use within your application with the following line of JavaScript:

var logger = require('@smartocto/so_logger');

Options

setting options

All options could be specified in .env file or overwritten on creating instance.

Global logger options

{
  LOGGER_TYPE: 'file',// file is default , options [file, kafka]
  LOGGER_LOG_TO_CONSOLE: true, //default is false 
  LOGGER_APPLICATION_NAME: 'TEST_APP', //application name will be log to each log message
  LOGGER_ENVIRONMENT_META:'{"environment":"staging","cluster":"x123"}' //environment metadata in encoded JSON string format
};

File logger options

{
  LOGGER_TYPE: 'file',
  LOGGER_APPLICATION_NAME: 'MY_APP',
  LOGGER_FILE_PATH: '/var/log/my/app/',
  LOGGER_FILE_TEMPLATE: '@@APP@@_@@DATE@@_log.json' // default value is @@APP@@_@@DATE@@_log.json it will replace application name and date
};

Kafka logger options

{
  LOGGER_TYPE: 'kafka',
  LOGGER_KAFKA_TOPIC: 'my_topic',
  LOGGER_KAFKA_PROXY_HOST: '127.0.0.1',
  LOGGER_KAFKA_PROXY_PORT: '9092'
};

.env file example

LOGGER_APPLICATION_NAME='MY_ENV_APP'
LOGGER_FILE_TEMPLATE='JUST_LOG.json'
LOGGER_FILE_PATH='/var/log/my/env/app/'
LOGGER_LOG_TO_CONSOLE=true
LOGGER_ENVIRONMENT_META='{"environment":"staging","cluster":"x123"}'

Usage Examples

Usage of logging when configuration is in .env

const loggerFactory = require('@smartocto/so_logger').loggerFactory();

loggerFactory.info('Message Hello World', {function_name:'fnX', param_x: '23'});
loggerFactory.error('Error Message', {function_name:'fnX', param_x: '23'});
loggerFactory.warning('Warning Message', {function_name:'fnX', param_x: '23'});
/*output 
{"level":"info","message":"Message Hello World","service":"MyApp","function_name":"fnX", param_x: "23","timestamp":"2023-03-27T12:54:10.353Z"}
{"level":"error","message":Error Message","service":"MyApp","function_name":"fnX", param_x: "23","timestamp":"2023-03-27T12:54:10.353Z"}
{"level":"warning","message":"Warning Message","service":"MyApp","function_name":"fnX", param_x: "23","timestamp":"2023-03-27T12:54:10.353Z"}
*/

Usage of creating instance and overwrite configuration

Usage of logger with file configuration

const Logger = require('@smartocto/so_logger');
const logger = new Logger({
      LOGGER_APPLICATION_NAME: 'MyApp',
      LOGGER_FILE_TEMPLATE: 'logAllToOneFile.json',
      LOGGER_FILE_PATH: '/var/log/app_log/',
      LOGGER_LOG_TO_CONSOLE: true
    });

logger.info('Message Hello World', {function_name:'fnX', param_x: '23'});
logger.error('Error Message', {function_name:'fnX', param_x: '23'});
logger.warning('Warning Message', {function_name:'fnX', param_x: '23'});

Usage of logger with Kafka configuration

const logger = new Logger({
      LOGGER_TYPE: 'kafka',
      LOGGER_KAFKA_TOPIC: 'some_topic',
      LOGGER_KAFKA_PROXY_HOST: '172.0.0.2',
      LOGGER_KAFKA_PROXY_PORT: '9092',
      LOGGER_LOG_TO_CONSOLE: true
    });
logger.info('msg', {});
logger.error('Error msg', {param_one:'value_one'});

Package Sidebar

Install

npm i @smartocto/so_logger

Weekly Downloads

4

Version

0.0.3

License

ISC

Unpacked Size

24.4 kB

Total Files

19

Last publish

Collaborators

  • smartocto_admin