A small (<2KB gzipped minified) JavaScript logging library inspired by charmbracelet/log and docs.rs/env_logger.
npm i @luckydye/log
import logger from '@luckydye/log';
const log = logger().prefix("Test").trace();
log.info("Log info");
log.error("This is an error!");
02/06/2024 00:38:05 INFO <log.spec.ts:7:13> Test: Hello, world!!
02/05/2024 13:32:53 ERROR <log.spec.ts:7:41> Test: This is an error!
03/01/2024 22:41:53 ERROR <log.spec.ts:43:25> testing err=Test error
SyntaxError: Test error
at <parse> (:0)
at <anonymous> (/Users/tihav/source/log/log.spec.ts:82:1)
log.warn('An Object', 'obj', { one: 2 });
02/06/2024 00:38:05 WARN <log.spec.ts:17:64> Text here obj=Object{"one":2}
const logJson = logger().prefix('Json').trace().json();
logJson.info('Hello, world!');
{"ts":"2024-02-05T13:33:05.270Z","level":"info","prefix":"Json","location":"log.spec.ts:9:48","msg":"Hello, world!","args":["Hello, world!"]}
import logger from "npm:@luckydye/log";
const log = logger().prefix("Deno");
log.error("Test error");
Send logs to a InfluxDB (v2).
import logger from "@luckydye/log";
import { InfluxWriteStream } from '@luckydye/log/influx';
const log = logger()
.prefix('Influx')
.pipeTo(
new InfluxWriteStream({
org: 'organisation',
bucket: 'bucket_name',
db: 'database_name',
url: 'https://influxdb.example.com',
token: 'ACCESS_TOKEN',
})
);
// JS_LOG filtering applies here as well
log.info('Hello, world!');
Set the log level. Default is info
.
JS_LOG=[prefix][=][level][,...]
JS_LOG = "error,Test=debug"
const log = logger().prefix("Topic");
Display last frame of stack trace in the output.
const log = logger().trace();
Set the time format. Default is local
.
Set to false
to disable time.
const log = logger().time("local" | "kitchen" | "iso" | "utc");
// disable time
const log = logger().time(false);
const log = logger().json();
const log = logger().pipeTo(WriteableStream);