Skip to main content

A simple logger for Javascript runtimes and the browser.

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
a month ago (0.1.13)

simcolog

A simple logger for Javascript runtimes and the browser.

Installation

npm

npx jsr add @mapokapo/simcolog

Deno

deno add @mapokapo/simcolog

Bun

bunx jsr add @mapokapo/simcolog

Usage

import { defaultLogger } from "@mapokapo/simcolog";
// or in Deno
import { defaultLogger } from "jsr:@mapokapo/simcolog@^0.1.13";

const logEverything = true;

const myLogger = defaultLogger.modify({
  level: logEverything ? "trace" : "info",
});

myLogger.info("Hello info!"); // [TIMETAMP] [info] Hello info!
myLogger.trace("Hello trace!"); // [TIMETAMP] [trace] Hello trace!

let messageHistory: string[] = [];

const newLogger = myLogger.modify({
  includeTimestamp: false,
  level: "info",
  logCallback: message => messageHistory.push(message),
});

newLogger.info("Hello info!"); // [info] Hello info!
newLogger.warn("Hello warn!"); // [warn] Hello warn!
newLogger.trace("Hello trace!"); // nothing gets printed

newLogger.info(`Message history: ${messageHistory.join(", ")}`); // [info] Hello info!, [warn] Hello warn!
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @mapokapo/simcolog

Import symbol

import * as mod from "@mapokapo/simcolog";

Add Package

npx jsr add @mapokapo/simcolog

Import symbol

import * as mod from "@mapokapo/simcolog";

Add Package

yarn dlx jsr add @mapokapo/simcolog

Import symbol

import * as mod from "@mapokapo/simcolog";

Add Package

pnpm dlx jsr add @mapokapo/simcolog

Import symbol

import * as mod from "@mapokapo/simcolog";

Add Package

bunx jsr add @mapokapo/simcolog

Import symbol

import * as mod from "@mapokapo/simcolog";