UNPKG

2.95 kBTypeScriptView Raw
1import * as Rx from 'rxjs';
2import { Command, CommandIdentifier } from './command';
3export declare class Logger {
4 private readonly hide;
5 private readonly raw;
6 private readonly prefixFormat?;
7 private readonly commandLength;
8 private readonly dateFormatter;
9 private chalk;
10 /**
11 * How many characters should a prefix have.
12 * Prefixes shorter than this will be padded with spaces to the right.
13 */
14 private prefixLength;
15 /**
16 * Last character emitted, and from which command.
17 * If `undefined`, then nothing has been logged yet.
18 */
19 private lastWrite?;
20 /**
21 * Observable that emits when there's been output logged.
22 * If `command` is is `undefined`, then the log is for a global event.
23 */
24 readonly output: Rx.Subject<{
25 command: Command | undefined;
26 text: string;
27 }>;
28 constructor({ hide, prefixFormat, commandLength, raw, timestampFormat, }: {
29 /**
30 * Which commands should have their output hidden.
31 */
32 hide?: CommandIdentifier[];
33 /**
34 * Whether output should be formatted to include prefixes and whether "event" logs will be
35 * logged.
36 */
37 raw?: boolean;
38 /**
39 * The prefix format to use when logging a command's output.
40 * Defaults to the command's index.
41 */
42 prefixFormat?: string;
43 /**
44 * How many characters should a prefix have at most when the format is `command`.
45 */
46 commandLength?: number;
47 /**
48 * Date format used when logging date/time.
49 * @see https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
50 */
51 timestampFormat?: string;
52 });
53 /**
54 * Toggles colors on/off globally.
55 */
56 toggleColors(on: boolean): void;
57 private shortenText;
58 private getPrefixesFor;
59 getPrefixContent(command: Command): {
60 type: 'default' | 'template';
61 value: string;
62 } | undefined;
63 getPrefix(command: Command): string;
64 setPrefixLength(length: number): void;
65 colorText(command: Command, text: string): string;
66 /**
67 * Logs an event for a command (e.g. start, stop).
68 *
69 * If raw mode is on, then nothing is logged.
70 */
71 logCommandEvent(text: string, command: Command): void;
72 logCommandText(text: string, command: Command): void;
73 /**
74 * Logs a global event (e.g. sending signals to processes).
75 *
76 * If raw mode is on, then nothing is logged.
77 */
78 logGlobalEvent(text: string): void;
79 /**
80 * Logs a table from an input object array, like `console.table`.
81 *
82 * Each row is a single input item, and they are presented in the input order.
83 */
84 logTable(tableContents: Record<string, unknown>[]): void;
85 log(prefix: string, text: string, command?: Command): void;
86 emit(command: Command | undefined, text: string): void;
87}