0.7.4 • Published 5 months ago
@luckydye/log v0.7.4
log
A small (<2KB gzipped minified) JavaScript logging library inspired by charmbracelet/log and docs.rs/env_logger.
Usage
npm i @luckydye/log
Examples
Log levels
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)
Formatted arguments
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}
JSON output
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!"]}
Deno
import logger from "npm:@luckydye/log";
const log = logger().prefix("Deno");
log.error("Test error");
InfluxDB
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!');
Environment variables
JS_LOG
Set the log level. Default is info
.
Set log level for specific prefixes.
JS_LOG=[prefix][=][level][,...]
JS_LOG = "error,Test=debug"
Configuration
Prefix
const log = logger().prefix("Topic");
Enable stack trace
Display last frame of stack trace in the output.
const log = logger().trace();
Set time format
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);
Enable json output
const log = logger().json();
Pipe log messages to arbitrary stream
const log = logger().pipeTo(WriteableStream);
0.7.4
5 months ago
0.7.3
7 months ago
0.7.2
8 months ago
0.7.1
9 months ago
0.7.0
9 months ago
0.6.1
10 months ago
0.5.8
10 months ago
0.5.7
10 months ago
0.5.4
10 months ago
0.5.6
10 months ago
0.5.5
10 months ago
0.6.0
10 months ago
0.5.3
10 months ago
0.5.0
10 months ago
0.5.2
10 months ago
0.5.1
10 months ago
0.3.2
10 months ago
0.4.0
10 months ago
0.3.4
10 months ago
0.3.3
10 months ago
0.3.1
10 months ago
0.3.0
10 months ago
0.2.1
10 months ago
0.2.0
10 months ago
0.1.0
10 months ago