@papabravocorp/pluggable-logger
Version:
A pluggable logger for Node.js that writes structured logs to local file systems, Azure ADLS, or custom storage backends.
16 lines (14 loc) • 589 B
text/typescript
// Local Disk Implemntation
import { StorageProvider, LogEntry } from '../storage';
import { appendFile, mkdir } from 'fs/promises';
import { join, dirname } from 'path';
export class LocalFsProvider implements StorageProvider {
constructor(private readonly baseDir: string) {}
async write(entry: LogEntry): Promise<void> {
const date = entry.timestamp.slice(0, 10);
const filePath = join(this.baseDir, `${date}.log`);
await mkdir(dirname(filePath), { recursive: true });
const line = JSON.stringify(entry) + '\n';
await appendFile(filePath, line, 'utf8');
}
}