naev 0.12.5
log.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <signal.h>
8#include <stdio.h>
9
10#include "gettext.h" // IWYU pragma: keep
12
13#include "nstring.h"
14
15#define LOG( str, ... ) logprintf( stdout, 1, str, ##__VA_ARGS__ )
16#define LOGERR( str, ... ) logprintf( stderr, 1, str, ##__VA_ARGS__ )
17#define WARN( str, ... ) \
18 log_warn( __FILE__, __LINE__, __func__, str, ##__VA_ARGS__ )
19#define ERR( str, ... ) \
20 ( logprintf( stderr, 0, _( "ERROR %s:%d [%s]: " ), __FILE__, __LINE__, \
21 __func__ ), \
22 logprintf( stderr, 1, str, ##__VA_ARGS__ ), abort() )
23#ifdef DEBUG
24#undef DEBUG
25#define DEBUG( str, ... ) LOG( str, ##__VA_ARGS__ )
26#ifndef DEBUGGING
27#define DEBUGGING 1
28#endif /* DEBUGGING */
29#else /* DEBUG */
30#define DEBUG( str, ... ) \
31 do { \
32 } while ( 0 )
33#endif /* DEBUG */
34#define DEBUG_BLANK() DEBUG( "%s", "" )
35
36PRINTF_FORMAT( 3, 4 )
37NONNULL( 3 ) int logprintf( FILE *stream, int newline, const char *fmt, ... );
38void log_init( void );
39void log_redirect( void );
40void log_clean( void );
41int log_warn( const char *file, size_t line, const char *func, const char *fmt,
42 ... );
void log_clean(void)
Deletes useless (empty) log files from the current session.
Definition log.c:228
int logprintf(FILE *stream, int newline, const char *fmt,...)
Like fprintf, but automatically teed to log files (and line-terminated if newline is true).
Definition log.c:116
void log_init(void)
Sets up the logging subsystem. (Calling this ensures logging output is preserved until we have a plac...
Definition log.c:164
void log_redirect(void)
Sets up redirection of stdout and stderr to files. PhysicsFS must be initialized for this to work.
Definition log.c:130
int log_warn(const char *file, size_t line, const char *func, const char *fmt,...)
Prints warnings, but skips if they are repeated too much.
Definition log.c:299