1
0

(docs): Update README.

This commit is contained in:
2026-04-05 23:56:44 +08:00
parent 6ecc774e4d
commit 7b005d5d28

View File

@@ -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.
class ConsoleTransport implements Transport {
#colors: Record<LogLevel, ChalkInstance> = {
[LogLevel.Debug]: chalk.cyan,
[LogLevel.Information]: chalk.green,
[LogLevel.Warning]: chalk.yellow,
[LogLevel.Error]: chalk.red,
[LogLevel.Fatal]: chalk.bgRed.white,
};
#names: Record<LogLevel, string> = {
[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.