1 /*
2  * This file is part of mpv.
3  *
4  * mpv is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * mpv is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MPLAYER_MP_MSG_H
19 #define MPLAYER_MP_MSG_H
20 
21 #include <stdarg.h>
22 #include <stdbool.h>
23 #include <stdlib.h>
24 #include <stdint.h>
25 
26 #include "osdep/compiler.h"
27 
28 struct mp_log;
29 
30 // A mp_log instance that never outputs anything.
31 extern struct mp_log *const mp_null_log;
32 
33 // Verbosity levels.
34 enum {
35     MSGL_FATAL,     // only errors (difference to MSGL_ERR isn't too clear)
36     MSGL_ERR,       // only errors
37     MSGL_WARN,      // only warnings
38     MSGL_INFO,      // what you normally see on the terminal
39     MSGL_STATUS,    // exclusively for the playback status line (-quiet disables)
40     MSGL_V,         // -v | slightly more information than default
41     MSGL_DEBUG,     // -v -v | full debug information; this and numerically below
42                     // should not produce "per frame" output
43     MSGL_TRACE,     // -v -v -v | anything that might flood the terminal
44     MSGL_STATS,     // dumping fine grained stats (--dump-stats)
45 
46     MSGL_MAX = MSGL_STATS,
47 };
48 
49 struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
50                           const char *name);
51 
52 void mp_msg(struct mp_log *log, int lev, const char *format, ...)
53     PRINTF_ATTRIBUTE(3, 4);
54 void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va);
55 
56 int mp_msg_level(struct mp_log *log);
57 
mp_msg_test(struct mp_log * log,int lev)58 static inline bool mp_msg_test(struct mp_log *log, int lev)
59 {
60     return lev <= mp_msg_level(log);
61 }
62 
63 void mp_msg_set_max_level(struct mp_log *log, int lev);
64 
65 // Convenience macros.
66 #define mp_fatal(log, ...)      mp_msg(log, MSGL_FATAL, __VA_ARGS__)
67 #define mp_err(log, ...)        mp_msg(log, MSGL_ERR, __VA_ARGS__)
68 #define mp_warn(log, ...)       mp_msg(log, MSGL_WARN, __VA_ARGS__)
69 #define mp_info(log, ...)       mp_msg(log, MSGL_INFO, __VA_ARGS__)
70 #define mp_verbose(log, ...)    mp_msg(log, MSGL_V, __VA_ARGS__)
71 #define mp_dbg(log, ...)        mp_msg(log, MSGL_DEBUG, __VA_ARGS__)
72 #define mp_trace(log, ...)      mp_msg(log, MSGL_TRACE, __VA_ARGS__)
73 
74 // Convenience macros, typically called with a pointer to a context struct
75 // as first argument, which has a "struct mp_log *log;" member.
76 
77 #define MP_MSG(obj, lev, ...)   mp_msg((obj)->log, lev, __VA_ARGS__)
78 
79 #define MP_FATAL(obj, ...)      MP_MSG(obj, MSGL_FATAL, __VA_ARGS__)
80 #define MP_ERR(obj, ...)        MP_MSG(obj, MSGL_ERR, __VA_ARGS__)
81 #define MP_WARN(obj, ...)       MP_MSG(obj, MSGL_WARN, __VA_ARGS__)
82 #define MP_INFO(obj, ...)       MP_MSG(obj, MSGL_INFO, __VA_ARGS__)
83 #define MP_VERBOSE(obj, ...)    MP_MSG(obj, MSGL_V, __VA_ARGS__)
84 #define MP_DBG(obj, ...)        MP_MSG(obj, MSGL_DEBUG, __VA_ARGS__)
85 #define MP_TRACE(obj, ...)      MP_MSG(obj, MSGL_TRACE, __VA_ARGS__)
86 
87 // This is a bit special. See TOOLS/stats-conv.py what rules text passed
88 // to these functions should follow. Also see --dump-stats.
89 #define mp_stats(obj, ...)      mp_msg(obj, MSGL_STATS, __VA_ARGS__)
90 #define MP_STATS(obj, ...)      MP_MSG(obj, MSGL_STATS, __VA_ARGS__)
91 
92 #endif /* MPLAYER_MP_MSG_H */
93