1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-11-14 22:41:04 +00:00

platform independant filename extraction

This commit is contained in:
Fabian Stamm 2017-10-21 12:45:20 +02:00
parent cec4cf158a
commit f8034d9758
4 changed files with 15 additions and 17 deletions

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const util = require("util");
const fs = require("fs");
const events_1 = require("events");
const path = require("path");
const Reset = "\x1b[0m";
const Bright = "\x1b[1m";
const Dim = "\x1b[2m";
@ -50,7 +51,7 @@ class Logging {
}
let m = "";
error.stack.forEach(e => {
m += e.toString() + "\n";
m += e.toString() + " | ";
});
var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]);
@ -156,9 +157,9 @@ class Logging {
});
});
Logging.fileStream = fs.createWriteStream(this.logFileLocation + "all.log", { flags: "a" });
Logging.fileStream.write("\n\n");
Logging.fileStream.write("\n");
Logging.errorStream = fs.createWriteStream(this.logFileLocation + "error.log", { flags: "a" });
Logging.errorStream.write("\n\n");
Logging.errorStream.write("\n");
}
catch (e) {
console.log(e);
@ -180,10 +181,9 @@ function _getCallerFile() {
current_file = err.stack.shift().getFileName();
while (err.stack.length) {
caller_file = err.stack.shift().getFileName();
if (current_file !== caller_file) {
let array = caller_file.split("/");
return array[array.length - 1];
}
console.log(caller_file);
if (current_file !== caller_file)
return path.basename(caller_file);
}
}
catch (err) { }

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "logger-perfcloud",
"version": "1.0.4",
"version": "1.0.5",
"description": "",
"main": "out/index.js",
"types": "out/index.d.ts",

View File

@ -1,6 +1,7 @@
import * as util from "util";
import * as fs from "fs";
import { EventEmitter } from "events";
import * as path from "path";
const Reset = "\x1b[0m"
const Bright = "\x1b[1m"
@ -68,7 +69,7 @@ export class Logging {
}
let m = "";
(<any>error.stack).forEach(e => {
m += e.toString() + "\n";
m += e.toString() + " | ";
})
var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]);
@ -168,9 +169,9 @@ export class Logging {
});
Logging.fileStream = fs.createWriteStream(this.logFileLocation + "all.log", { flags: "a" });
Logging.fileStream.write("\n\n");
Logging.fileStream.write("\n");
Logging.errorStream = fs.createWriteStream(this.logFileLocation + "error.log", { flags: "a" });
Logging.errorStream.write("\n\n");
Logging.errorStream.write("\n");
} catch (e) {
console.log(e);
}
@ -189,11 +190,8 @@ function _getCallerFile() {
while (err.stack.length) {
caller_file = (<any>err.stack).shift().getFileName();
if (current_file !== caller_file) {
let array = caller_file.split("/")
return array[array.length - 1];
}
console.log(caller_file);
if (current_file !== caller_file) return path.basename(caller_file);
}
} catch (err) { }
return undefined;