libmetal
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
8 * @file log.h
9 * @brief Logging support for libmetal.
10 */
11
12#ifndef __METAL_METAL_LOG__H__
13#define __METAL_METAL_LOG__H__
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
22
34
36typedef void (*metal_log_handler)(enum metal_log_level level,
37 const char *format, ...);
38
45
51
57
63
72 const char *format, ...);
73
85#if defined(ML_FUNC_LINE)
86#define metal_fmt(fmt) "%s:%u " fmt, __func__, __LINE__
87#else /* ML_FUNC_LINE */
88#define metal_fmt(fmt) fmt
89#endif /* ML_FUNC_LINE */
90
98#define metal_log(level, fmt, ...) ({ \
99 if (_metal.common.log_handler && level <= _metal.common.log_level) \
100 _metal.common.log_handler(level, metal_fmt(fmt), ## __VA_ARGS__); \
101})
102
103#define metal_err(fmt, args...) metal_log(METAL_LOG_ERROR, fmt, ##args)
104#define metal_warn(fmt, args...) metal_log(METAL_LOG_WARNING, fmt, ##args)
105#define metal_info(fmt, args...) metal_log(METAL_LOG_INFO, fmt, ##args)
106#define metal_dbg(fmt, args...) metal_log(METAL_LOG_DEBUG, fmt, ##args)
107
109
110#ifdef __cplusplus
111}
112#endif
113
114#include <metal/system/@PROJECT_SYSTEM@/log.h>
115
116#endif /* __METAL_METAL_LOG__H__ */
void metal_default_log_handler(enum metal_log_level level, const char *format,...)
Default libmetal log handler. This handler prints libmetal log messages to stderr.
Definition log.c:13
metal_log_level
Definition log.h:24
metal_log_handler metal_get_log_handler(void)
Get the current libmetal log handler.
Definition log.c:49
void metal_set_log_handler(metal_log_handler handler)
Set libmetal log handler.
Definition log.c:44
void metal_set_log_level(enum metal_log_level level)
Set the level for libmetal logging.
Definition log.c:54
void(* metal_log_handler)(enum metal_log_level level, const char *format,...)
Definition log.h:36
enum metal_log_level metal_get_log_level(void)
Get the current level for libmetal logging.
Definition log.c:59
@ METAL_LOG_NOTICE
Definition log.h:30
@ METAL_LOG_INFO
Definition log.h:31
@ METAL_LOG_WARNING
Definition log.h:29
@ METAL_LOG_EMERGENCY
Definition log.h:25
@ METAL_LOG_ALERT
Definition log.h:26
@ METAL_LOG_CRITICAL
Definition log.h:27
@ METAL_LOG_DEBUG
Definition log.h:32
@ METAL_LOG_ERROR
Definition log.h:28