A minimalistic logging tool designed specifically for use with Deno,
supporting essential log levels such as info
, warn
, error
, debug
, verbose
, trace
.
This logger outputs to the terminal in either text
or json
format,
displaying messages with a prefix that includes the current local date and time.
It allows users to easily toggle the enabled log level and change the output format,
providing flexibility based on their preference or application needs.
Introducing fork
to isolate and manage logs within specific application segments for pinpoint troubleshooting and future reference.
Added support of loggerInstance
to use a singleton pattern and centralize the logger configuration.
deno add @studiowebux/deno-minilog
const logger = new Logger(); // Logs everything by default logger.info("This is an info log"); logger.info({ foo: "bar" }); logger.error(new Error("Oops")) logger.warn("You should check the logs...") logger.debug("Debug message.") logger.verbose("Verbose message.") logger.trace("Message with trace.")
const logger = new Logger({info: false}); logger.info("This info wont be showed."); logger.error(new Error("Oops")) logger.warn("You should check the logs...")
You can set the format to json
, usually required with observability tools.
const jsonLogger = new Logger({ format: "json" }); // Prints {"message":"...","level":"...","timestamp":"...","id":"..."}
Trace option
This output will spread on multiple lines, so might not be the best in production environment where each line is an entry.
see tests/test.ts
for other examples.
Forks
This feature is useful to sort and isolate logs when wanting to troubleshoot part of the application. And to let the logs there (even in production) the Logger instance can isolate and hide those forked logger instance.
forkToPrint
: A list of the id to show, anything else is hidden.hideFork
: Hide all forks and show only the "normal" logs.See tests/flow.ts
for the examples.
const logger = new Logger({ forkToPrint: ["my_fn_logs"] });
Prints:
9/13/2024, 4:37:22 PM DEBUG [my_fn_logs]: myFn 9/13/2024, 4:37:22 PM DEBUG [my_fn_logs]: My Function 9/13/2024, 4:37:22 PM INFO [my_fn_logs]: i'm doing stuff 9/13/2024, 4:37:22 PM WARN [my_fn_logs]: Oops, stuff is now weird 9/13/2024, 4:37:22 PM VERBOSE [my_fn_logs]: {"foo":"bar"} 9/13/2024, 4:37:22 PM DEBUG [my_fn_logs]: I'm done.
const logger = new Logger();
Prints:
9/13/2024, 4:36:43 PM INFO: Application is starting... 9/13/2024, 4:36:43 PM DEBUG [my_fn_logs]: myFn 9/13/2024, 4:36:43 PM DEBUG [my_fn_logs]: My Function 9/13/2024, 4:36:43 PM INFO [my_fn_logs]: i'm doing stuff 9/13/2024, 4:36:43 PM WARN [my_fn_logs]: Oops, stuff is now weird 9/13/2024, 4:36:43 PM VERBOSE [my_fn_logs]: {"foo":"bar"} 9/13/2024, 4:36:43 PM DEBUG [my_fn_logs]: I'm done. 9/13/2024, 4:36:43 PM DEBUG [my_second_fn]: mySecondFn 9/13/2024, 4:36:43 PM DEBUG [my_second_fn]: My Second Function 9/13/2024, 4:36:43 PM DEBUG [my_second_fn]: I'm done. 9/13/2024, 4:36:43 PM INFO: Application has ended.
const logger = new Logger({ forkToPrint: [], hideForks: true });
Prints:
9/13/2024, 4:35:07 PM INFO: Application is starting... 9/13/2024, 4:35:07 PM INFO: Application has ended.
Singleton
See tests/instance
for an example.
import { loggerInstance } from "../../src/mod.ts"; loggerInstance.setConfig({ debug: false }); loggerInstance.info("Application is starting");
git tag -a X.Y.Z -m "Version X.Y.Z" git push origin tags/X.Y.Z
Branch Checkout:
git checkout -b <feature|fix|release|chore|hotfix>/prefix-name
Your branch name must starts with [feature|fix|release|chore|hotfix] and use a / before the name; Use hyphens as separator; The prefix correspond to your Kanban tool id (e.g. abc-123)
Keep your branch synced:
git fetch origin git rebase origin/master
Commit your changes:
git add . git commit -m "<feat|ci|test|docs|build|chore|style|refactor|perf|BREAKING CHANGE>: commit message"
Follow this convention commitlint for your commit message structure
Push your changes:
git push origin <feature|fix|release|chore|hotfix>/prefix-name
Examples:
git checkout -b release/v1.15.5 git checkout -b feature/abc-123-something-awesome git checkout -b hotfix/abc-432-something-bad-to-fix
git commit -m "docs: added awesome documentation" git commit -m "feat: added new feature" git commit -m "test: added tests"
Distributed under the MIT License. See LICENSE for more information.
Add Package
deno add jsr:@studiowebux/deno-minilog
Import symbol
import * as deno_minilog from "@studiowebux/deno-minilog";
---- OR ----
Import directly with a jsr specifier
import * as deno_minilog from "jsr:@studiowebux/deno-minilog";
Add Package
npx jsr add @studiowebux/deno-minilog
Import symbol
import * as deno_minilog from "@studiowebux/deno-minilog";
Add Package
yarn dlx jsr add @studiowebux/deno-minilog
Import symbol
import * as deno_minilog from "@studiowebux/deno-minilog";
Add Package
pnpm dlx jsr add @studiowebux/deno-minilog
Import symbol
import * as deno_minilog from "@studiowebux/deno-minilog";
Add Package
bunx jsr add @studiowebux/deno-minilog
Import symbol
import * as deno_minilog from "@studiowebux/deno-minilog";