README fixes, new RoundedLocal time format, more local source options

* i wanted to make sure `undefined` was handled properly. seems like it is.
* tested with Bun, works. Deno runs faster though, by about 1.8µs/message construction!
* Removed skeletons from closet (bug fixes)
* Sources can now optionally specify their own time format and/or log timing
* Requests and Responses now can be converted and displayed (no bodies)
This commit is contained in:
2025-07-19 05:00:07 -04:00
parent b6f3ccb73c
commit 44784130f9
10 changed files with 706 additions and 117 deletions

64
benchmark/bun.ts Normal file
View File

@@ -0,0 +1,64 @@
import chalk from "chalk";
import Logging, { MessageType } from "../mod.ts";
interface BenchStats {
avg: number,
med: number,
rng: number,
min: number,
max: number,
}
function createBench(n: number) {
const log = new Logging("Bench");
const data: number[] = [];
for (let i = 0; i < 30; i++) {
const last = performance.now();
for (let i = 0; i < n; i++)
log.bench(MessageType.Info, chalk.black, 'a');
data.push(performance.now() - last);
}
const sorted = [...data].sort((a, b) => a - b);
return {
n,
avg: data.reduce((sum, val) => sum + val, 0) / data.length,
med: sorted.length % 2 === 0
? (sorted[sorted.length / 2 - 1] + sorted[sorted.length / 2]) / 2
: sorted[Math.floor(sorted.length / 2)],
rng: Math.max(...data) - Math.min(...data),
min: Math.min(...data),
max: Math.max(...data)
} as BenchStats;
}
const benches = [
createBench(1),
createBench(100),
createBench(1000),
createBench(10000),
createBench(100000),
];
function trimNumber(n: number) {
const split = n.toString().split('.');
if (!split[1]) return n;
else if (split[1].length > 4) return `${split[0]}.${split[1].substring(0, 4)}`;
else if (split[1].length == 0) return n.toString();
else return split.join('.');
}
for (const stats of benches) {
for (const value of Object.values(stats)) {
const label = value < 1 ? 'µs' : 'ms';
const val = value < 1 ? value * 1000 : value;
const i = Object.values(stats).indexOf(value);
const key = Object.keys(stats).find((_val, index) => index == i);
console.log(`${key}: ${trimNumber(val)}${key !== 'n' ? label : ''}`);
}
console.log('');
}

227
benchmark/deno-example.json Normal file
View File

@@ -0,0 +1,227 @@
{
"version": 1,
"runtime": "Deno/2.4.1 x86_64-pc-windows-msvc",
"cpu": "unknown",
"benches": [
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-sync",
"name": "1 Log",
"baseline": false,
"results": [
{
"ok": {
"n": 42,
"min": 1547.66,
"max": 1867.93,
"avg": 1596.3097619047621,
"p75": 1602.51,
"p99": 1867.93,
"p995": 1867.93,
"p999": 1867.93,
"highPrecision": false,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-sync",
"name": "100 Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 3227,
"min": 149200.0,
"max": 277100.0,
"avg": 155426.0,
"p75": 151700.0,
"p99": 230500.0,
"p995": 233300.0,
"p999": 250500.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-sync",
"name": "1k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 332,
"min": 1492200.0,
"max": 2041200.0,
"avg": 1553763.0,
"p75": 1581400.0,
"p99": 1678900.0,
"p995": 1847700.0,
"p999": 2041200.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-sync",
"name": "10k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 43,
"min": 15433100.0,
"max": 15875500.0,
"avg": 15512717.0,
"p75": 15516000.0,
"p99": 15875500.0,
"p995": 15875500.0,
"p999": 15875500.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-sync",
"name": "100k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 14,
"min": 154448800.0,
"max": 162192300.0,
"avg": 156260422.0,
"p75": 156585200.0,
"p99": 162192300.0,
"p995": 162192300.0,
"p999": 162192300.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-deferred",
"name": "1 Log",
"baseline": false,
"results": [
{
"ok": {
"n": 42,
"min": 1553.59,
"max": 1623.61,
"avg": 1581.7592857142856,
"p75": 1594.76,
"p99": 1623.61,
"p995": 1623.61,
"p999": 1623.61,
"highPrecision": false,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-deferred",
"name": "100 Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 3205,
"min": 148800.0,
"max": 357900.0,
"avg": 156507.0,
"p75": 152200.0,
"p99": 233300.0,
"p995": 241400.0,
"p999": 273500.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-deferred",
"name": "1k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 330,
"min": 1504500.0,
"max": 1744900.0,
"avg": 1564083.0,
"p75": 1595100.0,
"p99": 1668200.0,
"p995": 1732400.0,
"p999": 1744900.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-deferred",
"name": "10k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 43,
"min": 15435800.0,
"max": 15980800.0,
"avg": 15641247.0,
"p75": 15771900.0,
"p99": 15980800.0,
"p995": 15980800.0,
"p999": 15980800.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
},
{
"origin": "file:///C:/Users/Keagan/undead-logging/benchmark/deno.ts",
"group": "timing-deferred",
"name": "100k Logs",
"baseline": false,
"results": [
{
"ok": {
"n": 14,
"min": 154775900.0,
"max": 159622500.0,
"avg": 156075222.0,
"p75": 156708400.0,
"p99": 159622500.0,
"p995": 159622500.0,
"p999": 159622500.0,
"highPrecision": true,
"usedExplicitTimers": false
}
}
]
}
]
}

109
benchmark/deno.ts Normal file
View File

@@ -0,0 +1,109 @@
import Logging, { LogTiming, MessageType } from "@proxnet/undead-logging";
import chalk from "chalk";
// SYNC
Deno.bench({
name: "1 Log",
group: "timing-sync",
fn: () => {
const log = new Logging("Bench");
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "100 Logs",
group: "timing-sync",
fn: () => {
const log = new Logging("Bench");
for (let i = 0; i < 100; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "1k Logs",
group: "timing-sync",
fn: () => {
const log = new Logging("Bench");
for (let i = 0; i < 1_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "10k Logs",
group: "timing-sync",
fn: () => {
const log = new Logging("Bench");
for (let i = 0; i < 10_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "100k Logs",
group: "timing-sync",
fn: () => {
const log = new Logging("Bench");
log.logTiming = LogTiming.Deferred;
for (let i = 0; i < 100_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
// DEFERRED
Deno.bench({
name: "1 Log",
group: "timing-deferred",
fn: () => {
const log = new Logging("Bench");
log.logTiming = LogTiming.Deferred;
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "100 Logs",
group: "timing-deferred",
fn: () => {
const log = new Logging("Bench");
log.logTiming = LogTiming.Deferred;
for (let i = 0; i < 100; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "1k Logs",
group: "timing-deferred",
fn: () => {
const log = new Logging("Bench");
log.logTiming = LogTiming.Deferred;
for (let i = 0; i < 1_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "10k Logs",
group: "timing-deferred",
fn: () => {
const log = new Logging("Bench");
log.logTiming = LogTiming.Deferred;
for (let i = 0; i < 10_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});
Deno.bench({
name: "100k Logs",
group: "timing-deferred",
fn: () => {
const log = new Logging("Bench");
for (let i = 0; i < 100_000; i++)
log.bench(MessageType.Info, chalk.black, 'a');
}
});