If you have instrumented with another logging library, it could be useful to expose a log method that takes LogLevel as a parameter to ease in mapping from another logging library to DatadogLogger.
Current State
Currently, you have to map the other logging library levels to a DD SDK method:
final logger = DatadogSdk.instance.logs?.createLogger(DatadogLoggerConfiguration());
// [LogRecord] from `logging` package
final LogRecord record = LogRecord(Level.INFO, 'message', 'LoggerName')
final logFn = switch (record.level) {
Level.SHOUT => logger?.error,
Level.SEVERE => logger?.error,
Level.WARNING => logger?.warn,
Level.INFO => logger?.info,
Level.CONFIG => logger?.info,
_ => logger?.debug,
};
logFn?.call(record.message, ...);
Here, the logFn is typed, but .call(...) signature is dynamic.
Proposed solution
Proposed API
final logger = DatadogSdk.instance.logs?.createLogger(DatadogLoggerConfiguration());
// [LogRecord] from `logging` package
final LogRecord record = LogRecord(Level.INFO, 'message', 'LoggerName')
final level = switch (record.level) {
Level.SHOUT => LogLevel.emergency,
Level.SEVERE => LogLevel.error,
Level.WARNING => LogLevel.warning,
Level.INFO => LogLevel.info,
Level.CONFIG => LogLevel.notice,
_ => LogLevel.debug,
};
logger?.log(level, message, ...)
Other relevant information
Either way you're still mapping something. The main benefit is that instead of call, which is dynamically typed, the log API would be typed.
Opened a PR in case this makes sense & is something you want to do for the API. No worries if it isn't what you're looking for! Just something I noticed while migrating from datadog_flutter.
Feature description
Use Case
If you have instrumented with another logging library, it could be useful to expose a
log
method that takesLogLevel
as a parameter to ease in mapping from another logging library to DatadogLogger.Current State
Currently, you have to map the other logging library levels to a DD SDK method:
Here, the
logFn
is typed, but.call(...)
signature isdynamic
.Proposed solution
Proposed API
Other relevant information
Either way you're still mapping something. The main benefit is that instead of
call
, which is dynamically typed, thelog
API would be typed.