exporting colors

This commit is contained in:
Fabian Stamm
2018-09-01 12:28:15 +02:00
parent 6bf59ede32
commit d7242f722a
4 changed files with 86 additions and 57 deletions

25
out/index.d.ts vendored
View File

@ -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;

View File

@ -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