createLogger()
The createLogger()
function is used to instantiate a logger based on a given configuration. You can create console-based, file-based, or Upstash Redis-based loggers by specifying the type and any additional parameters relevant to that type.
Usage
Console Logger (Development)
const consoleLogger = createLogger({ type: 'CONSOLE', level: 'DEBUG' });
consoleLogger.info('App started');
File Logger (Structured Logs)
const fileLogger = createLogger({ type: 'FILE', dirPath: 'my-logs', level: 'WARN' });
fileLogger.warn({ message: 'Low disk space', destinationPath: 'system', type: 'WORKFLOW' });
Upstash Logger (Remote Log Drain)
const upstashLogger = createLogger({
type: 'UPSTASH',
url: process.env.UPSTASH_URL!,
token: process.env.UPSTASH_TOKEN!,
level: 'INFO',
key: 'production-logs',
});
await upstashLogger.info({ message: 'User signed in', destinationPath: 'auth', type: 'AGENT', runId: 'run_123' });
Parameters
type:
0
Specifies the logger implementation to create.
level?:
LogLevel
Minimum severity level of logs to record. One of DEBUG, INFO, WARN, or ERROR.
dirPath?:
string
For FILE type only. Directory path where log files are stored (default: "logs").
url?:
string
For UPSTASH type only. Upstash Redis endpoint URL used for storing logs.
token?:
string
For UPSTASH type only. Upstash Redis access token.
key?:
string
For UPSTASH type only. Redis list key under which logs are stored.