diff options
Diffstat (limited to 'src/log/log.c')
-rw-r--r-- | src/log/log.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/log/log.c b/src/log/log.c new file mode 100644 index 0000000..a390421 --- /dev/null +++ b/src/log/log.c @@ -0,0 +1,31 @@ + +#include "log.h" + +/* System */ +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + + +void log_asdfghjklqwertzu( const char*level, const char*cLvl, const char*file, int line, const char*fmt, ... ) +{ + va_list args; + va_start( args, fmt ); + int isTTY = isatty(2); + const char *cRst = isTTY ? "\033[0m" : ""; + char *cTxt = isTTY ? "\033[90m" : ""; + cLvl = isTTY ? cLvl : ""; + char tBuf[20]; + const time_t t = time(0); + const char *tfmt = "%Y-%m-%d_%H:%M:%S"; + if( isTTY ){ tfmt += 9; } + strftime( tBuf,sizeof(tBuf), tfmt, localtime(&t) ); + const char *fileOnly = strrchr(file, '/') +1; + fprintf( stderr, "[%s%s%s %s%s%s %s%s:%d%s] ", + cTxt,tBuf,cRst, cLvl,level,cRst , cTxt,fileOnly,line,cRst ); + vfprintf( stderr, fmt, args ); + va_end( args ); +} + |