codec: ass: Don't force fonts that aren't shipped anymore in the winstore app
[vlc.git] / modules / logger / console.c
blob14627479c9a5d64e2fdd48c69a34a1a0594a126f
1 /*****************************************************************************
2 * console.c: console logger
3 *****************************************************************************
4 * Copyright © 1998-2005 VLC authors and VideoLAN
5 * Copyright © 2006-2015 Rémi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <inttypes.h>
29 #include <unistd.h> /* isatty(), STDERR_FILNO */
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
34 static const int ptr_width = 2 * /* hex digits */ sizeof (uintptr_t);
35 static const char msg_type[4][9] = { "", " error", " warning", " debug" };
37 #ifndef _WIN32
38 # define COL(x,y) "\033[" #x ";" #y "m"
39 # define RED COL(31,1)
40 # define GREEN COL(32,1)
41 # define YELLOW COL(0,33)
42 # define WHITE COL(0,1)
43 # define GRAY "\033[0m"
44 static const char msg_color[4][8] = { WHITE, RED, YELLOW, GRAY };
46 static void LogConsoleColor(void *opaque, int type, const vlc_log_t *meta,
47 const char *format, va_list ap)
49 FILE *stream = stderr;
50 int verbose = (intptr_t)opaque;
52 if (verbose < type)
53 return;
55 flockfile(stream);
56 fprintf(stream, "["GREEN"%0*"PRIxPTR GRAY"] ", ptr_width,
57 meta->i_object_id);
58 if (meta->psz_header != NULL)
59 fprintf(stream, "[%s] ", meta->psz_header);
60 fprintf(stream, "%s %s%s: %s", meta->psz_module, meta->psz_object_type,
61 msg_type[type], msg_color[type]);
62 vfprintf(stream, format, ap);
63 fputs(GRAY"\n", stream);
64 funlockfile(stream);
66 #endif /* !_WIN32 */
68 static void LogConsoleGray(void *opaque, int type, const vlc_log_t *meta,
69 const char *format, va_list ap)
71 FILE *stream = stderr;
72 int verbose = (intptr_t)opaque;
74 if (verbose < type)
75 return;
77 flockfile(stream);
78 fprintf(stream, "[%0*"PRIxPTR"] ", ptr_width, meta->i_object_id);
79 if (meta->psz_header != NULL)
80 fprintf(stream, "[%s] ", meta->psz_header);
81 fprintf(stream, "%s %s%s: ", meta->psz_module, meta->psz_object_type,
82 msg_type[type]);
83 vfprintf(stream, format, ap);
84 putc_unlocked('\n', stream);
85 funlockfile(stream);
88 static vlc_log_cb Open(vlc_object_t *obj, void **sysp)
90 int verbosity = -1;
92 if (!var_InheritBool(obj, "quiet"))
94 const char *str = getenv("VLC_VERBOSE");
95 if (str != NULL)
96 verbosity = atoi(str);
97 else
98 verbosity = var_InheritInteger(obj, "verbose");
101 if (verbosity < 0)
102 return NULL;
104 verbosity += VLC_MSG_ERR;
105 *sysp = (void *)(uintptr_t)verbosity;
107 #if defined (HAVE_ISATTY) && !defined (_WIN32)
108 if (isatty(STDERR_FILENO) && var_InheritBool(obj, "color"))
109 return LogConsoleColor;
110 #endif
111 return LogConsoleGray;
114 #define QUIET_TEXT N_("Be quiet")
115 #define QUIET_LONGTEXT N_("Turn off all messages on the console.")
117 vlc_module_begin()
118 set_shortname(N_("Console log"))
119 set_description(N_("Console logger"))
120 set_category(CAT_ADVANCED)
121 set_subcategory(SUBCAT_ADVANCED_MISC)
122 set_capability("logger", 10)
123 set_callbacks(Open, NULL)
125 add_bool("quiet", false, QUIET_TEXT, QUIET_LONGTEXT, false)
126 change_short('q')
127 change_volatile()
128 vlc_module_end ()