log_console.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. bool add_space = false;
  16. /*
  17. * The output format is designed to give someone a fighting chance of
  18. * figuring out which field is which:
  19. * - level is in CAPS
  20. * - cat is lower case and ends with comma
  21. * - file normally has a .c extension and ends with a colon
  22. * - line is integer and ends with a -
  23. * - function is an identifier and ends with ()
  24. * - message has a space before it unless it is on its own
  25. */
  26. if (!(rec->flags & LOGRECF_CONT) && fmt != BIT(LOGF_MSG)) {
  27. add_space = true;
  28. if (fmt & BIT(LOGF_LEVEL))
  29. printf("%s.", log_get_level_name(rec->level));
  30. if (fmt & BIT(LOGF_CAT))
  31. printf("%s,", log_get_cat_name(rec->cat));
  32. if (fmt & BIT(LOGF_FILE))
  33. printf("%s:", rec->file);
  34. if (fmt & BIT(LOGF_LINE))
  35. printf("%d-", rec->line);
  36. if (fmt & BIT(LOGF_FUNC))
  37. printf("%*s()", CONFIG_LOGF_FUNC_PAD, rec->func);
  38. }
  39. if (fmt & BIT(LOGF_MSG))
  40. printf("%s%s", add_space ? " " : "", rec->msg);
  41. return 0;
  42. }
  43. LOG_DRIVER(console) = {
  44. .name = "console",
  45. .emit = log_console_emit,
  46. .flags = LOGDF_ENABLE,
  47. };