Add a method to check if logger is enabled based on severity? #1945
Replies: 3 comments
-
Good point, many log library have functions to set and get log level, though it seems not be a part of specification. |
Beta Was this translation helpful? Give feedback.
-
The otel specification doesn't provide any logging API which can be directly called through instrumentation library, as indicated here -
So it ONLY defines
The get/set level are generally part of these language provided import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG) This is probably the reason why we don't have any get and set log levels as part of this In case of C++ language, the application developers may be using an existing logging framework (say)
If we want to support configuring log-level as part of otel-cpp, we can provide a similar convenience library/wrapper at api level with basic functions to emit logs, set/get level, something like:
I think it would be good idea to provide this convenience library/wrapper once our |
Beta Was this translation helpful? Give feedback.
-
I've seen that as of #2094 (comment) there is an (internal) |
Beta Was this translation helpful? Give feedback.
-
In the current log API in opentelemetry-cpp, like EmitLogRecord below,
LogRecord
is created and passed to processors directly. minSeverity should be checked in the beginning to avoid all the heavy operations like log information calculation and log record creation. I think the best thing is we provide a wrapper function likelogger::Enabled(severity)
as a fast pre-check before producing any log data. .NET has something similar here.https://github.com/open-telemetry/opentelemetry-cpp/blob/main/api/include/opentelemetry/logs/logger.h#L163
Beta Was this translation helpful? Give feedback.
All reactions