mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-12-23 04:09:24 +00:00
Adding line support and adding default export
This commit is contained in:
parent
932eeacb86
commit
db9a6472c9
1
out/index.d.ts
vendored
1
out/index.d.ts
vendored
@ -22,6 +22,7 @@ export declare class Logging {
|
||||
private static checkQueue();
|
||||
private static initializeFile();
|
||||
}
|
||||
export default Logging;
|
||||
export declare enum LoggingTypes {
|
||||
Log = 0,
|
||||
Warning = 1,
|
||||
|
23
out/index.js
23
out/index.js
@ -52,10 +52,6 @@ class Logging {
|
||||
Logging.errorMessage(error + e.stack);
|
||||
return;
|
||||
}
|
||||
// let m = "";
|
||||
// (<any>error.stack).forEach(e => {
|
||||
// m += e.toString() + "\n";
|
||||
// })
|
||||
var message = error.name + " " + error.message + "\n" + error.stack;
|
||||
Logging.message(LoggingTypes.Error, [message]);
|
||||
}
|
||||
@ -99,7 +95,9 @@ class Logging {
|
||||
}
|
||||
});
|
||||
}
|
||||
var m = "[" + LoggingTypes[type] + "][" + _getCallerFile() + "][" + new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + "]: " + mb;
|
||||
let file = getCallerFile();
|
||||
let date = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
||||
var m = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: ${mb}`;
|
||||
if (this.stdout)
|
||||
console.log(consoleLogFormat + m + Reset);
|
||||
let index = m.indexOf("\x1b");
|
||||
@ -224,6 +222,7 @@ Logging.writing = false;
|
||||
Logging.queue = new Array();
|
||||
Logging.events = new events_1.EventEmitter();
|
||||
exports.Logging = Logging;
|
||||
exports.default = Logging;
|
||||
function fsUnlink(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.unlink(path, (err) => {
|
||||
@ -303,18 +302,22 @@ function getStack() {
|
||||
stack.shift(); // getStack --> Error
|
||||
return stack;
|
||||
}
|
||||
function _getCallerFile() {
|
||||
function getCallerFile() {
|
||||
try {
|
||||
let stack = getStack();
|
||||
let current_file = stack.shift().getFileName();
|
||||
while (stack.length) {
|
||||
let caller_file = stack.shift().getFileName();
|
||||
if (current_file !== caller_file)
|
||||
return path.basename(caller_file);
|
||||
let caller_file = stack.shift();
|
||||
const util = require("util");
|
||||
if (current_file !== caller_file.getFileName())
|
||||
return {
|
||||
file: path.basename(caller_file.getFileName()),
|
||||
line: caller_file.getLineNumber()
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (err) { }
|
||||
return undefined;
|
||||
return { file: undefined, line: 0 };
|
||||
}
|
||||
var LoggingTypes;
|
||||
(function (LoggingTypes) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,12 +1,14 @@
|
||||
{
|
||||
"name": "logger-perfcloud",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node out/test.js"
|
||||
"watch": "tsc --watch",
|
||||
"test": "node out/test.js",
|
||||
"live": "nodemon out/test.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -16,6 +18,7 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.0.24",
|
||||
"nodemon": "^1.17.4",
|
||||
"typescript": "^2.4.2"
|
||||
}
|
||||
}
|
25
src/index.ts
25
src/index.ts
@ -74,10 +74,7 @@ export class Logging {
|
||||
Logging.errorMessage(error + e.stack);
|
||||
return;
|
||||
}
|
||||
// let m = "";
|
||||
// (<any>error.stack).forEach(e => {
|
||||
// m += e.toString() + "\n";
|
||||
// })
|
||||
|
||||
var message = error.name + " " + error.message + "\n" + error.stack;
|
||||
Logging.message(LoggingTypes.Error, [message]);
|
||||
}
|
||||
@ -119,8 +116,9 @@ export class Logging {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var m = "[" + LoggingTypes[type] + "][" + _getCallerFile() + "][" + new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') + "]: " + mb;
|
||||
let file = getCallerFile()
|
||||
let date = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
|
||||
var m = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: ${mb}`;
|
||||
if (this.stdout) console.log(consoleLogFormat + m + Reset);
|
||||
|
||||
let index = m.indexOf("\x1b");
|
||||
@ -235,6 +233,8 @@ export class Logging {
|
||||
}
|
||||
}
|
||||
|
||||
export default Logging;
|
||||
|
||||
function fsUnlink(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.unlink(path, (err) => {
|
||||
@ -325,18 +325,23 @@ function getStack() {
|
||||
return stack
|
||||
}
|
||||
|
||||
function _getCallerFile() {
|
||||
function getCallerFile() {
|
||||
try {
|
||||
let stack = getStack()
|
||||
|
||||
let current_file = stack.shift().getFileName();
|
||||
|
||||
while (stack.length) {
|
||||
let caller_file = stack.shift().getFileName();
|
||||
if (current_file !== caller_file) return path.basename(caller_file);
|
||||
let caller_file = stack.shift();
|
||||
const util = require("util")
|
||||
if (current_file !== caller_file.getFileName())
|
||||
return {
|
||||
file: path.basename(caller_file.getFileName()),
|
||||
line: caller_file.getLineNumber()
|
||||
};
|
||||
}
|
||||
} catch (err) { }
|
||||
return undefined;
|
||||
return { file: undefined, line: 0 };
|
||||
}
|
||||
|
||||
export enum LoggingTypes {
|
||||
|
Loading…
Reference in New Issue
Block a user