[Logs] How do I get a simplified logger result? #1747
-
Hi. I managed to read the examples, I also found a LogHandler, but it doesn't match the result of the LoggerProvider. Generallyi I would like to keep the fields from the "complex" logger, but at the same time I need the file name and the line. Can I get this somehow? #include "opentelemetry/exporters/ostream/log_record_exporter.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/simple_log_record_processor.h"
#include <memory>
namespace logs = opentelemetry::logs;
namespace sdklogs = opentelemetry::sdk::logs;
namespace logs_api = opentelemetry::logs;
namespace exporterlogs = opentelemetry::exporter::logs;
int main()
{
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(new exporterlogs::OStreamLogExporter(std::cout));
auto sdkProvider = std::shared_ptr<sdklogs::LoggerProvider>(new sdklogs::LoggerProvider());
sdkProvider->AddProcessor(std::unique_ptr<sdklogs::LogRecordProcessor>(
new sdklogs::SimpleLogProcessor(std::move(exporter))));
auto apiProvider = std::shared_ptr<logs_api::LoggerProvider>(sdkProvider);
auto provider = std::shared_ptr<logs_api::LoggerProvider>(apiProvider);
auto logger = provider->GetLogger("firstlog", "", "my lib", "12.32.2");
logger->Debug("I am the first log message.");
} I have something like this. It is also possible that I don't understand the premise of this logger, then I would ask for a reference to the documentation. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
These fields are coming from the logs data model. If you want to add file-name/line-number, you can pass them using attributes field. We may plan to create convenience macros on top of the existing API to implicitly add these fields, but at the moment Logging API/SDK is still experimental, and work in progress - https://github.com/open-telemetry/opentelemetry-cpp/milestone/18, and not recommended for production use.
These are two different things - LogHandler is part of opentelemetry-cpp internal logging, while LoggerProvider is what you need to use for instrumenting your application. |
Beta Was this translation helpful? Give feedback.
These fields are coming from the logs data model. If you want to add file-name/line-number, you can pass them using attributes field. We may plan to create convenience macros on top of the existing API to implicitly add these fields, but at the moment Logging API/SDK is still experimental, and work in progress - https://github.com/open-telemetry/opentelemetry-cpp/milestone/18, and not recommended for production use.
These are two different things - LogHandler is part of opentelemetry-cpp int…