log_console.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. DECLARE_GLOBAL_DATA_PTR;
  11. static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
  12. {
  13. int fmt = gd->log_fmt;
  14. /*
  15. * The output format is designed to give someone a fighting chance of
  16. * figuring out which field is which:
  17. * - level is in CAPS
  18. * - cat is lower case and ends with comma
  19. * - file normally has a .c extension and ends with a colon
  20. * - line is integer and ends with a -
  21. * - function is an identifier and ends with ()
  22. * - message has a space before it unless it is on its own
  23. */
  24. if (fmt & (1 << LOGF_LEVEL))
  25. printf("%s.", log_get_level_name(rec->level));
  26. if (fmt & (1 << LOGF_CAT))
  27. printf("%s,", log_get_cat_name(rec->cat));
  28. if (fmt & (1 << LOGF_FILE))
  29. printf("%s:", rec->file);
  30. if (fmt & (1 << LOGF_LINE))
  31. printf("%d-", rec->line);
  32. if (fmt & (1 << LOGF_FUNC))
  33. printf("%s()", rec->func);
  34. if (fmt & (1 << LOGF_MSG))
  35. printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);
  36. return 0;
  37. }
  38. LOG_DRIVER(console) = {
  39. .name = "console",
  40. .emit = log_console_emit,
  41. };