version 1.3!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

This commit is contained in:
2025-06-25 02:42:05 -04:00
parent df15f608ed
commit 5175d66eb5
5 changed files with 279 additions and 28 deletions

View File

@@ -34,7 +34,7 @@ log.n("Something happened");
Disable a type of message globally:
```ts
import Logging, { MessageTypeVisibility } from "./mod.ts";
import Logging, { MessageTypeVisibility } from "@proxnet/undead-logging";
// .. logging source "Main" is in the scope
MessageTypeVisibility.Error = false;
@@ -45,4 +45,62 @@ log.error("I am not visible");
// output:
// 2024-11-14T01:21:40.350Z Main [INFO] I am visible
```
## Event Listeners
Event listeners are called when a message is logged on any logging source
An event callback can either receive messages as either:
* Whole lines, including formatting, colors, excluding newlines
or
* Individual `msg` (string), `type` (MessageType), `source` (string), and `time` (Date) arguments
Callback ran when a message is logged anywhere:
```ts
LoggingListeners.onmsg('basic', msg => {
// `msg` is a string containing the entire line w/ formatting
});
```
Callback ran when a message is logged anywhere (this time components are split up):
```ts
LoggingListeners.onmsg('type', (msg, type, source, time) => {
// msg: string
// type: MessageType - import { MessageType } from "@proxnet/undead-logging";)
// source: string
// time: Date
});
```
Remove callback:
```ts
const cb = msg => { /* do something with msg */ };
LoggingListeners.onmsg('basic', cb);
LoggingListeners.offmsg('basic', cb);
```
## Time display modes
You can display three different formats for time:
* UTC
* Unix time (in milliseconds)
* Local [process] time (in seconds, from the `performance` API)
Set the time format:
```ts
import { LoggingConfiguration, TimeFormat } from "@proxnet/undead-logging";
LoggingConfiguration.timeFormat = TimeFormat.Local
// or
LoggingConfiguration.timeFormat = TimeFormat.Utc
```
## (advanced) Logging timing
You can control when log functions are executed using `LoggingConfiguration.logTiming`.
Logs are sent synchronously by default. You can optionally defer logs with `setImmediate` using `LogTiming.Deferred`
```ts
LoggingConfiguration.logTiming = LogTiming.Sync
LoggingConfiguration.logTiming = LogTiming.Deferred
```