1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-12-23 04:49:23 +00:00

Adding events and fixing call stack in one line problem

This commit is contained in:
Fabian Stamm 2017-09-16 19:12:58 +02:00
parent 836935ac8a
commit 3562efdd6f
5 changed files with 22 additions and 4 deletions

3
out/index.d.ts vendored
View File

@ -1,3 +1,5 @@
/// <reference types="node" />
import { EventEmitter } from "events";
export declare class Logging {
private static logFileLocation;
private static stdout;
@ -5,6 +7,7 @@ export declare class Logging {
private static errorStream;
private static writing;
private static queue;
static events: EventEmitter;
static config(logfolder: string, stdout: boolean): void;
static debug(...message: any[]): void;
static log(...message: any[]): void;

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const util = require("util");
const fs = require("fs");
const events_1 = require("events");
const Reset = "\x1b[0m";
const Bright = "\x1b[1m";
const Dim = "\x1b[2m";
@ -44,7 +45,11 @@ class Logging {
Logging.errorMessage(error);
return;
}
var message = error.name + " " + error.message + "\n" + error.stack;
let m = "";
error.stack.forEach(e => {
m += e.toString() + "\n";
});
var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]);
}
static errorMessage(...message) {
@ -89,6 +94,7 @@ class Logging {
}
Logging.writeMessageToFile(m, type === LoggingTypes.Error);
}
Logging.events.emit("message", { type: type, message: mb });
if (this.stdout)
console.log(consoleLogFormat + m + Reset);
}
@ -155,6 +161,7 @@ Logging.logFileLocation = "./logs/";
Logging.stdout = true;
Logging.writing = false;
Logging.queue = new Array();
Logging.events = new events_1.EventEmitter();
exports.Logging = Logging;
function _getCallerFile() {
try {

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,5 +1,6 @@
import * as util from "util";
import * as fs from "fs";
import { EventEmitter } from "events";
const Reset = "\x1b[0m"
const Bright = "\x1b[1m"
@ -37,6 +38,8 @@ export class Logging {
private static writing = false;
private static queue = new Array<{ message: string, error: boolean }>();
static events: EventEmitter = new EventEmitter();
static config(logfolder: string, stdout: boolean) {
this.logFileLocation = logfolder;
this.stdout = stdout;
@ -59,7 +62,11 @@ export class Logging {
Logging.errorMessage(error);
return;
}
var message = error.name + " " + error.message + "\n" + error.stack;
let m = "";
(<any>error.stack).forEach(e => {
m += e.toString() + "\n";
})
var message = error.name + " " + error.message + "\n" + m;
Logging.message(LoggingTypes.Error, [message]);
}
@ -104,6 +111,7 @@ export class Logging {
}
Logging.writeMessageToFile(m, type === LoggingTypes.Error);
}
Logging.events.emit("message", { type: type, message: mb });
if (this.stdout) console.log(consoleLogFormat + m + Reset);
}