0.6.2 • Published 1 year ago

@pimred/logger v0.6.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Logger

Write logs in nodejs.

Installation

npm install --save @pimred/logger

File logging

Usage

const logger = require('@pimred/logger')('my-logs')
logger.info('Hello logger')

With options

const logger = require('@pimred/logger')('my-logs', { directory: 'different-location', filename: 'my-logs.log'})
logger.info('Hello logger')

API documentation

The module exports a function that can be invoked immediately.\ The directory will be created if it's not existing.

Options

NameRequiredDescription
namexName of the directory where the logfiles will be stored
optionsOptional options
options.directoryLocation of the log directoriesDefault: _logs
options.filenameFormat of the filenameAvailable placeholders: {{YEAR}}, {{MONTH}}, {{DAY}}Default: log_{{YEAR}}_{{MONTH}}_{{DAY}}.txt

Default options

It's possible to define default options in the process.env scope.

NameMapped to
process.env.PIMRED_LOGGER_DIRECTORYoptions.directory
process.env.PIMRED_LOGGER_FILENAMEoptions.filename

Logging to Elasticsearch

Usage

const logger = require('@pimred/logger/dist/elastic')()
logger.info('This message will be stored in Elasticsearch')
logger.warn({ myKey: 'myValue' }, 'This message will include an additional key')

With options

const logger = require('@pimred/logger/dist/elastic')({ indexName: 'my-index-name' })

Options

NameRequiredDescription
indexNamexName of the index in elastic
elasticNodeConnection string to the elastic node
elasticVersionMajor Elasticsearch version, e.g. 7
elasticUsernameAuthentication credentials: username
elasticPasswordAuthentication credentials: password

Default options

It's possible to define default options in the process.env scope.

NameMapped to
process.env.PIMRED_LOGGER_ELASTIC_INDEX_NAMEoptions.indexName
process.env.PIMRED_LOGGER_ELASTIC_NODEoptions.elasticNode
process.env.PIMRED_LOGGER_ELASTIC_VERSIONoptions.elasticVersion
process.env.PIMRED_LOGGER_ELASTIC_USERNAMEoptions.elasticUsername
process.env.PIMRED_LOGGER_ELASTIC_PASSWORDoptions.elasticPassword

Logging to Loki

Usage

const logger = require('@pimred/logger/dist/loki')()
logger.info('This message will be stored in Loki - grafana')
logger.warn({ myKey: 'myValue' }, 'This message will include an additional key')

With options

const logger = require('@pimred/logger/dist/loki')({
  labels: {
    job: 'my-job-name'
  },
  propsToLabels: ['myKey'],
  lokiUrl: 'http://loki-ip-address:port'
})

Options

NameRequiredDescription
lokiUrlxLoki url used to push logs
labelsObject with labels will be passed to loki - grafana
propsToLabelsArray of strings which is going to be used to create labels from message

Default options

It's possible to define default options in the process.env scope.

NameMapped to
process.env.PIMRED_LOGGER_LOKI_URLoptions.lokiUrl
process.env.PIMRED_LOGGER_LOKI_USERNAMEoptions.username
process.env.PIMRED_LOGGER_LOKI_PASSWORDoptions.password
0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.0

2 years ago

0.5.1

2 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago