blob: bb091ce21a4a616e763406b4f4c8e1a61acd0932 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc6d47532017-12-04 13:48:25 -07002/*
3 * Logging support
4 *
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
Simon Glassc6d47532017-12-04 13:48:25 -07007 */
8
9#include <common.h>
10#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glassc6d47532017-12-04 13:48:25 -070012
Simon Glassdeca50f2017-12-28 13:14:18 -070013DECLARE_GLOBAL_DATA_PTR;
14
Simon Glassc6d47532017-12-04 13:48:25 -070015static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
16{
Simon Glassdeca50f2017-12-28 13:14:18 -070017 int fmt = gd->log_fmt;
Simon Glass9ad7a6c2021-01-20 20:10:53 -070018 bool add_space = false;
Simon Glassdeca50f2017-12-28 13:14:18 -070019
20 /*
21 * The output format is designed to give someone a fighting chance of
22 * figuring out which field is which:
23 * - level is in CAPS
24 * - cat is lower case and ends with comma
25 * - file normally has a .c extension and ends with a colon
26 * - line is integer and ends with a -
27 * - function is an identifier and ends with ()
28 * - message has a space before it unless it is on its own
29 */
Simon Glass9ad7a6c2021-01-20 20:10:53 -070030 if (!(rec->flags & LOGRECF_CONT) && fmt != BIT(LOGF_MSG)) {
31 add_space = true;
32 if (fmt & BIT(LOGF_LEVEL))
33 printf("%s.", log_get_level_name(rec->level));
34 if (fmt & BIT(LOGF_CAT))
35 printf("%s,", log_get_cat_name(rec->cat));
36 if (fmt & BIT(LOGF_FILE))
37 printf("%s:", rec->file);
38 if (fmt & BIT(LOGF_LINE))
39 printf("%d-", rec->line);
Simon Glassf9ebfd72023-07-15 21:39:14 -060040 if (fmt & BIT(LOGF_FUNC)) {
41 if (CONFIG_IS_ENABLED(USE_TINY_PRINTF)) {
42 printf("%s()", rec->func);
43 } else {
44 printf("%*s()", CONFIG_LOGF_FUNC_PAD,
45 rec->func);
46 }
47 }
Simon Glass9ad7a6c2021-01-20 20:10:53 -070048 }
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020049 if (fmt & BIT(LOGF_MSG))
Simon Glass9ad7a6c2021-01-20 20:10:53 -070050 printf("%s%s", add_space ? " " : "", rec->msg);
Simon Glassc6d47532017-12-04 13:48:25 -070051
52 return 0;
53}
54
55LOG_DRIVER(console) = {
56 .name = "console",
57 .emit = log_console_emit,
Simon Glassb4520302020-09-12 12:28:47 -060058 .flags = LOGDF_ENABLE,
Simon Glassc6d47532017-12-04 13:48:25 -070059};