ua_log_stdout.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  5. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  6. #include <stdio.h>
  7. #include <stdarg.h>
  8. #include "ua_log_stdout.h"
  9. #include "ua_types_generated.h"
  10. #include "ua_types_generated_handling.h"
  11. const char *LogLevelNames[6] = {"trace", "debug", "info", "warning", "error", "fatal"};
  12. const char *LogCategoryNames[6] = {"network", "channel", "session", "server", "client", "userland"};
  13. #if (defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
  14. # pragma GCC diagnostic push
  15. # pragma GCC diagnostic ignored "-Wformat-nonliteral"
  16. #endif
  17. void UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
  18. UA_String t = UA_DateTime_toString(UA_DateTime_now());
  19. printf("[%.23s] %s/%s\t", t.data, LogLevelNames[level], LogCategoryNames[category]);
  20. UA_ByteString_deleteMembers(&t);
  21. va_list ap;
  22. va_start(ap, msg);
  23. vprintf(msg, ap);
  24. va_end(ap);
  25. printf("\n");
  26. }
  27. #if (defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
  28. # pragma GCC diagnostic pop
  29. #endif