comparison mupdf-source/source/fitz/log.c @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 // Copyright (C) 2004-2021 Artifex Software, Inc.
2 //
3 // This file is part of MuPDF.
4 //
5 // MuPDF is free software: you can redistribute it and/or modify it under the
6 // terms of the GNU Affero General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or (at your option)
8 // any later version.
9 //
10 // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
17 //
18 // Alternative licensing terms are available from the licensor.
19 // For commercial licensing, see <https://www.artifex.com/> or contact
20 // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
21 // CA 94129, USA, for further information.
22
23 #include "mupdf/fitz.h"
24
25 #include <assert.h>
26 #include <limits.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 fz_output *fz_new_log_for_module(fz_context *ctx, const char *module)
31 {
32 char text[256];
33 char *s = NULL;
34
35 if (module)
36 {
37 fz_snprintf(text, sizeof(text), "FZ_LOG_FILE_%s", module);
38 s = getenv(text);
39 }
40 if (s == NULL)
41 s = getenv("FZ_LOG_FILE");
42 if (s == NULL)
43 s = "fitz_log.txt";
44 return fz_new_output_with_path(ctx, s, 1);
45 }
46
47 void fz_log(fz_context *ctx, const char *fmt, ...)
48 {
49 fz_output *out;
50 va_list args;
51 va_start(args, fmt);
52 fz_try(ctx)
53 {
54 out = fz_new_log_for_module(ctx, NULL);
55 fz_write_vprintf(ctx, out, fmt, args);
56 fz_close_output(ctx, out);
57 }
58 fz_always(ctx)
59 {
60 va_end(args);
61 fz_drop_output(ctx, out);
62 }
63 fz_catch(ctx)
64 fz_rethrow(ctx);
65 }
66
67 void fz_log_module(fz_context *ctx, const char *module, const char *fmt, ...)
68 {
69 fz_output *out;
70 va_list args;
71 va_start(args, fmt);
72 fz_try(ctx)
73 {
74 out = fz_new_log_for_module(ctx, module);
75 if (module)
76 fz_write_printf(ctx, out, "%s\t", module);
77 fz_write_vprintf(ctx, out, fmt, args);
78 fz_close_output(ctx, out);
79 }
80 fz_always(ctx)
81 {
82 va_end(args);
83 fz_drop_output(ctx, out);
84 }
85 fz_catch(ctx)
86 fz_rethrow(ctx);
87 }