a transport defines where log entries are sent. implement this interface to create custom log destinations.
class HttpTransport implements Transport { constructor(private url: string) {} async log(entry: LogEntry): Promise<void> { await fetch(this.url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(entry) }); }} Copy
class HttpTransport implements Transport { constructor(private url: string) {} async log(entry: LogEntry): Promise<void> { await fetch(this.url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(entry) }); }}
class DatabaseTransport implements Transport { async log(entry: LogEntry): Promise<void> { await db.logs.insert({ level: entry.level, message: entry.message, timestamp: entry.timestamp, scope: entry.scope.join('/'), metadata: entry.metadata }); }} Copy
class DatabaseTransport implements Transport { async log(entry: LogEntry): Promise<void> { await db.logs.insert({ level: entry.level, message: entry.message, timestamp: entry.timestamp, scope: entry.scope.join('/'), metadata: entry.metadata }); }}
process a log entry. can be synchronous or asynchronous. if this method throws an error or returns a rejected promise, the error will be caught and logged to console.error.
the log entry to process
a transport defines where log entries are sent. implement this interface to create custom log destinations.
Example: custom http transport
Example: custom database transport