| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // |
| // Entry points used by clients. |
| |
| #ifndef LIB_SYSLOG_GLOBAL_H_ |
| #define LIB_SYSLOG_GLOBAL_H_ |
| |
| #include <lib/syslog/logger.h> |
| |
| __BEGIN_CDECLS |
| |
| // Gets the global logger for the process to which log messages emitted |
| // using the FX_LOG macros will be written. This function returns the same |
| // logger on all threads and is thread-safe. The returned pointer is never |
| // null and it does not get invalidated when the logger is reconfigured. |
| fx_logger_t* fx_log_get_logger(void); |
| |
| // Returns true if writing messages with the given severity is enabled in the |
| // global logger. |
| static inline bool fx_log_is_enabled(fx_log_severity_t severity) { |
| fx_logger_t* logger = fx_log_get_logger(); |
| return severity >= fx_logger_get_min_severity(logger); |
| } |
| |
| // Reconfigures the global logger for this process with the specified |
| // configuration. |
| // If |console_fd| and |log_service_channel| are invalid in |config|, |
| // this function doesn't change the currently used file descriptor or channel. |
| // |config| can be safely deallocated after this function returns. |
| // This function is NOT thread-safe and must be called early in the program |
| // before other threads are spawned. |
| // Returns: |
| // - ZX_ERR_INVALID_ARGS if config is invalid (i.e. is null or has more than |
| // FX_LOG_MAX_TAGS tags), |
| // - ZX_OK if the reconfiguration succeeds. |
| zx_status_t fx_log_reconfigure(const fx_logger_config_t* config); |
| |
| // DEPRECATED. Do not use. |
| zx_status_t fx_log_init_with_config(const fx_logger_config_t* config); |
| |
| // Returns true if writing messages with the given severity is enabled in the |
| // global logger. |severity| is one of DEBUG, INFO, WARNING, ERROR, or FATAL. |
| #define FX_LOG_IS_ENABLED(severity) (fx_log_is_enabled(FX_LOG_##severity)) |
| |
| // Returns true if writing messages with the given verbosity is enabled in the |
| // global logger. |verbosity| is positive number. |
| #define FX_VLOG_IS_ENABLED(verbosity) (fx_log_is_enabled(-(verbosity))) |
| |
| #define _FX_LOG_SET_SEVERITY(severity) \ |
| do { \ |
| fx_logger_t* logger = fx_log_get_logger(); \ |
| if (logger) { \ |
| fx_logger_set_min_severity(logger, (severity)); \ |
| } \ |
| } while (0) |
| |
| // Sets severity for global logger. |
| // |severity| is one of DEBUG, INFO, WARNING, ERROR, or FATAL. |
| #define FX_LOG_SET_SEVERITY(severity) _FX_LOG_SET_SEVERITY(FX_LOG_##severity) |
| |
| // Sets verbosity for global logger. |
| // |verbosity| is positive number. Logger severity is set to -verbosity |
| #define FX_LOG_SET_VERBOSITY(verbosity) _FX_LOG_SET_SEVERITY(-(verbosity)) |
| |
| #define _FX_LOG(severity, tag, message) \ |
| do { \ |
| fx_logger_t* logger = fx_log_get_logger(); \ |
| if (fx_logger_get_min_severity(logger) <= (severity)) { \ |
| fx_logger_log(logger, (severity), (tag), (message)); \ |
| } \ |
| } while (0) |
| |
| #define _FX_LOGF(severity, tag, message, ...) \ |
| do { \ |
| fx_logger_t* logger = fx_log_get_logger(); \ |
| if (fx_logger_get_min_severity(logger) <= (severity)) { \ |
| fx_logger_logf(logger, (severity), (tag), (message), __VA_ARGS__); \ |
| } \ |
| } while (0) |
| |
| #define _FX_LOGVF(severity, tag, message, args) \ |
| do { \ |
| fx_logger_t* logger = fx_log_get_logger(); \ |
| if (fx_logger_get_min_severity(logger) <= (severity)) { \ |
| fx_logger_logvf(logger, (severity), (tag), (message), (args)); \ |
| } \ |
| } while (0) |
| |
| // Writes a message to the global logger. |
| // |severity| is one of DEBUG, INFO, WARNING, ERROR, FATAL |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| #define FX_LOG(severity, tag, message) _FX_LOG((FX_LOG_##severity), tag, message) |
| |
| // Writes formatted message to the global logger. |
| // |severity| is one of DEBUG, INFO, WARNING, ERROR, FATAL |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| #define FX_LOGF(severity, tag, message, ...) \ |
| _FX_LOGF((FX_LOG_##severity), tag, message, __VA_ARGS__) |
| |
| // Writes formatted message to the global logger using vaargs |
| // |severity| is one of DEBUG, INFO, WARNING, ERROR, FATAL |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| // |args| are the arguments to |message|. |
| #define FX_LOGVF(severity, tag, message, args) _FX_LOGVF((FX_LOG_##severity), tag, message, args) |
| |
| // Writes verbose message to the global logger. |
| // |verbosity| is positive integer. |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| #define FX_VLOG(verbosity, tag, message) _FX_LOG(-(verbosity), tag, message) |
| |
| // Writes formatted verbose message to the global logger. |
| // |verbosity| is positive integer. |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| #define FX_VLOGF(verbosity, tag, message, ...) _FX_LOGF(-(verbosity), tag, message, __VA_ARGS__) |
| |
| // Writes formatted verbose message to the global logger using vaargs |
| // |verbosity| is positive integer. |
| // |tag| is a tag to associated with the message, or NULL if none. |
| // |message| is the message to write, or NULL if none. |
| // |args| are the arguments to |message|. |
| #define FX_VLOGVF(verbosity, tag, message, args) _FX_LOGVF(-(verbosity), tag, message, args) |
| |
| __END_CDECLS |
| |
| #endif // LIB_SYSLOG_GLOBAL_H_ |