libmetal  353
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 
12 #ifndef __METAL_METAL_LOG__H__
13 #define __METAL_METAL_LOG__H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
33 };
34 
36 typedef void (*metal_log_handler)(enum metal_log_level level,
37  const char *format, ...);
38 
44 
50 
55 void metal_set_log_level(enum metal_log_level level);
56 
62 
70  const char *format, ...);
71 
83 #if defined(ML_FUNC_LINE)
84 #define metal_fmt(fmt) "%s:%u " fmt, __func__, __LINE__
85 #else /* ML_FUNC_LINE */
86 #define metal_fmt(fmt) fmt
87 #endif /* ML_FUNC_LINE */
88 
96 #define metal_log(level, fmt, ...) ({ \
97  if (_metal.common.log_handler && level <= _metal.common.log_level) \
98  _metal.common.log_handler(level, metal_fmt(fmt), ## __VA_ARGS__); \
99 })
100 
101 #define metal_err(fmt, args...) metal_log(METAL_LOG_ERROR, fmt, ##args)
102 #define metal_warn(fmt, args...) metal_log(METAL_LOG_WARNING, fmt, ##args)
103 #define metal_info(fmt, args...) metal_log(METAL_LOG_INFO, fmt, ##args)
104 #define metal_dbg(fmt, args...) metal_log(METAL_LOG_DEBUG, fmt, ##args)
105 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* __METAL_METAL_LOG__H__ */
void metal_default_log_handler(enum metal_log_level level, const char *format,...)
Default libmetal log handler.
Definition: log.c:18
metal_log_level
Log message priority levels for libmetal.
Definition: log.h:24
metal_log_handler metal_get_log_handler(void)
Get the current libmetal log handler.
Definition: log.c:54
void metal_set_log_handler(metal_log_handler handler)
Set libmetal log handler.
Definition: log.c:49
void metal_set_log_level(enum metal_log_level level)
Set the level for libmetal logging.
Definition: log.c:59
void(* metal_log_handler)(enum metal_log_level level, const char *format,...)
Log message handler type.
Definition: log.h:36
enum metal_log_level metal_get_log_level(void)
Get the current level for libmetal logging.
Definition: log.c:64
@ METAL_LOG_NOTICE
normal but significant condition.
Definition: log.h:30
@ METAL_LOG_INFO
informational messages.
Definition: log.h:31
@ METAL_LOG_WARNING
warning conditions.
Definition: log.h:29
@ METAL_LOG_EMERGENCY
system is unusable.
Definition: log.h:25
@ METAL_LOG_ALERT
action must be taken immediately.
Definition: log.h:26
@ METAL_LOG_CRITICAL
critical conditions.
Definition: log.h:27
@ METAL_LOG_DEBUG
debug-level messages.
Definition: log.h:32
@ METAL_LOG_ERROR
error conditions.
Definition: log.h:28