MCPcopy Create free account
hub / github.com/code-pushup/cli / Logger

Class Logger

packages/utils/src/lib/logger.ts:36–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 * Use {@link logger} singleton.
35 */
36export class Logger {
37 #isVerbose = isEnvVarEnabled('CP_VERBOSE');
38 #isCI = isEnvVarEnabled('CI');
39 #ciPlatform: CiPlatform | undefined = isEnvVarEnabled('GITHUB_ACTIONS')
40 ? 'GitHub'
41 : isEnvVarEnabled('GITLAB_CI')
42 ? 'GitLab'
43 : undefined;
44 #groupColor: GroupColor | undefined;
45
46 #groupsCount = 0;
47 #activeSpinner: Ora | undefined;
48 #activeSpinnerLogs: string[] = [];
49 #endsWithBlankLine = false;
50
51 #groupSymbols = {
52 start: '❯',
53 middle: '│',
54 end: '└',
55 };
56
57 #sigintListener = () => {
58 if (this.#activeSpinner != null) {
59 const text = `${this.#activeSpinner.text} ${ansis.red.bold('[SIGINT]')}`;
60 if (this.#groupColor) {
61 this.#activeSpinner.stopAndPersist({
62 text,
63 symbol: this.#colorize(this.#groupSymbols.end, this.#groupColor),
64 });
65 this.#groupColor = undefined;
66 } else {
67 this.#activeSpinner.fail(text);
68 }
69 this.#activeSpinner = undefined;
70 }
71 this.newline();
72 this.error(ansis.bold('Cancelled by SIGINT'));
73 // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
74 process.exit(SIGNAL_EXIT_CODES().SIGINT);
75 };
76
77 /**
78 * Logs an error to the console (red).
79 *
80 * Automatically adapts to logger state if called within {@link task}, {@link group}, etc.
81 *
82 * @example
83 * logger.error('Config file is invalid');
84 *
85 * @param message Error text
86 * @param options Additional options
87 */
88 error(message: string, options?: LogOptions): void {
89 this.#log(message, 'red', options);
90 }
91
92 /**
93 * Logs a warning to the console (yellow).

Callers

nothing calls this directly

Calls 5

#colorizeMethod · 0.95
newlineMethod · 0.95
errorMethod · 0.95
isEnvVarEnabledFunction · 0.85
SIGNAL_EXIT_CODESFunction · 0.85

Tested by

no test coverage detected