X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=blobdiff_plain;f=vg_log.h;h=d30e7ba330bb827d9884a63c1acf05a53bebf477;hp=72dd82c4dfa9cd3ac62301cc2cfb86bc968a42a9;hb=HEAD;hpb=fb4da0217c89131c17e33d03804ebd46b9232897 diff --git a/vg_log.h b/vg_log.h index 72dd82c..cf2b737 100644 --- a/vg_log.h +++ b/vg_log.h @@ -1,11 +1,23 @@ -#ifndef VG_LOG_H -#define VG_LOG_H +#pragma once -#include -#include -#include -#include "vg_stdint.h" #include "vg_platform.h" +#include + +#define VG_LOG_MCSTR(S) VG_LOG_MCSTR2(S) +#define VG_LOG_MCSTR2(S) #S +#define VG_LOG_WHERE "@" __FILE__ ":" VG_LOG_MCSTR(__LINE__)\ + " " + +#define vg_success( ... ) \ + vg_logx(stdout,VG_LOG_WHERE,"success",KGRN,__VA_ARGS__) +#define vg_info( ... ) \ + vg_logx(stdout,VG_LOG_WHERE,"info",KNRM,__VA_ARGS__) +#define vg_warn( ... ) \ + vg_logx(stdout,VG_LOG_WHERE,"warn",KYEL,__VA_ARGS__ ) +#define vg_error( ... ) \ + vg_logx(stdout,VG_LOG_WHERE,"error",KRED,__VA_ARGS__) +#define vg_low( ... ) \ + vg_logx(stdout,VG_LOG_WHERE,"log",KWHT,__VA_ARGS__) #define KNRM "\x1B[0m" #define KBLK "\x1B[30m" @@ -27,78 +39,30 @@ #define PRINTF_U64 "%lu" #endif -#ifdef VG_GAME -static SDL_SpinLock log_print_sl; +#ifdef VG_ENGINE + #include "dep/sdl/include/SDL.h" #endif struct vg_log { - char buffer[64][96]; - u32 buffer_line_count, buffer_line_current; -} -static vg_log; - -void _vg_console_append_to_log( const char *str ) -{ - if( vg_log.buffer_line_count < vg_list_size( vg_log.buffer ) ) - vg_log.buffer_line_count ++; - - char *dest = vg_log.buffer[ vg_log.buffer_line_current ++ ]; - - for( int i=0; i= vg_list_size( vg_log.buffer ) ) - vg_log.buffer_line_current = 0; -} - -VG_STATIC void _vg_log_write( FILE *file, const char *prefix, - const char *fmt, va_list args ) -{ -#ifdef VG_GAME - SDL_AtomicLock( &log_print_sl ); -#endif + char log[64][96]; + u32 log_line_count, log_line_current; - char buffer[ 4096 ]; - int i, j; - - for( i=0; i