log_console.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Logging support
  4. *
  5. * Copyright (c) 2017 Google, Inc
  6. * Written by Simon Glass <sjg@chromium.org>
  7. */
  8. #include <common.h>
  9. #include <log.h>
  10. #include <asm/global_data.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 & BIT(LOGF_LEVEL))
  26. printf("%s.", log_get_level_name(rec->level));
  27. if (fmt & BIT(LOGF_CAT))
  28. printf("%s,", log_get_cat_name(rec->cat));
  29. if (fmt & BIT(LOGF_FILE))
  30. printf("%s:", rec->file);
  31. if (fmt & BIT(LOGF_LINE))
  32. printf("%d-", rec->line);
  33. if (fmt & BIT(LOGF_FUNC))
  34. printf("%s()", rec->func);
  35. if (fmt & BIT(LOGF_MSG))
  36. printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
  37. return 0;
  38. }
  39. LOG_DRIVER(console) = {
  40. .name = "console",
  41. .emit = log_console_emit,
  42. .flags = LOGDF_ENABLE,
  43. };