Log.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "util/log/Log.h"
  16. #include "util/log/Log_impl.h"
  17. #include "util/CString.h"
  18. #include <stdarg.h>
  19. void Log_print(struct Log* log,
  20. enum Log_Level logLevel,
  21. const char* file,
  22. int line,
  23. const char* format,
  24. ...)
  25. {
  26. va_list args;
  27. va_start(args, format);
  28. log->print(log, logLevel, file, line, format, args);
  29. va_end(args);
  30. }
  31. char* Log_nameForLevel(enum Log_Level logLevel)
  32. {
  33. switch (logLevel) {
  34. case Log_Level_KEYS: return "KEYS";
  35. case Log_Level_DEBUG: return "DEBUG";
  36. case Log_Level_INFO: return "INFO";
  37. case Log_Level_WARN: return "WARN";
  38. case Log_Level_ERROR: return "ERROR";
  39. case Log_Level_CRITICAL: return "CRITICAL";
  40. default: return "INVALID";
  41. }
  42. }
  43. enum Log_Level Log_levelForName(char* name)
  44. {
  45. for (enum Log_Level logLevel = Log_Level_KEYS; logLevel <= Log_Level_CRITICAL; logLevel++) {
  46. if (!CString_strcasecmp(name, Log_nameForLevel(logLevel))) {
  47. return logLevel;
  48. }
  49. }
  50. return Log_Level_INVALID;
  51. }