Stick is a tiny logger for Deno.
Here's how to use it:
The most basic way to use Stick is to create a default Logger
instance.
import Logger from 'https://deno.land/x/stick/mod.ts';
const logger = new Logger();
logger.info('Hello, world!');
// [Thu, 13 Jan 2022 09:18:41 GMT] [INFO] Hello, world!
The output format is "[label] [name] [level] message". Note that name
is optional, and left out by default.
Logger
can also take parameters:
Logger(level: Logger.LogLevel, label: string | () => string, name: string, file: string)
By default, Loggers do not log to a file, however, you can enable this by specifying a file in the file
parameter.
However, an easier way to create a Logger
instance is to use the Builder:
new Logger.Builder().setName('Process XYZ').build();
Logger.Builder
has a few functions you can use: setName
, setLevel
, setLabel
, and setFile
. Once you have set everything you need, call build
to receive a new Logger
.
LogLevel
s are how Stick determines what messages get logged. The current available levels are:
Use when logging an error. Level 0.
Use when warning the user. Level 1.
Use when logging general information. Level 2.
Use when logging information for debugging purposes. Level 3.
When a Logger
instance is created, it is assigned a LogLevel
. By default, this is INFO
. A Logger will not log any messages above it's specified level - e.g. a Logger on INFO will not log DEBUG messages, but will log INFO, WARNING, and ERROR messages.
This is an object which contains a few pre-specified labels for creating Loggers with. The current available labels are:
Resolves to new Date().toUTCString()
This is the default for all new Loggers
Resolves to new Date().toISOString().substring(11, 19)
(The current time in HH:MM:SS format)
Resolves to new Date().toISOString().substring(11, 16)
(The current time in HH:MM format)
Resolves to new Date().toISOString()