mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-14 17:01:05 +00:00
exporting colors
This commit is contained in:
parent
6bf59ede32
commit
d7242f722a
25
out/index.d.ts
vendored
25
out/index.d.ts
vendored
@ -1,5 +1,30 @@
|
||||
/// <reference types="node" />
|
||||
import { EventEmitter } from "events";
|
||||
export declare const Colors: {
|
||||
Reset: string;
|
||||
Bright: string;
|
||||
Dim: string;
|
||||
Underscore: string;
|
||||
Blink: string;
|
||||
Reverse: string;
|
||||
Hidden: string;
|
||||
FgBlack: string;
|
||||
FgRed: string;
|
||||
FgGreen: string;
|
||||
FgYellow: string;
|
||||
FgBlue: string;
|
||||
FgMagenta: string;
|
||||
FgCyan: string;
|
||||
FgWhite: string;
|
||||
BgBlack: string;
|
||||
BgRed: string;
|
||||
BgGreen: string;
|
||||
BgYellow: string;
|
||||
BgBlue: string;
|
||||
BgMagenta: string;
|
||||
BgCyan: string;
|
||||
BgWhite: string;
|
||||
};
|
||||
export interface LoggingBaseOptions {
|
||||
logfile: string;
|
||||
errorfile: string;
|
||||
|
58
out/index.js
58
out/index.js
@ -5,29 +5,31 @@ const fs = require("fs");
|
||||
const events_1 = require("events");
|
||||
const path = require("path");
|
||||
const lock_1 = require("./lock");
|
||||
const Reset = "\x1b[0m";
|
||||
const Bright = "\x1b[1m";
|
||||
const Dim = "\x1b[2m";
|
||||
const Underscore = "\x1b[4m";
|
||||
const Blink = "\x1b[5m";
|
||||
const Reverse = "\x1b[7m";
|
||||
const Hidden = "\x1b[8m";
|
||||
const FgBlack = "\x1b[30m";
|
||||
const FgRed = "\x1b[31m";
|
||||
const FgGreen = "\x1b[32m";
|
||||
const FgYellow = "\x1b[33m";
|
||||
const FgBlue = "\x1b[34m";
|
||||
const FgMagenta = "\x1b[35m";
|
||||
const FgCyan = "\x1b[36m";
|
||||
const FgWhite = "\x1b[37m";
|
||||
const BgBlack = "\x1b[40m";
|
||||
const BgRed = "\x1b[41m";
|
||||
const BgGreen = "\x1b[42m";
|
||||
const BgYellow = "\x1b[43m";
|
||||
const BgBlue = "\x1b[44m";
|
||||
const BgMagenta = "\x1b[45m";
|
||||
const BgCyan = "\x1b[46m";
|
||||
const BgWhite = "\x1b[47m";
|
||||
exports.Colors = {
|
||||
Reset: "\x1b[0m",
|
||||
Bright: "\x1b[1m",
|
||||
Dim: "\x1b[2m",
|
||||
Underscore: "\x1b[4m",
|
||||
Blink: "\x1b[5m",
|
||||
Reverse: "\x1b[7m",
|
||||
Hidden: "\x1b[8m",
|
||||
FgBlack: "\x1b[30m",
|
||||
FgRed: "\x1b[31m",
|
||||
FgGreen: "\x1b[32m",
|
||||
FgYellow: "\x1b[33m",
|
||||
FgBlue: "\x1b[34m",
|
||||
FgMagenta: "\x1b[35m",
|
||||
FgCyan: "\x1b[36m",
|
||||
FgWhite: "\x1b[37m",
|
||||
BgBlack: "\x1b[40m",
|
||||
BgRed: "\x1b[41m",
|
||||
BgGreen: "\x1b[42m",
|
||||
BgYellow: "\x1b[43m",
|
||||
BgBlue: "\x1b[44m",
|
||||
BgMagenta: "\x1b[45m",
|
||||
BgCyan: "\x1b[46m",
|
||||
BgWhite: "\x1b[47m"
|
||||
};
|
||||
const maxFileSize = 500000000;
|
||||
const OriginalErrorStackFunction = Error.prototype.prepareStackTrace;
|
||||
class LoggingBase {
|
||||
@ -95,20 +97,20 @@ class LoggingBase {
|
||||
this.message(LoggingTypes.Error, message);
|
||||
}
|
||||
async message(type, message, customColors, caller) {
|
||||
var consoleLogFormat = Reset;
|
||||
var consoleLogFormat = exports.Colors.Reset;
|
||||
if (!customColors) {
|
||||
switch (type) {
|
||||
case LoggingTypes.Log:
|
||||
//m += FgWhite + BgBlack;
|
||||
break;
|
||||
case LoggingTypes.Error:
|
||||
consoleLogFormat += FgRed; //FgWhite + BgRed + FgWhite;
|
||||
consoleLogFormat += exports.Colors.FgRed; //FgWhite + BgRed + FgWhite;
|
||||
break;
|
||||
case LoggingTypes.Debug:
|
||||
consoleLogFormat += FgCyan;
|
||||
consoleLogFormat += exports.Colors.FgCyan;
|
||||
break;
|
||||
case LoggingTypes.Warning:
|
||||
consoleLogFormat += FgYellow;
|
||||
consoleLogFormat += exports.Colors.FgYellow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -136,7 +138,7 @@ class LoggingBase {
|
||||
let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `;
|
||||
let message_lines = mb.split("\n").map(line => prefix + line);
|
||||
if (this.config.console_out)
|
||||
message_lines.forEach(line => console.log(consoleLogFormat + line + Reset));
|
||||
message_lines.forEach(line => console.log(consoleLogFormat + line + exports.Colors.Reset));
|
||||
let m = message_lines.join("\n");
|
||||
let index = m.indexOf("\x1b");
|
||||
while (index >= 0) {
|
||||
|
File diff suppressed because one or more lines are too long
58
src/index.ts
58
src/index.ts
@ -4,31 +4,33 @@ import { EventEmitter } from "events";
|
||||
import * as path from "path";
|
||||
import Lock from "./lock";
|
||||
|
||||
const Reset = "\x1b[0m"
|
||||
const Bright = "\x1b[1m"
|
||||
const Dim = "\x1b[2m"
|
||||
const Underscore = "\x1b[4m"
|
||||
const Blink = "\x1b[5m"
|
||||
const Reverse = "\x1b[7m"
|
||||
const Hidden = "\x1b[8m"
|
||||
export const Colors = {
|
||||
Reset: "\x1b[0m",
|
||||
Bright: "\x1b[1m",
|
||||
Dim: "\x1b[2m",
|
||||
Underscore: "\x1b[4m",
|
||||
Blink: "\x1b[5m",
|
||||
Reverse: "\x1b[7m",
|
||||
Hidden: "\x1b[8m",
|
||||
|
||||
const FgBlack = "\x1b[30m"
|
||||
const FgRed = "\x1b[31m"
|
||||
const FgGreen = "\x1b[32m"
|
||||
const FgYellow = "\x1b[33m"
|
||||
const FgBlue = "\x1b[34m"
|
||||
const FgMagenta = "\x1b[35m"
|
||||
const FgCyan = "\x1b[36m"
|
||||
const FgWhite = "\x1b[37m"
|
||||
FgBlack: "\x1b[30m",
|
||||
FgRed: "\x1b[31m",
|
||||
FgGreen: "\x1b[32m",
|
||||
FgYellow: "\x1b[33m",
|
||||
FgBlue: "\x1b[34m",
|
||||
FgMagenta: "\x1b[35m",
|
||||
FgCyan: "\x1b[36m",
|
||||
FgWhite: "\x1b[37m",
|
||||
|
||||
const BgBlack = "\x1b[40m"
|
||||
const BgRed = "\x1b[41m"
|
||||
const BgGreen = "\x1b[42m"
|
||||
const BgYellow = "\x1b[43m"
|
||||
const BgBlue = "\x1b[44m"
|
||||
const BgMagenta = "\x1b[45m"
|
||||
const BgCyan = "\x1b[46m"
|
||||
const BgWhite = "\x1b[47m"
|
||||
BgBlack: "\x1b[40m",
|
||||
BgRed: "\x1b[41m",
|
||||
BgGreen: "\x1b[42m",
|
||||
BgYellow: "\x1b[43m",
|
||||
BgBlue: "\x1b[44m",
|
||||
BgMagenta: "\x1b[45m",
|
||||
BgCyan: "\x1b[46m",
|
||||
BgWhite: "\x1b[47m"
|
||||
}
|
||||
|
||||
const maxFileSize = 500000000;
|
||||
|
||||
@ -122,20 +124,20 @@ export class LoggingBase {
|
||||
}
|
||||
|
||||
private async message(type: LoggingTypes, message: any[] | string, customColors?: string, caller?: { file: string, line: number }) {
|
||||
var consoleLogFormat = Reset;
|
||||
var consoleLogFormat = Colors.Reset;
|
||||
if (!customColors) {
|
||||
switch (type) {
|
||||
case LoggingTypes.Log:
|
||||
//m += FgWhite + BgBlack;
|
||||
break;
|
||||
case LoggingTypes.Error:
|
||||
consoleLogFormat += FgRed;//FgWhite + BgRed + FgWhite;
|
||||
consoleLogFormat += Colors.FgRed;//FgWhite + BgRed + FgWhite;
|
||||
break;
|
||||
case LoggingTypes.Debug:
|
||||
consoleLogFormat += FgCyan;
|
||||
consoleLogFormat += Colors.FgCyan;
|
||||
break;
|
||||
case LoggingTypes.Warning:
|
||||
consoleLogFormat += FgYellow;
|
||||
consoleLogFormat += Colors.FgYellow;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -159,7 +161,7 @@ export class LoggingBase {
|
||||
let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `;
|
||||
let message_lines = mb.split("\n").map(line => prefix + line);
|
||||
|
||||
if (this.config.console_out) message_lines.forEach(line => console.log(consoleLogFormat + line + Reset));
|
||||
if (this.config.console_out) message_lines.forEach(line => console.log(consoleLogFormat + line + Colors.Reset));
|
||||
|
||||
let m = message_lines.join("\n");
|
||||
let index = m.indexOf("\x1b");
|
||||
|
Loading…
Reference in New Issue
Block a user