• Home
  • Extend
  • Extend user experience and behavior
  • Dynatrace OpenKit logging

Dynatrace OpenKit logging

There are two different ways to log with OpenKit:

  • Configure OpenKit to use the built-in console logger
  • Configure OpenKit to use a custom logger implementation

Logging via console logger

OpenKit includes a console logger. By default, any error or warning message is logged to stdout. When you set a log level, all log events with the same or higher prior levels are logged.

OpenKit uses the following log levels:

Log levelPriorityDescription
Debug0For debugging and development. Not recommended for production due to a high volume of log entries.
Info10General OpenKit flow.
Warning20Warnings encountered in OpenKit library, including API usage problems.
Error30Errors that cannot be handled by OpenKit.
java
OpenKit openKit = new DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .withLogLevel(LogLevel.DEBUG) // enable Debug, Info, Warning, and Error log events .build();
typescript
IOpenKit openKit = new DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .WithLogLevel(LogLevel.DEBUG) // enable Debug, Info, Warning, and Error log events .Build();
cpp
std::shared_pointer<openkit::IOpenKit> openKit = openkit::DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .withLogLevel(LogLevel::LOG_LEVEL_DEBUG) // enable Debug, Info, Warning, and Error log events .build();
c
struct OpenKitConfigurationHandle* configurationHandle = createOpenKitConfiguration(endpointURL, applicationID, deviceID); useDefaultLogLevelForConfiguration(configurationHandle, LOGLEVEL_DEBUG); struct OpenKitHandle* openKitHandle = createDynatraceOpenKit(configurationHandle);
javascript
const openKit = new OpenKitBuilder(endpointURL, applicationID, deviceID) .withLogLevel(LogLevel.Debug) // enable Debug, Info, Warning, and Error log events .build();

Logging via custom logger

You can also configure OpenKit with a custom logger implementation. Implement a custom logger to log OpenKit messages using the logging framework of your choice.

java
import com.dynatrace.openkit.api.Logger; class MyCustomLoggerImpl implements Logger { // implement interface methods } Logger customLogger = new MyCustomLoggerImpl(); OpenKit openKit = new DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .withLogger(customLogger) .build();
typescript
using Dynatrace.OpenKit.API.ILogger; class MyCustomLoggerImpl : ILogger { // implement interface methods } ILogger customLogger = new MyCustomLoggerImpl(); IOpenKit openKit = new DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .WithLogger(customLogger) .Build();
cpp
class MyCustomLoggerImpl : public openkit::ILogger { // implement interface methods }; std::shared_ptr<openkit::ILogger> customLogger = std::make_shared<MyCustomLoggerImpl>(); std::shared_pointer<openkit::IOpenKit> openKit = openkit::DynatraceOpenKitBuilder(endpointURL, applicationID, deviceID) .withLogger(customLogger) .build();
c
bool levelEnabledFunction(LOG_LEVEL level) { // return true if level is enabled, false otherwise } void logFunction(LOG_LEVEL level, const char* traceStatement) { // write trace statement } // create custom logger struct LoggerHandle* loggerHandle = createLogger(&levelEnabledFunction, &logFunction); // create OpenKit configuration and assign logger handle struct OpenKitConfigurationHandle* configurationHandle = createOpenKitConfiguration(endpointURL, applicationID, deviceID); useLoggerForConfiguration(configurationHandle, loggerHandle); struct OpenKitHandle* openKitHandle = createDynatraceOpenKit(configurationHandle);
javascript
class MyCustomLoggerFactory implements LoggerFactory { // implement interface methods } const customLogger = new MyCustomLoggerFactory(); const openKit = new OpenKitBuilder(endpointURL, applicationID, deviceID) .withLoggerFactory(customLogger) .build();