oddlog

A high-performance payload focused logging library for node.js

Usage no npm install needed!

<script type="module">
  import oddlog from 'https://cdn.skypack.dev/oddlog';
</script>

README

oddlog - Object driven data logging

License Version

oddlog is a high-performance payload-focused logging library for node.js.

Being restricted to strings for logging sucks. So we use arbitrary JSON objects instead.

Preview 01

const oddlog = require("oddlog");
const log = oddlog.createLogger("my-app"), child = log.child({user: "root"});
log
  .handleUncaughtExceptions()
  .info({random: 42}, "Application startup");
child
  .warn({method: "terminate"}, "Procedure initiated");

throw new Error("Nah, nothing failed");

References

Installation

npm install --save oddlog

Features

  • Trigger based log output
  • Payload inheritance
  • Multi-transport logging
  • Source-code location logging (not for production)
  • Safe termination (await flush of all logs)
  • Suited for libraries
  • CLI for (pretty) output format and filters
  • Payload transformation (key-based; e.g. req, res, err)
  • Stateless and stateful logging APIs

Command-line interface

The CLI @oddlog/cli is a command-line tool to reformat, prettify and filter message records. It accepts input from stdin and outputs on stdout; Thus it suits well for any common operations.

node my-application | oddlog        # simply prettify the output of my-application
node my-application | oddlog -vv    # increased verbosity to show payload as well

cat logs/app.log | oddlog -vvl info # read (pretty) log records from logs/app.log that are INFO or above

tail -f logs/app.log | oddlog       # pretty print latest and future log records within logs/app.log
                                    # this is the recommended way of checking live logs of a running application; it
                                    # allows you to change the filters, etc. without interrupting the process itself.

For further information take a look into oddlog --help or check out the @oddlog/cli repository.

License

The source code and all related examples, tests and benchmarks are licensed under MIT. If you don't agree to the license, you may not contribute to the project. Feel free to fork and maintain your custom build thought.

Thanks

Many thanks also to everyone who supports this project by usage, contribution and/or spreading the word!

All contributors may add themselves to the contributors field within the package.json regardless of the amount of changes; however I won't do it for them.

Since this project is inspired by bunyan, at this point a big Thanks! to its author.

Donations

Donations (dt.: Schenkungen) to the author are accepted via PayPal and Patreon.

Related projects

  • bunyan - The main inspiration for this project.
  • winston - Some inspiration came from winston as well.