From 7b005d5d28346f3f2b2fa4405ce82f7b4a28c071 Mon Sep 17 00:00:00 2001 From: Nix Date: Sun, 5 Apr 2026 23:56:44 +0800 Subject: [PATCH] (docs): Update README. --- README.md | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dcfc0f6..3c937d9 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,76 @@ # @nixkrystik/logger -My wonderful logger package. +A heavily stripped down logging library for JavaScript & TypeScript. -## Can i contribute? -you can suggest fixes through Discord, but making pull requests is a no. +## Introduction +This is a rather lightweight, bare-bones package. It's designed to be as frictionless as possible while abstracting multiple transports into simple functions. -## Can i use it? -sure, i couldn't give a shit. +### Example Transport (Using [chalk](https://github.com/chalk/chalk)) +```typescript +import { Logger, LogLevel, Transport } from "@nixkrystik/logger"; +import chalk, { ChalkInstance } from "chalk"; -## Can i fork it? -it's a public library, not sure why not. \ No newline at end of file +class ConsoleTransport implements Transport { + #colors: Record = { + [LogLevel.Debug]: chalk.cyan, + [LogLevel.Information]: chalk.green, + [LogLevel.Warning]: chalk.yellow, + [LogLevel.Error]: chalk.red, + [LogLevel.Fatal]: chalk.bgRed.white, + }; + + #names: Record = { + [LogLevel.Debug]: "DEBUG", + [LogLevel.Information]: "INFO", + [LogLevel.Warning]: "WARN", + [LogLevel.Error]: "ERROR", + [LogLevel.Fatal]: "FATAL", + }; + + async log(level: LogLevel, module: string, content: string) { + console.log( + `[ ${new Date().toISOString().replace("T", " ").replace("Z", "")} ] [ ${this.#colors[level](this.#names[level])} ] >> [ ${chalk.magenta(module)} ]: ${content}`, + ); + } +} + +export default new Logger([new ConsoleTransport()]); +``` + +--- + +### Transport.minLevel +Each transport can restrict the minimum required level before handling logs. + +```typescript +import { LogLevel, Transport } from "@nixkrystik/logger"; + +class ExampleTransport implements Transport { + minLevel = LogLevel.Warning; + + async log(level: LogLevel, module: string, content: string) { + console.log('I only print on "warning" logs!'); + } +} +``` + +### Transport.log(level, module, content) +When handling transports, each logger is able to run asynchronously. + +```typescript +import { LogLevel, Transport } from "@nixkrystik/logger"; + +class ExampleTransport implements Transport { + minLevel = LogLevel.Warning; + + async log(level: LogLevel, module: string, content: string) { + console.log('I only print on "warning" logs!'); + } +} +``` + +## Contributing +Keep issues and PRs in English. + +I don't entirely mind what contributions are made. Unless it's extremely important to add an extenal package, please keep them out :) + +If you're unsure about adding a new feature, you can create an issue. \ No newline at end of file