createLogger (utils/logger.ts)

deepbot · src/shared/utils/logger.ts · typescript · MIT
infra, tag:knn-classified

Unified logger with console and file support for TypeScript projects.

// Source: https://github.com/kevinluosl/deepbot | License: MIT | Copyright 2024 Kevin Luo
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * 统一的日志工具
 */

import { writeFileSync, appendFileSync, existsSync, mkdirSync } from 'fs';
import { join } from 'path';
import { expandUserPath } from './path-utils';

export enum LogLevel {
  DEBUG = 0,
  INFO = 1,
  WARN = 2,
  ERROR = 3,
}

class Logger {
  private level: LogLevel = LogLevel.INFO;
  private module: string;
  private enableFileLogging: boolean = false; // 默认不启用文件日志
  private static logDir: string = expandUserPath('~/.deepbot/logs');
  private static logFile: string = join(Logger.logDir, 'deepbot.log');
  private static initialized: boolean = false;

  constructor(module: string, enableFileLogging: boolean = false)

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key