1.1.7-ops • Published 5 years ago

@hackcapital/logger-nodejs v1.1.7-ops

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

node version status

logger

A powerful logger built on top of Bunyan capable to write logs to stdout, file and send to LogStash out-of-the-box.

Usage

There's a full functional example at the example/index.js file.

Features

  • Buffer milions of messages
  • Logs to Logstash, local FS and stdout
  • setTags() allows to dynamically append to the original set tags

Env Vars

  • process.env.NODE_DEBUG: If specified, produces a lot of noise
  • process.env.LOGGER_PLUGINS_LOCALFILE_ENABLED: If specified, enables the localfile plugin
  • process.env.LOGGER_PLUGINS_LOCALFILE_ROTATION: Set log file rotation. Default: 1d
  • process.env.LOGGER_PLUGINS_LOCALFILE_RETENTION: Set log file retention. Default: 5
  • process.env.LOGGER_PLUGINS_LOCALFILE_LOG_DIR_NAME: Default directory name. Default: logs
  • process.env.LOGGER_PLUGINS_LOCALFILE_MIN_LEVEL: Default: debug
  • process.env.LOGGER_PLUGINS_STDOUT_ENABLED: If specified, enables the stdout plugin
  • process.env.LOGGER_PLUGINS_STDOUT_MIN_LEVEL: Default: debug
  • process.env.LOGGER_PLUGINS_LOGSTASH_ENABLED: If specified, enables the logstash plugin
  • process.env.LOGGER_PLUGINS_LOGSTASH_HOST: Set the Logstash host
  • process.env.LOGGER_PLUGINS_LOGSTASH_PORT: Set the Logstash port
  • process.env.LOGGER_PLUGINS_LOGSTASH_MIN_LEVEL: Default: info

Levels

The log levels in bunyan are as follows. The level descriptions are best practice opinions of the author.

  • fatal (60): The service/app is going to stop or become unusable now. An operator should definitely look into this soon.
  • error (50): Fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this soon(ish).
  • warn (40): A note on something that should probably be looked at by an operator eventually.
  • info (30): Detail on regular operation.
  • debug (20): Anything else, i.e. too verbose to be included in "info" level.
  • trace (10): Logging from external libraries used by your app or very detailed application logging.

Setting a logger instance (or one of its streams) to a particular level implies that all log records at that level and above are logged. E.g. a logger set to level "info" will log records at level info and above (warn, error, fatal).

Source: Bunyan Levels

Logger <-> Logstash Integration

Logstash can take actions based on levels and special tags. Follows the level vs action matrix:

levellogstashslackemailpagerduty
debugnononono
infoyesnonono
warnyesnonono
erroryesyesnono
fatalyesyesyesyes

_Notes:

  • It requires Logstash to be already setup and integrated with these services
  • Logger connects via tcp with Logstash
  • If the Logstash server is not available, it will not block the Logger execution

Tips

  • Do no concat strings
  • Less is more, reduce noise
  • If Logstash is routing to ES, pay attention to mapping conflicts
  • Do not blindly log objects
  • Do not directly logging errors -> mapping conflicts.
  • Don't use these fields!
  • message
  • timestamp
  • level
  • name
  • hostname
  • pid
  • time
  • msg
  • src
  • Add "outputCapture": "std" to your VSCode launch.json to see logs in debug mode
1.1.7-ops

5 years ago

1.1.6-ops

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago