logfunction

The simplest possible logging library.

Usage no npm install needed!

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

README

logfunction

The simplest possible logging library.

Motivation

Other log libraries have interfaces that are hard to mock/shim/intercept/inject. For example, they often have who-knows-how-many logger.{info,debug,warn}(...?) methods. What exactly is the signature there? logger is an object with an interface that varies across libraries.

This one is simple. You dont have a logger object, you have a logger function. The first argument is a log level hint, and the rest of the args get logged.

It's written in TypeScript and has types such that you can't pass wrong values for the log level argument.

I found this useful while building permanent.cloud. Consider check it out and following along via email or @PermanentCPU.

API

index.js

import log from "logfunction"

// log(level, ...loggables)
log(process.env.LOGFUNCTION_LEVEL, "my message", { meta: "data" })

In a shell

gt; node index.js 
gt; LOGFUNCTION_LEVEL=debug node index.js
my message

That's it :|