MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / Logger

Class Logger

packages/baseai/src/utils/logger.ts:21–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19];
20
21class Logger {
22 private static instance: Logger;
23 private config: LoggerConfig;
24
25 private constructor(config: LoggerConfig) {
26 this.config = config;
27 }
28
29 public static async initialize(): Promise<Logger> {
30 if (!Logger.instance) {
31 const baseAIConfig = await loadConfig();
32 Logger.instance = new Logger(baseAIConfig.log);
33 }
34 return Logger.instance;
35 }
36
37 private formatValue(value: unknown): string {
38 if (typeof value === 'object' && value !== null) {
39 return util.inspect(value, { colors: true, depth: null });
40 }
41 if (typeof value === 'string') {
42 return chalk.green(`"${value}"`);
43 }
44 if (typeof value === 'number') {
45 return chalk.yellow(value.toString());
46 }
47 if (typeof value === 'boolean') {
48 return chalk.cyan(value.toString());
49 }
50 return String(value);
51 }
52
53 private isSensitiveData(key: string): boolean {
54 return sensitiveWords.some(word => key.toLowerCase().includes(word));
55 }
56
57 private formatAndRedactSensitiveData(
58 value: unknown,
59 isSensitive: boolean
60 ): string {
61 return isSensitive && !this.config.logSensitiveData
62 ? chalk.red('======REDACTED======')
63 : this.formatValue(value);
64 }
65
66 private isCategoryEnabled(category: LogCategories): boolean {
67 const parts = category.split('.');
68 let partialCategory = '';
69
70 for (const part of parts) {
71 partialCategory += (partialCategory ? '.' : '') + part;
72 if (partialCategory in this.config) {
73 const value = this.config[partialCategory as LogCategories];
74 if (typeof value === 'boolean') {
75 if (value === false) {
76 // console.log(
77 // `Category ${category} is false due to ${partialCategory}`
78 // );

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected