UNPKG

1.89 kBTypeScriptView Raw
1import { LogEntry } from '../logger.js';
2import { Transform } from '../transform.js';
3import * as ansi from '@bevry/ansi';
4/** A mapping of log level numbers to their intended colours */
5interface LevelsToColorsMap {
6 [logLevelNumber: string]: ansi.ANSIApplier;
7}
8/** Configuration options for the Caterpillar Human Transform */
9export interface HumanOptions {
10 /** Use to override the default value of {@link Human.color} */
11 color?: boolean;
12 /** Use to override the default value of {@link Human.colors} */
13 colors?: LevelsToColorsMap;
14}
15/**
16 * Convert Logger entries into human readable format.
17 * @extends Transform
18 * @example
19 * ``` javascript
20 * import { Logger, Human } from 'caterpillar'
21 * const logger = new Logger()
22 * const human = new Human()
23 * logger.pipe(human).pipe(process.stdout)
24 * logger.log('info', 'some', {data: 'oh yeah'}, 42)
25 * ```
26 */
27export declare class Human extends Transform {
28 /** Whether or not to use colors? */
29 color: boolean;
30 /** Mapping of which log level numbers correspond to which colours */
31 colors: LevelsToColorsMap;
32 /** Create our instance and apply our configuration options. */
33 constructor(opts?: HumanOptions);
34 /** Get the color for the log level */
35 getColor(levelNumber: number): ansi.ANSIApplier | false;
36 /** Pad the left of some content if need be with the specified padding to make the content reach a certain size */
37 padLeft(padding: string, size: number, content: string | number): string;
38 /** Convert logger entry arguments into a human readable string */
39 formatArguments(args: any[]): string;
40 /** Convert a datetime into a human readable format */
41 formatDate(datetime: Date | number | string): string;
42 /** Convert a logger entry into a human readable format */
43 format(entry: LogEntry): string;
44}
45export default Human;
46//# sourceMappingURL=human.d.ts.map
\No newline at end of file