blob: 3f6177499ef9394e0cc1b52b92eef27e46ac9f54 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassa68ce922017-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 Glassa68ce922017-12-04 13:48:25 -07007 */
8
9#include <common.h>
10#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glassa68ce922017-12-04 13:48:25 -070012
Simon Glass44e57632017-12-28 13:14:18 -070013DECLARE_GLOBAL_DATA_PTR;
14
Simon Glassa68ce922017-12-04 13:48:25 -070015static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
16{
Simon Glass44e57632017-12-28 13:14:18 -070017 int fmt = gd->log_fmt;
Simon Glass5fc47e32021-01-20 20:10:53 -070018 bool add_space = false;
Simon Glass44e57632017-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 Glass5fc47e32021-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);
40 if (fmt & BIT(LOGF_FUNC))
41 printf("%s()", rec->func);
42 }
Heinrich Schuchardtadd83a32020-06-17 21:52:45 +020043 if (fmt & BIT(LOGF_MSG))
Simon Glass5fc47e32021-01-20 20:10:53 -070044 printf("%s%s", add_space ? " " : "", rec->msg);
Simon Glassa68ce922017-12-04 13:48:25 -070045
46 return 0;
47}
48
49LOG_DRIVER(console) = {
50 .name = "console",
51 .emit = log_console_emit,
Simon Glass885cf5f2020-09-12 12:28:47 -060052 .flags = LOGDF_ENABLE,
Simon Glassa68ce922017-12-04 13:48:25 -070053};