Working toward web compatibility
- Separating File output from LoggingBasse - Separating Console output from LoggingBase - Adding new Plugin mechanism
This commit is contained in:
27
src/test.ts
27
src/test.ts
@ -1,5 +1,21 @@
|
||||
import { Logging, LoggingBase } from "./index";
|
||||
import { randomBytes } from "crypto";
|
||||
import * as fs from "fs";
|
||||
const deleteFolderRecursive = function (path: string) {
|
||||
if (fs.existsSync(path)) {
|
||||
fs.readdirSync(path).forEach(function (file, index) {
|
||||
var curPath = path + "/" + file;
|
||||
if (fs.lstatSync(curPath).isDirectory()) { // recurse
|
||||
deleteFolderRecursive(curPath);
|
||||
} else { // delete file
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
}
|
||||
};
|
||||
|
||||
deleteFolderRecursive("./logs")
|
||||
|
||||
Logging.log("test")
|
||||
Logging.log("i", "am", { a: "an" }, 1000);
|
||||
@ -30,17 +46,20 @@ cus2.log("Hello from custom Logger 2")
|
||||
cus22.log("Hello from custom Logger 22")
|
||||
cus2.log("Hello from custom Logger 2")
|
||||
|
||||
Logging.console_out = false;
|
||||
const BenchmarkLogger = new LoggingBase({
|
||||
console: false,
|
||||
name: "bench"
|
||||
})
|
||||
async function benchmark(count: number, message_size: number) {
|
||||
await Logging.waitForSetup();
|
||||
await BenchmarkLogger.waitForSetup();
|
||||
const randData = randomBytes(message_size).toString("hex")
|
||||
const t = process.hrtime();
|
||||
for (let i = 0; i < count; i++) {
|
||||
Logging.log(randData)
|
||||
BenchmarkLogger.log(randData)
|
||||
}
|
||||
const diff = process.hrtime(t);
|
||||
const NS_PER_SEC = 1e9;
|
||||
await Logging.waitForSetup();
|
||||
await BenchmarkLogger.waitForSetup();
|
||||
const ns = diff[0] * NS_PER_SEC + diff[1];
|
||||
console.log(`Benchmark took ${ns / 1000000}ms for ${count} messages with a size of ${message_size} characters`);
|
||||
console.log(`This is equal to ${(ns / 1000000) / count} ms per message`)
|
||||
|
Reference in New Issue
Block a user