mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
Resolves merge conflicts: - apps/server/src/routes/terminal/common.ts: Keep randomBytes import, use @automaker/utils for createLogger - apps/ui/eslint.config.mjs: Use main's explicit globals list with XMLHttpRequest and MediaQueryListEvent additions - apps/ui/src/components/views/terminal-view.tsx: Keep our terminal improvements (killAllSessions, beforeunload, better error handling) - apps/ui/src/config/terminal-themes.ts: Keep our search highlight colors for all themes - apps/ui/src/store/app-store.ts: Keep our terminal settings persistence improvements (merge function) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
75 lines
1.6 KiB
TypeScript
75 lines
1.6 KiB
TypeScript
/**
|
|
* Simple logger utility with log levels
|
|
* Configure via LOG_LEVEL environment variable: error, warn, info, debug
|
|
* Defaults to 'info' if not set
|
|
*/
|
|
|
|
export enum LogLevel {
|
|
ERROR = 0,
|
|
WARN = 1,
|
|
INFO = 2,
|
|
DEBUG = 3,
|
|
}
|
|
|
|
const LOG_LEVEL_NAMES: Record<string, LogLevel> = {
|
|
error: LogLevel.ERROR,
|
|
warn: LogLevel.WARN,
|
|
info: LogLevel.INFO,
|
|
debug: LogLevel.DEBUG,
|
|
};
|
|
|
|
let currentLogLevel: LogLevel = LogLevel.INFO;
|
|
|
|
// Initialize log level from environment variable
|
|
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase();
|
|
if (envLogLevel && LOG_LEVEL_NAMES[envLogLevel] !== undefined) {
|
|
currentLogLevel = LOG_LEVEL_NAMES[envLogLevel];
|
|
}
|
|
|
|
/**
|
|
* Create a logger instance with a context prefix
|
|
*/
|
|
export function createLogger(context: string) {
|
|
const prefix = `[${context}]`;
|
|
|
|
return {
|
|
error: (...args: unknown[]): void => {
|
|
if (currentLogLevel >= LogLevel.ERROR) {
|
|
console.error(prefix, ...args);
|
|
}
|
|
},
|
|
|
|
warn: (...args: unknown[]): void => {
|
|
if (currentLogLevel >= LogLevel.WARN) {
|
|
console.warn(prefix, ...args);
|
|
}
|
|
},
|
|
|
|
info: (...args: unknown[]): void => {
|
|
if (currentLogLevel >= LogLevel.INFO) {
|
|
console.log(prefix, ...args);
|
|
}
|
|
},
|
|
|
|
debug: (...args: unknown[]): void => {
|
|
if (currentLogLevel >= LogLevel.DEBUG) {
|
|
console.log(prefix, '[DEBUG]', ...args);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get the current log level
|
|
*/
|
|
export function getLogLevel(): LogLevel {
|
|
return currentLogLevel;
|
|
}
|
|
|
|
/**
|
|
* Set the log level programmatically (useful for testing)
|
|
*/
|
|
export function setLogLevel(level: LogLevel): void {
|
|
currentLogLevel = level;
|
|
}
|