This document explains how to get started with syslogger APIs.
Ensure that your component has the required capabilities to log by including the following in your component manifest:
{ include: [ "syslog/client.shard.cml" ], ... }
The syslog library will fallback to stderr if the LogSink connection fails.
The global logger is lazily instantiated on the first use of the API. The default configuration for the global logger is:
fuchsia.logger.LogSinkfuchsia_logging::LogSeverity::Info//sdk/lib/syslog/cpp
#include <lib/syslog/cpp/macros.h> FX_LOGS(INFO) << "my message"; FX_LOGST(INFO, "tag") << "my message";
By default, the process name is used as the tag, but this can be changed by calling fuchsia_logging::SetTags.
#include <lib/syslog/cpp/log_settings.h> int main(int argc, char** argv) { fuchsia_logging::SetTags({"tag1", "tag2"}); }
#include "<lib/syslog/cpp/log_settings.h> int main(int argc, char** argv) { fuchsia_logging::LogSettings settings = { .min_log_level = fuchsia_logging::LOG_ERROR, }; fuchsia_logging::SetLogSettings(settings, {"tag1", "tag2"}); }
#include "src/lib/fxl/command_line.h" #include "src/lib/fxl/log_settings_command_line.h" int main(int argc, char** argv) { auto command_line = fxl::CommandLineFromArgcArgv(argc, argv); fxl::SetLogSettingsFromCommandLine(command_line, {"my_program"}); }
No initialization is required for using the default configuration of syslog. If you would like your test suite to change the configuration based on command line arguments (e.g. --verbose), use:
//src/lib/fxl/test:gtest_main