1
0
mirror of https://git.hibas.dev/OpenServer/NodeLogging.git synced 2025-04-05 21:32:56 +00:00
nodelogging/src/test.ts
2019-04-02 19:59:29 -04:00

76 lines
2.4 KiB
TypeScript

import { randomBytes } from "crypto";
import * as fs from "fs";
import { Logging, LoggingBase } from ".";
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);
Logging.error(new Error("fehler 001"));
Logging.debug("Some Debug infos");
Logging.errorMessage("i", "am", "an", "error");
Logging.log("\x1b[31m\x1b[31m\x1b[31m\x1b[31m\x1b[31m\x1b[31m TEST \x1b[31m\x1b[31m\x1b[31m")
let err = new Error()
if (typeof err.stack !== "string") console.log("Stacktrace invalid", err.stack)
let cus = new LoggingBase({ name: "test" });
cus.log("Hello from custom Logger")
let cus2 = new LoggingBase("test2");
cus2.log("Hello from custom Logger 2")
let cus22 = new LoggingBase("test2");
cus22.log("Hello from custom Logger 22")
cus2.log("Hello from custom Logger 2")
cus22.log("Hello from custom Logger 22")
cus2.log("Hello from custom Logger 2")
cus22.log("Hello from custom Logger 22")
cus2.log("Hello from custom Logger 2")
cus22.log("Hello from custom Logger 22")
cus2.log("Hello from custom Logger 2")
cus22.log("Hello from custom Logger 22")
cus2.log("Hello from custom Logger 2")
const BenchmarkLogger = new LoggingBase({
console: false,
name: "bench"
})
async function benchmark(count: number, message_size: number) {
await BenchmarkLogger.waitForSetup();
const randData = randomBytes(message_size).toString("hex")
const t = process.hrtime();
for (let i = 0; i < count; i++) {
BenchmarkLogger.log(randData)
}
const diff = process.hrtime(t);
const NS_PER_SEC = 1e9;
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`)
}
Logging.waitForSetup().then(async () => {
return;
console.log("Large data benchmark:")
await benchmark(7000, 50000);
console.log("Realdata data benchmark:")
await benchmark(100000, 100)
});