This document explains how to get started with syslogger APIs.
In C
BUILD.gn dependency
//zircon/public/lib/syslog
Initialization
Logger can only be initialized once.
Basic initialization
#include <lib/syslog/global.h>
int main(int argc, char** argv) {
fx_log_init();
}
Initialization with tags
#include <lib/syslog/global.h>
int main(int argc, char** argv) {
fx_logger_config_t config = {.min_severity = FX_LOG_INFO,
.console_fd = -1,
.log_service_channel = ZX_HANDLE_INVALID,
.tags = (const char * []) {"gtag", "gtag2"},
.num_tags = 2};
fx_log_init_with_config(&config);
}
Log messages
FX_LOGF(INFO, "tag", "my msg: %d", 10);
FX_LOG(INFO, "tag", "my msg");
FX_LOGF(INFO, NULL, "my msg: %d", 10);
Reference
In C++
BUILD.gn dependency
//src/lib/syslog/cpp
sandboxing dependency
{
"sandbox": {
"services": [
"fuchsia.logger.LogSink"
]
}
}
Initialization
Logger can only be initialized once.
Basic initialization
#include "src/lib/syslog/cpp/logger.h"
int main(int argc, char** argv) {
syslog::InitLogger();
}
Initialization with tags
#include "src/lib/syslog/cpp/logger.h"
int main(int argc, char** argv) {
syslog::InitLogger({"tag1", "tag2"});
}
Initialization using command line
#include "src/lib/fsl/syslogger/init.h"
#include "src/lib/fxl/command_line.h"
int main(int argc, char** argv) {
auto command_line = fxl::CommandLineFromArgcArgv(argc, argv);
fsl::InitLoggerFromCommandLine(command_line, {"my_program"});
}
Log messages
FX_LOGS(INFO) << "my message";
FX_LOGST(INFO, "tag") << "my message";
Reference
C++ APIs
FSL initialization API
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.