Skip to content

Commit 2ed7ded

Browse files
SiegeLordExSiegeLord
authored andcommitted
Allow outputting logs to stdout via the ALLEGRO_TRACE env variable.
1 parent 96757f2 commit 2ed7ded

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

allegro5.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ channels=all
186186
# Log-level. Can be one of debug, info, warn, error, none or empty.
187187
# In debug builds if it is empty or unset, then the level is set to debug.
188188
# In release builds if it is empty or unset, then the level is set to none.
189+
# If not none, Allegro will write out the logs to an allegro.log file next to
190+
# the binary. Use ALLEGRO_TRACE environment variable to control that file
191+
# location. A special filename of - (dash) means logging to stdout.
189192
level=
190193

191194
# Set to 0 to disable line numbers in log files.

src/debug.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct TRACE_INFO
3636
{
3737
bool trace_virgin;
3838
FILE *trace_file;
39+
bool need_close;
3940
_AL_MUTEX trace_mutex;
4041

4142
/* 0: debug, 1: info, 2: warn, 3: error */
@@ -54,6 +55,7 @@ static TRACE_INFO trace_info =
5455
{
5556
true,
5657
NULL,
58+
true,
5759
_AL_MUTEX_UNINITED,
5860
0,
5961
7,
@@ -173,8 +175,15 @@ static void open_trace_file(void)
173175
if (trace_info.trace_virgin) {
174176
const char *s = getenv("ALLEGRO_TRACE");
175177

176-
if (s)
177-
trace_info.trace_file = fopen(s, "w");
178+
if (s) {
179+
if (!strcmp(s, "-")) {
180+
trace_info.trace_file = stdout;
181+
trace_info.need_close = false;
182+
}
183+
else {
184+
trace_info.trace_file = fopen(s, "w");
185+
}
186+
}
178187
else
179188
#if defined(ALLEGRO_IPHONE) || defined(ALLEGRO_ANDROID) || defined(__EMSCRIPTEN__)
180189
/* iPhone and Android don't like us writing files, so we'll be doing
@@ -342,7 +351,7 @@ void _al_shutdown_logging(void)
342351
trace_info.configured = false;
343352
}
344353

345-
if (trace_info.trace_file) {
354+
if (trace_info.trace_file && trace_info.need_close) {
346355
fclose(trace_info.trace_file);
347356
}
348357

0 commit comments

Comments
 (0)