638d63feaa13172d3df2e7cde302c38f34a77d2d
6 #include "vg_platform.h"
13 static void _vg_log_append_line( const char *str
){
14 if( vg_log
.log_line_count
< vg_list_size( vg_log
.log
) )
15 vg_log
.log_line_count
++;
17 char *dest
= vg_log
.log
[ vg_log
.log_line_current
++ ];
18 vg_strncpy( str
, dest
, vg_list_size(vg_log
.log
[0]), k_strncpy_allow_cutoff
);
20 if( vg_log
.log_line_current
>= vg_list_size( vg_log
.log
) )
21 vg_log
.log_line_current
= 0;
24 static void _vg_logx_va( FILE *file
,
25 const char *location
, const char *prefix
,
27 const char *fmt
, va_list args
)
30 /* @model.h:2000 info| dwahjdiawdjaiwdwadwa djaidjwa\n
31 * | djwaidwaj waodawh a\n
36 SDL_AtomicLock( &log_print_sl
);
41 vsnprintf( buffer
, vg_list_size(buffer
), fmt
, args
);
43 const char *line
= buffer
;
46 for( u32 i
=0; i
<vg_list_size(buffer
); i
++ ){
49 if( c
== '\0' || c
== '\n' ){
52 const char *line_prefix
= "",
55 if( line
== buffer
) {
57 line_location
= location
;
60 snprintf( logline
, 96, "%s%7s" KNRM
"|%s %s",
61 colour
, line_prefix
, colour
, line
);
62 _vg_log_append_line( logline
);
66 const char *thread_colours
[] = {
67 KGRN
, KMAG
, KCYN
, KYEL
, KBLU
70 const char *colour
= thread_colours
[
71 (vg_thread_purpose() % vg_list_size( thread_colours
))];
73 fprintf( file
, "%s[%u]"KNRM
"%.32s",
74 colour
, vg_thread_purpose(), line_location
);
76 fprintf( file
, KNRM
"%.32s", line_location
);
80 fputs( logline
, file
);
84 if( c
== '\0' ) break;
85 if( buffer
[i
+1] == '\0' ) break;
91 SDL_AtomicUnlock( &log_print_sl
);
95 static void vg_logx( FILE *file
,
96 const char *location
, const char *prefix
,
98 const char *fmt
, ... ){
101 va_start( args
, fmt
);
103 #ifdef VG_LOG_SOURCE_INFO
108 prefix
, colour
, fmt
, args
);
112 static void vg_print_backtrace(void){
119 size
= backtrace( array
, 20 );
120 strings
= backtrace_symbols( array
, size
);
122 if( strings
!= NULL
){
123 vg_error( "---------------- gnu backtrace -------------\n" );
125 for( int i
=0; i
<size
; i
++ )
126 vg_info( "%s\n", strings
[i
] );
128 vg_error( "---------------- gnu backtrace -------------\n" );
136 #endif /* VG_LOG_C */