log_console.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Logging support
  3. *
  4. * Copyright (c) 2017 Google, Inc
  5. * Written by Simon Glass <sjg@chromium.org>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <log.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
  13. {
  14. int fmt = gd->log_fmt;
  15. /*
  16. * The output format is designed to give someone a fighting chance of
  17. * figuring out which field is which:
  18. * - level is in CAPS
  19. * - cat is lower case and ends with comma
  20. * - file normally has a .c extension and ends with a colon
  21. * - line is integer and ends with a -
  22. * - function is an identifier and ends with ()
  23. * - message has a space before it unless it is on its own
  24. */
  25. if (fmt & (1 << LOGF_LEVEL))
  26. printf("%s.", log_get_level_name(rec->level));
  27. if (fmt & (1 << LOGF_CAT))
  28. printf("%s,", log_get_cat_name(rec->cat));
  29. if (fmt & (1 << LOGF_FILE))
  30. printf("%s:", rec->file);
  31. if (fmt & (1 << LOGF_LINE))
  32. printf("%d-", rec->line);
  33. if (fmt & (1 << LOGF_FUNC))
  34. printf("%s()", rec->func);
  35. if (fmt & (1 << LOGF_MSG))
  36. printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);
  37. return 0;
  38. }
  39. LOG_DRIVER(console) = {
  40. .name = "console",
  41. .emit = log_console_emit,
  42. };