medfall

A super great game engine
Log | Files | Refs

log.h (1009B)


      1 #pragma once
      2 
      3 #include <stdlib.h>
      4 
      5 #include "str.h"
      6 #include "platform_backtrace.h"
      7 
      8 enum LogLevel {
      9 	LOGLEVEL_FATAL,
     10 	LOGLEVEL_WARNING,
     11 	LOGLEVEL_INFO,
     12 
     13 	LOGLEVEL_COUNT,
     14 };
     15 
     16 void logger_init();
     17 void logger_term();
     18 
     19 void logger_thread_name( const char * name );
     20 void logger_log( LogLevel level, const char * message );
     21 
     22 template< typename... Rest >
     23 void logger_thread_name( const char * fmt, Rest... rest ) {
     24 	str< 32 > buf( fmt, rest... );
     25 	logger_thread_name( buf.c_str() );
     26 }
     27 
     28 template< typename... Rest >
     29 void logger_log( LogLevel level, const char * fmt, Rest... rest ) {
     30 	str< 1024 > buf( fmt, rest... );
     31 	logger_log( level, buf.c_str() );
     32 }
     33 
     34 const char * logger_get_logs_dir();
     35 
     36 #define INFO( form, ... ) logger_log( LOGLEVEL_INFO, "[INFO] " form, ##__VA_ARGS__ )
     37 #define WARN( form, ... ) logger_log( LOGLEVEL_WARNING, "[WARN] " form, ##__VA_ARGS__ )
     38 #define FATAL( form, ... ) \
     39 	do { \
     40 		logger_log( LOGLEVEL_FATAL, "[FATAL] " form, ##__VA_ARGS__ ); \
     41 		print_backtrace_and_abort(); \
     42 	} while( 0 )