VLC  4.0.0-dev
vlc_messages.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_messages.h: messages interface
3  * This library provides basic functions for threads to interact with user
4  * interface, such as message output.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000, 2001, 2002 VLC authors and VideoLAN
7  *
8  * Authors: Vincent Seguin <seguin@via.ecp.fr>
9  * Samuel Hocevar <sam@zoy.org>
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25 
26 #ifndef VLC_MESSAGES_H_
27 #define VLC_MESSAGES_H_
28 
29 #include <stdarg.h>
30 
31 /**
32  * \defgroup messages Logging
33  * \ingroup os
34  * \brief Message logs
35  *
36  * Functions for modules to emit log messages.
37  *
38  * @{
39  * \file
40  * Logging functions
41  */
42 
43 /** Message types */
44 enum vlc_log_type
45 {
46  VLC_MSG_INFO=0, /**< Important information */
47  VLC_MSG_ERR, /**< Error */
48  VLC_MSG_WARN, /**< Warning */
49  VLC_MSG_DBG, /**< Debug */
50 };
51 
52 /**
53  * Log message
54  */
55 typedef struct vlc_log_t
56 {
57  uintptr_t i_object_id; /**< Emitter (temporarily) unique object ID or 0 */
58  const char *psz_object_type; /**< Emitter object type name */
59  const char *psz_module; /**< Emitter module (source code) */
60  const char *psz_header; /**< Additional header (used by VLM media) */
61  const char *file; /**< Source code file name or NULL */
62  int line; /**< Source code file line number or -1 */
63  const char *func; /**< Source code calling function name or NULL */
64  unsigned long tid; /**< Emitter thread ID */
66 
67 /**
68  * Emit a log message.
69  *
70  * \param obj VLC object emitting the message or NULL
71  * \param type VLC_MSG_* message type (info, error, warning or debug)
72  * \param module name of module from which the message come
73  * (normally vlc_module_name)
74  * \param file source module file name (normally __FILE__) or NULL
75  * \param line function call source line number (normally __LINE__) or 0
76  * \param func calling function name (normally __func__) or NULL
77  * \param format printf-like message format
78  */
79 VLC_API void vlc_object_Log(vlc_object_t *obj, int prio, const char *module,
80  const char *file, unsigned line, const char *func,
81  const char *format, ...) VLC_FORMAT(7, 8);
82 
83 /**
84  * Emit a log message.
85  *
86  * This function is the variable argument list equivalent to vlc_object_Log().
87  */
88 VLC_API void vlc_object_vaLog(vlc_object_t *obj, int prio, const char *module,
89  const char *file, unsigned line, const char *func,
90  const char *format, va_list ap);
91 
92 #define msg_GenericVa(o, p, fmt, ap) \
93  vlc_object_vaLog(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
94  __func__, fmt, ap)
95 
96 #define msg_Generic(o, p, ...) \
97  vlc_object_Log(VLC_OBJECT(o), p, vlc_module_name, __FILE__, __LINE__, \
98  __func__, __VA_ARGS__)
99 #define msg_Info(p_this, ...) \
100  msg_Generic(p_this, VLC_MSG_INFO, __VA_ARGS__)
101 #define msg_Err(p_this, ...) \
102  msg_Generic(p_this, VLC_MSG_ERR, __VA_ARGS__)
103 #define msg_Warn(p_this, ...) \
104  msg_Generic(p_this, VLC_MSG_WARN, __VA_ARGS__)
105 #define msg_Dbg(p_this, ...) \
106  msg_Generic(p_this, VLC_MSG_DBG, __VA_ARGS__)
107 
108 #ifndef __cplusplus
109 extern const char vlc_module_name[];
110 #else
111 extern "C" const char vlc_module_name[];
112 #endif
113 
114 VLC_API const char *vlc_strerror(int);
115 VLC_API const char *vlc_strerror_c(int);
116 
117 /**
118  * \defgroup logger Logger
119  * \brief Message log back-end.
120  *
121  * @{
122  */
123 
124 struct vlc_logger;
125 
126 VLC_API void vlc_Log(struct vlc_logger *const *logger, int prio,
127  const char *type, const char *module,
128  const char *file, unsigned line, const char *func,
129  const char *format, ...) VLC_FORMAT(8, 9);
130 VLC_API void vlc_vaLog(struct vlc_logger *const *logger, int prio,
131  const char *type, const char *module,
132  const char *file, unsigned line, const char *func,
133  const char *format, va_list ap);
134 
135 #define vlc_log_gen(logger, prio, ...) \
136  vlc_Log(&(logger), prio, "generic", vlc_module_name, \
137  __FILE__, __LINE__, __func__, __VA_ARGS__)
138 #define vlc_info(logger, ...) vlc_log_gen(logger, VLC_MSG_INFO, __VA_ARGS__)
139 #define vlc_error(logger, ...) vlc_log_gen(logger, VLC_MSG_ERR, __VA_ARGS__)
140 #define vlc_warning(logger, ...) vlc_log_gen(logger, VLC_MSG_WARN, __VA_ARGS__)
141 #define vlc_debug(logger, ...) vlc_log_gen(logger, VLC_MSG_DBG, __VA_ARGS__)
142 
143 /**
144  * Message logging callback signature.
145  * \param data data pointer as provided to vlc_msg_SetCallback().
146  * \param type message type (VLC_MSG_* values from enum vlc_log_type)
147  * \param item meta information
148  * \param fmt format string
149  * \param args format string arguments
150  */
151 typedef void (*vlc_log_cb) (void *data, int type, const vlc_log_t *item,
152  const char *fmt, va_list args);
153 
155 {
156  vlc_log_cb log;
157  void (*destroy)(void *data);
158 };
159 
160 /**
161  * Creates a prefixed message log.
162  *
163  * This creates a message log that prefixes all its messages and forwards them
164  * in another log.
165  * \param parent message log to inject into
166  * \param str nul-terminated prefix (a.k.a. "header")
167  * \return a new message log on success or @c NULL on error
168  */
169 VLC_API struct vlc_logger *vlc_LogHeaderCreate(struct vlc_logger *parent,
170  const char *str) VLC_USED;
171 
172 /**
173  * Destroys a message log.
174  */
175 VLC_API void vlc_LogDestroy(struct vlc_logger *);
176 
177 /**
178  * @}
179  */
180 /**
181  * @}
182  */
183 #endif
vlc_object_vaLog
VLC_EXPORT void vlc_object_vaLog(vlc_object_t *obj, int prio, const char *module, const char *file, unsigned line, const char *func, const char *format, va_list ap)
Emit a log message.
Definition: objects.c:139
VLC_API
#define VLC_API
Definition: fourcc_gen.c:31
vlc_common.h
vlc_logger
Definition: messages.c:54
vlc_LogDestroy
VLC_EXPORT void vlc_LogDestroy(struct vlc_logger *)
Destroys a message log.
Definition: messages.c:585
vlc_log_t::psz_header
const char * psz_header
Additional header (used by VLM media)
Definition: vlc_messages.h:61
VLC_MSG_INFO
@ VLC_MSG_INFO
Important information.
Definition: vlc_messages.h:47
vlc_log_t::psz_object_type
const char * psz_object_type
Emitter object type name.
Definition: vlc_messages.h:59
VLC_MSG_ERR
@ VLC_MSG_ERR
Error.
Definition: vlc_messages.h:48
vlc_strerror
const VLC_EXPORT char * vlc_strerror(int)
Formats an error message in the current locale.
Definition: error.c:29
vlc_log_cb
void(* vlc_log_cb)(void *data, int type, const vlc_log_t *item, const char *fmt, va_list args)
Message logging callback signature.
Definition: vlc_messages.h:152
vlc_log_t
struct vlc_log_t vlc_log_t
Log message.
vlc_logger_operations
Definition: vlc_messages.h:155
vlc_strerror_c
const VLC_EXPORT char * vlc_strerror_c(int)
Formats an error message in the POSIX/C locale (i.e.
Definition: error.c:34
vlc_vaLog
VLC_EXPORT void vlc_vaLog(struct vlc_logger *const *logger, int prio, const char *type, const char *module, const char *file, unsigned line, const char *func, const char *format, va_list ap)
Definition: messages.c:85
vlc_log_t::file
const char * file
Source code file name or NULL.
Definition: vlc_messages.h:62
vlc_log_t::line
int line
Source code file line number or -1.
Definition: vlc_messages.h:63
vlc_log_t::tid
unsigned long tid
Emitter thread ID.
Definition: vlc_messages.h:65
VLC_MSG_WARN
@ VLC_MSG_WARN
Warning.
Definition: vlc_messages.h:49
VLC_FORMAT
#define VLC_FORMAT(x, y)
String format function annotation.
Definition: vlc_common.h:141
vlc_object_t
VLC object common members.
Definition: vlc_objects.h:43
vlc_log_t::func
const char * func
Source code calling function name or NULL.
Definition: vlc_messages.h:64
vlc_Log
VLC_EXPORT void vlc_Log(struct vlc_logger *const *logger, int prio, const char *type, const char *module, const char *file, unsigned line, const char *func, const char *format,...)
Definition: messages.c:131
vlc_logger_operations::log
vlc_log_cb log
Definition: vlc_messages.h:157
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:32
vlc_log_t::psz_module
const char * psz_module
Emitter module (source code)
Definition: vlc_messages.h:60
vlc_logger_operations::destroy
void(* destroy)(void *data)
Definition: vlc_messages.h:158
vlc_module_name
const char vlc_module_name[]
vlc_LogHeaderCreate
VLC_EXPORT struct vlc_logger * vlc_LogHeaderCreate(struct vlc_logger *parent, const char *str)
Creates a prefixed message log.
Definition: messages.c:505
vlc_object_Log
VLC_EXPORT void vlc_object_Log(vlc_object_t *obj, int prio, const char *module, const char *file, unsigned line, const char *func, const char *format,...)
Emit a log message.
Definition: objects.c:155
vlc_log_t::i_object_id
uintptr_t i_object_id
Emitter (temporarily) unique object ID or 0.
Definition: vlc_messages.h:58
VLC_MSG_DBG
@ VLC_MSG_DBG
Debug.
Definition: vlc_messages.h:50
vlc_log_t
Log message.
Definition: vlc_messages.h:56
vlc_log_type
vlc_log_type
Message types.
Definition: vlc_messages.h:45