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" /> /// <reference types="node" />
import { EventEmitter } from "events"; 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 { export interface LoggingBaseOptions {
logfile: string; logfile: string;
errorfile: string; errorfile: string;

View File

@ -5,29 +5,31 @@ const fs = require("fs");
const events_1 = require("events"); const events_1 = require("events");
const path = require("path"); const path = require("path");
const lock_1 = require("./lock"); const lock_1 = require("./lock");
const Reset = "\x1b[0m"; exports.Colors = {
const Bright = "\x1b[1m"; Reset: "\x1b[0m",
const Dim = "\x1b[2m"; Bright: "\x1b[1m",
const Underscore = "\x1b[4m"; Dim: "\x1b[2m",
const Blink = "\x1b[5m"; Underscore: "\x1b[4m",
const Reverse = "\x1b[7m"; Blink: "\x1b[5m",
const Hidden = "\x1b[8m"; Reverse: "\x1b[7m",
const FgBlack = "\x1b[30m"; Hidden: "\x1b[8m",
const FgRed = "\x1b[31m"; FgBlack: "\x1b[30m",
const FgGreen = "\x1b[32m"; FgRed: "\x1b[31m",
const FgYellow = "\x1b[33m"; FgGreen: "\x1b[32m",
const FgBlue = "\x1b[34m"; FgYellow: "\x1b[33m",
const FgMagenta = "\x1b[35m"; FgBlue: "\x1b[34m",
const FgCyan = "\x1b[36m"; FgMagenta: "\x1b[35m",
const FgWhite = "\x1b[37m"; FgCyan: "\x1b[36m",
const BgBlack = "\x1b[40m"; FgWhite: "\x1b[37m",
const BgRed = "\x1b[41m"; BgBlack: "\x1b[40m",
const BgGreen = "\x1b[42m"; BgRed: "\x1b[41m",
const BgYellow = "\x1b[43m"; BgGreen: "\x1b[42m",
const BgBlue = "\x1b[44m"; BgYellow: "\x1b[43m",
const BgMagenta = "\x1b[45m"; BgBlue: "\x1b[44m",
const BgCyan = "\x1b[46m"; BgMagenta: "\x1b[45m",
const BgWhite = "\x1b[47m"; BgCyan: "\x1b[46m",
BgWhite: "\x1b[47m"
};
const maxFileSize = 500000000; const maxFileSize = 500000000;
const OriginalErrorStackFunction = Error.prototype.prepareStackTrace; const OriginalErrorStackFunction = Error.prototype.prepareStackTrace;
class LoggingBase { class LoggingBase {
@ -95,20 +97,20 @@ class LoggingBase {
this.message(LoggingTypes.Error, message); this.message(LoggingTypes.Error, message);
} }
async message(type, message, customColors, caller) { async message(type, message, customColors, caller) {
var consoleLogFormat = Reset; var consoleLogFormat = exports.Colors.Reset;
if (!customColors) { if (!customColors) {
switch (type) { switch (type) {
case LoggingTypes.Log: case LoggingTypes.Log:
//m += FgWhite + BgBlack; //m += FgWhite + BgBlack;
break; break;
case LoggingTypes.Error: case LoggingTypes.Error:
consoleLogFormat += FgRed; //FgWhite + BgRed + FgWhite; consoleLogFormat += exports.Colors.FgRed; //FgWhite + BgRed + FgWhite;
break; break;
case LoggingTypes.Debug: case LoggingTypes.Debug:
consoleLogFormat += FgCyan; consoleLogFormat += exports.Colors.FgCyan;
break; break;
case LoggingTypes.Warning: case LoggingTypes.Warning:
consoleLogFormat += FgYellow; consoleLogFormat += exports.Colors.FgYellow;
break; break;
} }
} }
@ -136,7 +138,7 @@ class LoggingBase {
let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `; let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `;
let message_lines = mb.split("\n").map(line => prefix + line); let message_lines = mb.split("\n").map(line => prefix + line);
if (this.config.console_out) 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 m = message_lines.join("\n");
let index = m.indexOf("\x1b"); let index = m.indexOf("\x1b");
while (index >= 0) { while (index >= 0) {

File diff suppressed because one or more lines are too long

View File

@ -4,31 +4,33 @@ import { EventEmitter } from "events";
import * as path from "path"; import * as path from "path";
import Lock from "./lock"; import Lock from "./lock";
const Reset = "\x1b[0m" export const Colors = {
const Bright = "\x1b[1m" Reset: "\x1b[0m",
const Dim = "\x1b[2m" Bright: "\x1b[1m",
const Underscore = "\x1b[4m" Dim: "\x1b[2m",
const Blink = "\x1b[5m" Underscore: "\x1b[4m",
const Reverse = "\x1b[7m" Blink: "\x1b[5m",
const Hidden = "\x1b[8m" Reverse: "\x1b[7m",
Hidden: "\x1b[8m",
const FgBlack = "\x1b[30m" FgBlack: "\x1b[30m",
const FgRed = "\x1b[31m" FgRed: "\x1b[31m",
const FgGreen = "\x1b[32m" FgGreen: "\x1b[32m",
const FgYellow = "\x1b[33m" FgYellow: "\x1b[33m",
const FgBlue = "\x1b[34m" FgBlue: "\x1b[34m",
const FgMagenta = "\x1b[35m" FgMagenta: "\x1b[35m",
const FgCyan = "\x1b[36m" FgCyan: "\x1b[36m",
const FgWhite = "\x1b[37m" FgWhite: "\x1b[37m",
const BgBlack = "\x1b[40m" BgBlack: "\x1b[40m",
const BgRed = "\x1b[41m" BgRed: "\x1b[41m",
const BgGreen = "\x1b[42m" BgGreen: "\x1b[42m",
const BgYellow = "\x1b[43m" BgYellow: "\x1b[43m",
const BgBlue = "\x1b[44m" BgBlue: "\x1b[44m",
const BgMagenta = "\x1b[45m" BgMagenta: "\x1b[45m",
const BgCyan = "\x1b[46m" BgCyan: "\x1b[46m",
const BgWhite = "\x1b[47m" BgWhite: "\x1b[47m"
}
const maxFileSize = 500000000; 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 }) { private async message(type: LoggingTypes, message: any[] | string, customColors?: string, caller?: { file: string, line: number }) {
var consoleLogFormat = Reset; var consoleLogFormat = Colors.Reset;
if (!customColors) { if (!customColors) {
switch (type) { switch (type) {
case LoggingTypes.Log: case LoggingTypes.Log:
//m += FgWhite + BgBlack; //m += FgWhite + BgBlack;
break; break;
case LoggingTypes.Error: case LoggingTypes.Error:
consoleLogFormat += FgRed;//FgWhite + BgRed + FgWhite; consoleLogFormat += Colors.FgRed;//FgWhite + BgRed + FgWhite;
break; break;
case LoggingTypes.Debug: case LoggingTypes.Debug:
consoleLogFormat += FgCyan; consoleLogFormat += Colors.FgCyan;
break; break;
case LoggingTypes.Warning: case LoggingTypes.Warning:
consoleLogFormat += FgYellow; consoleLogFormat += Colors.FgYellow;
break; break;
} }
} else { } else {
@ -159,7 +161,7 @@ export class LoggingBase {
let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `; let prefix = `[${LoggingTypes[type]}][${file.file}:${file.line}][${date}]: `;
let message_lines = mb.split("\n").map(line => prefix + line); 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 m = message_lines.join("\n");
let index = m.indexOf("\x1b"); let index = m.indexOf("\x1b");