UNPKG

2.48 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 prefixLength;
8 private readonly timestampFormat;
9 /**
10 * Last character emitted.
11 * If `undefined`, then nothing has been logged yet.
12 */
13 private lastChar?;
14 /**
15 * Observable that emits when there's been output logged.
16 * If `command` is is `undefined`, then the log is for a global event.
17 */
18 readonly output: Rx.Subject<{
19 command: Command | undefined;
20 text: string;
21 }>;
22 constructor({ hide, prefixFormat, prefixLength, raw, timestampFormat, }: {
23 /**
24 * Which command(s) should have their output hidden.
25 */
26 hide?: CommandIdentifier | CommandIdentifier[];
27 /**
28 * Whether output should be formatted to include prefixes and whether "event" logs will be
29 * logged.
30 */
31 raw?: boolean;
32 /**
33 * The prefix format to use when logging a command's output.
34 * Defaults to the command's index.
35 */
36 prefixFormat?: string;
37 /**
38 * How many characters should a prefix have at most, used when the prefix format is `command`.
39 */
40 prefixLength?: number;
41 /**
42 * Date format used when logging date/time.
43 * @see https://date-fns.org/v2.0.1/docs/format
44 */
45 timestampFormat?: string;
46 });
47 private shortenText;
48 private getPrefixesFor;
49 getPrefix(command: Command): string;
50 colorText(command: Command, text: string): string;
51 /**
52 * Logs an event for a command (e.g. start, stop).
53 *
54 * If raw mode is on, then nothing is logged.
55 */
56 logCommandEvent(text: string, command: Command): void;
57 logCommandText(text: string, command: Command): void;
58 /**
59 * Logs a global event (e.g. sending signals to processes).
60 *
61 * If raw mode is on, then nothing is logged.
62 */
63 logGlobalEvent(text: string): void;
64 /**
65 * Logs a table from an input object array, like `console.table`.
66 *
67 * Each row is a single input item, and they are presented in the input order.
68 */
69 logTable(tableContents: Record<string, unknown>[]): void;
70 log(prefix: string, text: string, command?: Command): void;
71 emit(command: Command | undefined, text: string): void;
72}