1 /*
2 * log functions
3 * Copyright (c) 2003 Michel Bardiaux
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * logging functions
25 */
26
27 #include "config.h"
28
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 #if HAVE_IO_H
33 #include <io.h>
34 #endif
35 #include <stdarg.h>
36 #include <stdlib.h>
42
43 #if HAVE_PTHREADS
44 #include <pthread.h>
46 #endif
47
49
52
53 #if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE
54 #include <windows.h>
80 };
81
82 static int16_t background, attr_orig;
84 #else
85
111 };
112
113 #endif
115
117 {
118 #if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE
119 CONSOLE_SCREEN_BUFFER_INFO con_info;
120 con = GetStdHandle(STD_ERROR_HANDLE);
122 !getenv("AV_LOG_FORCE_NOCOLOR");
124 GetConsoleScreenBufferInfo(con, &con_info);
125 attr_orig = con_info.wAttributes;
126 background = attr_orig & 0xF0;
127 }
128 #elif HAVE_ISATTY
129 char *term = getenv("TERM");
130 use_color = !getenv(
"NO_COLOR") && !getenv(
"AV_LOG_FORCE_NOCOLOR") &&
131 (getenv("TERM") && isatty(2) || getenv("AV_LOG_FORCE_COLOR"));
132 if ( getenv("AV_LOG_FORCE_256COLOR")
133 || (term && strstr(term, "256color")))
135 #else
136 use_color = getenv(
"AV_LOG_FORCE_COLOR") && !getenv(
"NO_COLOR") &&
137 !getenv("AV_LOG_FORCE_NOCOLOR");
138 #endif
139 }
140
142 {
143 int local_use_color;
144 if (!*str)
145 return;
146
149
152
153 #if defined(_WIN32) && !defined(__MINGW32CE__) && HAVE_SETCONSOLETEXTATTRIBUTE
154 if (local_use_color)
155 SetConsoleTextAttribute(con, background |
color[level]);
156 fputs(str, stderr);
157 if (local_use_color)
158 SetConsoleTextAttribute(con, attr_orig);
159 #else
160 if (local_use_color == 1) {
161 fprintf(stderr,
162 "033円[%d;3%dm%s033円[0m",
163 (
color[level] >> 4) & 15,
165 str);
167 fprintf(stderr,
168 "033円[48;5;%dm033円[38;5;%dm%s033円[0m",
169 (
color[level] >> 16) & 0xff,
170 tint,
171 str);
172 } else if (local_use_color == 256) {
173 fprintf(stderr,
174 "033円[48;5;%dm033円[38;5;%dm%s033円[0m",
175 (
color[level] >> 16) & 0xff,
176 (
color[level] >> 8) & 0xff,
177 str);
178 } else
179 fputs(str, stderr);
180 #endif
181
182 }
183
185 {
186 return (*(
AVClass **) ptr)->class_name;
187 }
188
190 {
191 return (*(
AVClass **) ptr)->category;
192 }
193
195 while(*line){
196 if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
197 *line='?';
198 line++;
199 }
200 }
201
204 if( !avc
206 || avc->
version < (51 << 16 | 59 << 8)
208
211
213 }
214
216 {
217 switch (level) {
219 return "quiet";
221 return "debug";
223 return "verbose";
225 return "info";
227 return "warning";
229 return "error";
231 return "fatal";
233 return "panic";
234 default:
235 return "";
236 }
237 }
238
240 AVBPrint part[4],
int *print_prefix,
int type[2])
241 {
247
249 if (*print_prefix && avc) {
253 if (parent && *parent) {
255 (*parent)->item_name(parent), parent);
257 }
258 }
262
265 }
266
268
269 if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
270 char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0;
271 *print_prefix = lastc == '\n' || lastc == '\r';
272 }
273 }
274
276 char *
line,
int line_size,
int *print_prefix)
277 {
278 AVBPrint part[4];
280 snprintf(line, line_size,
"%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
282 }
283
285 {
286 static int print_prefix = 1;
289 AVBPrint part[4];
291 static int is_atty;
293 unsigned tint = 0;
294
295 if (level >= 0) {
296 tint = level & 0xff00;
297 level &= 0xff;
298 }
299
301 return;
302 #if HAVE_PTHREADS
304 #endif
305
306 format_line(ptr, level, fmt, vl, part, &print_prefix, type);
307 snprintf(line,
sizeof(line),
"%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
308
309 #if HAVE_ISATTY
310 if (!is_atty)
311 is_atty = isatty(2) ? 1 : -1;
312 #endif
313
315 *line && line[strlen(line) - 1] != '\r'){
316 count++;
317 if (is_atty == 1)
318 fprintf(stderr, " Last message repeated %d times\r", count);
320 }
321 if (count > 0) {
322 fprintf(stderr, " Last message repeated %d times\n", count);
323 count = 0;
324 }
325 strcpy(prev, line);
331 colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, part[2].str);
333 colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, part[3].str);
336 #if HAVE_PTHREADS
338 #endif
339 }
340
343
345 {
347 va_list vl;
348 va_start(vl, fmt);
349 if (avc && avc->
version >= (50 << 16 | 15 << 8 | 2) &&
353 va_end(vl);
354 }
355
357 {
359 if (log_callback)
360 log_callback(avcl, level, fmt, vl);
361 }
362
364 {
366 }
367
369 {
371 }
372
374 {
376 }
377
379 {
381 }
382
384 {
386 }
387
389 va_list argument_list)
390 {
393 "version to the newest one from Git. If the problem still "
394 "occurs, it means that your file has a feature which has not "
395 "been implemented.\n");
396 if (sample)
398 "of this file to ftp://upload.ffmpeg.org/incoming/ "
399 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
400 }
401
403 {
404 va_list argument_list;
405
406 va_start(argument_list, msg);
408 va_end(argument_list);
409 }
410
412 {
413 va_list argument_list;
414
415 va_start(argument_list, msg);
417 va_end(argument_list);
418 }
419
420 #ifdef TEST
421 // LCOV_EXCL_START
422 #include <string.h>
423
424 int main(
int argc,
char **argv)
425 {
426 int i;
435 }
437 }
438 return 0;
439 }
440 // LCOV_EXCL_STOP
441 #endif