(docs): Update README.
This commit is contained in:
79
README.md
79
README.md
@@ -1,11 +1,76 @@
|
|||||||
# @nixkrystik/logger
|
# @nixkrystik/logger
|
||||||
My wonderful logger package.
|
A heavily stripped down logging library for JavaScript & TypeScript.
|
||||||
|
|
||||||
## Can i contribute?
|
## Introduction
|
||||||
you can suggest fixes through Discord, but making pull requests is a no.
|
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?
|
### Example Transport (Using [chalk](https://github.com/chalk/chalk))
|
||||||
sure, i couldn't give a shit.
|
```typescript
|
||||||
|
import { Logger, LogLevel, Transport } from "@nixkrystik/logger";
|
||||||
|
import chalk, { ChalkInstance } from "chalk";
|
||||||
|
|
||||||
## Can i fork it?
|
class ConsoleTransport implements Transport {
|
||||||
it's a public library, not sure why not.
|
#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.
|
||||||
Reference in New Issue
Block a user