chocolog
Version:
A highlighted android-style logger
247 lines (246 loc) • 7.5 kB
TypeScript
import { Chalk } from "chalk";
import { HlLanguage, Sheet } from "emphasize";
import StackTrace from "stack-trace";
import { TypeColors } from "./colordefine";
import { HlTheme } from "./hlthemes";
import { LogLv, LogLvStatic } from "./loglv";
import TsMap from "./tsmap";
export declare class ChocoLog {
/**
* Default theme
*
* Used in text content
*/
protected readonly defaultTheme: Chalk & {
supportsColor: import("chalk").ColorSupport;
};
protected readonly width: number;
protected readonly headerSize: number;
protected readonly timestamp: string;
protected static defaultLevel: LogLv;
/**
* Default name of header
*/
name: string;
/**
* Use AM/PM instead of 24-hours?
*/
use12Hour: boolean;
/**
* Min header size
*/
minHeaderSize: number;
/**
* Log Levels defines
*/
readonly levels: import("../types/deepreadonly").DeepReadonlyObject<{
[x: number]: string;
ALL: LogLv.ALL;
VERBOSE: LogLv.VERBOSE;
DEBUG: LogLv.DEBUG;
INFO: LogLv.INFO;
WARN: LogLv.WARN;
ERROR: LogLv.ERROR;
ASSERT: LogLv.ASSERT;
SILENT: LogLv.SILENT;
}>;
/**
* Current log level
*/
protected logLevel: LogLv;
/**
* Code theme store
*/
protected codeStyle: Sheet;
/**
* General colors (all used to type)
*/
protected generalColors: {
back: string;
backSub: string;
backInfo: string;
text: string;
};
protected typedColors: TypeColors;
protected middleSize: number;
protected subpadSize: number;
protected cwd: string;
protected sourceMap: Map<string, TsMap>;
constructor(name: string);
/**
* Prints *debug* log. (Loglevel 2)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
d(title: unknown, ...desc: Array<unknown>): string;
/**
* Prints *verbose* log. (Loglevel 1)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
v(title: unknown, ...desc: Array<unknown>): string;
/**
* Prints *info* log. (Loglevel 3)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
i(title: unknown, ...desc: Array<unknown>): string;
/**
* Prints *warn* log. (Loglevel 4)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
w(title: unknown, ...desc: Array<unknown>): string;
/**
* Prints *error* log. (Loglevel 5)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
e(title: unknown, ...desc: Array<unknown>): null;
/**
* ☠ (Loglevel **6**)
* @param title Title of logger. If none, this is used to content
* @param desc Contents to print
*/
wtf(title: unknown, ...desc: Array<unknown>): string;
/**
* Log programming code with formatter
*
* used `highlight.js` wrapper `emphasize`
* @param codeContent Code string to print (css, js, etc...)
* @param title Title of log, not need at normal.
* @param lang The language of the code. If non-specic, Library will auto detect
*/
code(codeContent: string, title?: string | number | boolean, lang?: HlLanguage): string;
/**
* Set `highlight.js` theme to console
*
* Almost check [highlight.js github](https://github.com/highlightjs/highlight.js/tree/master/src/styles)
*
* Scss not supported.
* @param css css text
*/
setCssTheme(css: string): {
[x: string]: Chalk;
};
/**
* Set background & text color
*
* Auto modify type colors.
* @param background Background of terminal
* @param textColor The default text color of terminal
*/
setBgTheme(background: string, textColor?: string): void;
/**
* Apply Highlight.js style from github
*
* https://github.com/highlightjs/highlight.js
* @param type Highlight.js style
*/
setStyleGithub(type: HlTheme): Promise<void>;
/**
* Get current loglevel
*
* Let's see [loglevel doc](https://www.npmjs.com/package/loglevel)
*/
getLevel(): LogLv;
/**
* Set loglevel to `level`
*
* Let's see [loglevel doc](https://www.npmjs.com/package/loglevel)
* @param level The minimum level to want logging
*/
setLevel(level: LogLv | keyof typeof LogLvStatic): void;
/**
* Set default loglevel to `level`
*
* This doesn't applies copied object but will be copyed object
* @param level The minimum level to want logging
*/
setDefaultLevel(level: LogLv | keyof typeof LogLvStatic): void;
/**
* Enable all log messages
*
* Same as `setLevel(cLog.levels.ALL)`
*
* See [loglevel doc](https://www.npmjs.com/package/loglevel)
*/
enableAll(): void;
/**
* Disable all log messages
*
* Same as `setLevel(cLog.levels.SLIENT)`
*
* See [loglevel doc](https://www.npmjs.com/package/loglevel)
*/
disableAll(): void;
/**
* Clones this Log class and returns it
* @param name New logger's name
*/
getLogger(name: string): ChocoLog;
/**
* Let's trace error beauty
* @param err Error
*/
protected errorToString(err: Error): string;
/**
* Decode LogLv to number
* @param level LogLv
*/
protected decodeLogLevel(level: LogLv | keyof typeof LogLvStatic): LogLv | -1;
/**
* Something type to string (Maybe recursive)
* @param obj any object or number or etc..
*/
protected toStr(obj: unknown, beauty?: boolean): string;
protected fallbackParam(title: unknown, desc: Array<unknown>): [string, string];
protected mapToObject<V>(map: Map<unknown, V>): {
[x: string]: V;
};
protected encodeCaller(called: Called): string;
protected caller(): Called;
protected filterStack(stacktrace: StackTrace.StackFrame[]): StackTrace.StackFrame[];
protected decodeStack(query: StackTrace.StackFrame): Called;
protected beautyCode(code: string, type?: HlLanguage): string;
protected beautyJSON(json: string): string;
/**
* Mix A and B, P P A P
* @param color1 C2lor 1
* @param color2 Color 2
*/
protected mixColor(color1: [string, number?], color2: [string, number?]): string;
/**
* Print Content with split & color & beauty
*
* This can't be optimized.
* @param header
* @param content
* @param options
*/
protected printSimple(header: string, content: string, options: {
tagName: string;
colorTheme: string;
fontColor: string;
level: LogLv;
}): string;
/**
* Get Header of logger
*
* [Timestamp] [Header] [typeInfo]
* @param header To print header
* @param typeStr To print type
*/
protected getHeader(header: string, timeTheme: Chalk): string;
protected getMiddle(style: Chalk, typeStr: string): string;
protected getFooter(encodedCaller: string): string;
protected write(str: string): string;
}
interface Called {
fileName: string;
funcName: string;
line: number;
column: number;
}
declare const chocolog: ChocoLog;
export default chocolog;