Guest User

Untitled

a guest
Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. //
  2. // Created by hyotiger on 12/14/18.
  3. //
  4.  
  5. //
  6. // Created by hyotiger on 12/13/18.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include "simplog.h"
  12.  
  13. static unsigned int simplog_run_level = SIMP_LOG_LVL_NEVER;
  14.  
  15. static const char * simplog_level_strings [] = {
  16. "NONE", // 0
  17. " ERR", // 1
  18. "WARN", // 2
  19. "INFO", // 3
  20. " DBG", // 4
  21. " ALL" // 5
  22. };
  23.  
  24. static void simplog_write(int level, const char *funcname, unsigned int linenum, const char *str, ...)
  25. {
  26. va_list args;
  27. va_start(args, str);
  28.  
  29. if ( level <= simplog_run_level) {
  30. char fmt[1024];
  31. snprintf(fmt, sizeof(fmt), "[%s %s:%d] %s\n", simplog_level_strings[level], funcname, linenum, str);
  32. vfprintf( stdout, fmt, args);
  33. }
  34.  
  35. va_end( args );
  36. }
  37.  
  38. static void simplog_set_loglevel(unsigned char level) {
  39. fprintf(stdout, "[SIMPLOG] LOG level is changed from %s to %s\n", simplog_level_strings[simplog_run_level], simplog_level_strings[level]);
  40. simplog_run_level = level;
  41. }
  42.  
  43. simplelog_namespace const simplog = {
  44. .SetLogLevel = simplog_set_loglevel,
  45. .WriteLog = simplog_write,
  46. };
Add Comment
Please, Sign In to add comment