1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-09-28 06:07:07 +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 util = require("util");
const fs = require("fs"); const fs = require("fs");
const events_1 = require("events"); const events_1 = require("events");
const path = require("path");
const Reset = "\x1b[0m"; const Reset = "\x1b[0m";
const Bright = "\x1b[1m"; const Bright = "\x1b[1m";
const Dim = "\x1b[2m"; const Dim = "\x1b[2m";
@ -50,7 +51,7 @@ class Logging {
} }
let m = ""; let m = "";
error.stack.forEach(e => { error.stack.forEach(e => {
m += e.toString() + "\n"; m += e.toString() + " | ";
}); });
var message = error.name + " " + error.message + "\n" + m; var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]); Logging.message(LoggingTypes.Error, [message]);
@ -156,9 +157,9 @@ class Logging {
}); });
}); });
Logging.fileStream = fs.createWriteStream(this.logFileLocation + "all.log", { flags: "a" }); 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 = fs.createWriteStream(this.logFileLocation + "error.log", { flags: "a" });
Logging.errorStream.write("\n\n"); Logging.errorStream.write("\n");
} }
catch (e) { catch (e) {
console.log(e); console.log(e);
@ -180,10 +181,9 @@ function _getCallerFile() {
current_file = err.stack.shift().getFileName(); current_file = err.stack.shift().getFileName();
while (err.stack.length) { while (err.stack.length) {
caller_file = err.stack.shift().getFileName(); caller_file = err.stack.shift().getFileName();
if (current_file !== caller_file) { console.log(caller_file);
let array = caller_file.split("/"); if (current_file !== caller_file)
return array[array.length - 1]; return path.basename(caller_file);
}
} }
} }
catch (err) { } catch (err) { }

File diff suppressed because one or more lines are too long

View File

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

View File

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