@thundra/log
v1.0.2
Published
Thundra Lambda Log Module
Downloads
6
Readme
Thundra Lambda Node.js Log Module
Monitor your logs using Thundra and enjoy the three pillars of observability in one place!
Check out our core module and docs for more information.
Installation
npm install @thundra/log --save
Usage
Require this module, create a log plugin and pass it to our core module.
Then you can create a logger in any file and log using it.
Thundra will report your logs automatically!
const thundraLog = require("@thundra/log");
const thundra = require("@thundra/core")({
apiKey: "MY_APIKEY",
plugins: [thundraLog.createLogPlugin()]
});
const logger = thundraLog.createLogger();
exports.handler = thundra((event, context, callback) => {
logger.info("Hello %s", "Thundra");
callback(null, "Hello Thundra!");
});
You can also set the name of a logger while creating it (default name is default
):
const logger = thundraLog.createLogger({loggerName: "Bob"});
Logger's name will be visible in Thundra's trace chart.
How to use Thundra loggers
You can log by two different ways.
1. Using trace
, debug
, info
, warn
, error
, fatal
methods
All these methods support printf
-like format. Same as Node's util.format
.
const thundraLog = require("@thundra/log");
const logger = thundraLog.createLogger();
logger.trace("Hey, I %s things", "trace");
logger.debug("Someone is %s %d"," debugging", 2);
logger.info("Get some info","and more");
logger.warn("I am warning you %s", "!!!");
logger.error("Error Error Error...");
logger.fatal("FATALITY");
2. Using log
method
Pass an object with level
and message
fields:
const thundraLog = require("@thundra/log");
const logger = thundraLog.createLogger();
logger.log({
level: "trace",
message: "Hey, I am tracing."
});
You can also pass level
as a string, this way you can use printf
-like formatting:
logger.log("trace", "Hey, I am %s", "tracing.");
level
can be one of the following: "trace"
, "debug"
, "info"
, "warn"
, "error"
, "fatal"
Log Levels
In increasing precedence: trace
, debug
, info
, warn
, error
, fatal
.
You can set the log level by setting the environment variable thundra_log_logLevel
to one of the following:
trace
debug
info
warn
error
fatal
none
For instance, if thundra_log_logLevel
is:
debug
, onlydebug
and higher precedence logs will be reported.none
, none of the logs will be reported.
Changelog
Please see the CHANGELOG file.