docutils-ts
Version:
Port of the Python Docutils library to TypeScript
51 lines (50 loc) • 1.55 kB
JavaScript
export class Logger {
constructor(options = {}) {
this.options = options;
}
child(options) {
return new Logger(options);
}
// Implement log methods
debug(message, ...meta) {
if (typeof console !== 'undefined' && this.shouldLog('debug')) {
console.warn(`[DEBUG] ${message}`, ...meta);
}
return this;
}
silly(message, ...meta) {
if (typeof console !== 'undefined' && this.shouldLog('silly')) {
console.warn(`[SILLY] ${message}`, ...meta);
}
return this;
}
info(message, ...meta) {
if (typeof console !== 'undefined' && this.shouldLog('info')) {
console.warn(`[INFO] ${message}`, ...meta);
}
return this;
}
warn(message, ...meta) {
if (typeof console !== 'undefined' && this.shouldLog('warn')) {
console.warn(`[WARN] ${message}`, ...meta);
}
return this;
}
error(message, ...meta) {
if (typeof console !== 'undefined' && this.shouldLog('error')) {
console.error(`[ERROR] ${message}`, ...meta);
}
return this;
}
// Helper to determine if we should log based on level
shouldLog(level) {
// Implement any filtering logic here
return true;
}
}
// Factory function that mimics winston's createLogger
export function createLogger(options) {
return new Logger(options);
}
export const logger = createLogger();
export const child = () => { throw new Error('redo logger'); };