blob: c27101b8fe2237e0e2ef09b58a238fd8792a8c67 [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
Simon Glassa68ce922017-12-04 13:48:25 -07009#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Simon Glassa68ce922017-12-04 13:48:25 -070011
Simon Glass44e57632017-12-28 13:14:18 -070012DECLARE_GLOBAL_DATA_PTR;
13
Simon Glassa68ce922017-12-04 13:48:25 -070014static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
15{
Simon Glass44e57632017-12-28 13:14:18 -070016 int fmt = gd->log_fmt;
Simon Glass5fc47e32021-01-20 20:10:53 -070017 bool add_space = false;
Simon Glass44e57632017-12-28 13:14:18 -070018
19 /*
20 * The output format is designed to give someone a fighting chance of
21 * figuring out which field is which:
22 * - level is in CAPS
23 * - cat is lower case and ends with comma
24 * - file normally has a .c extension and ends with a colon
25 * - line is integer and ends with a -
26 * - function is an identifier and ends with ()
27 * - message has a space before it unless it is on its own
28 */
Simon Glass5fc47e32021-01-20 20:10:53 -070029 if (!(rec->flags & LOGRECF_CONT) && fmt != BIT(LOGF_MSG)) {
30 add_space = true;
31 if (fmt & BIT(LOGF_LEVEL))
32 printf("%s.", log_get_level_name(rec->level));
33 if (fmt & BIT(LOGF_CAT))
34 printf("%s,", log_get_cat_name(rec->cat));
35 if (fmt & BIT(LOGF_FILE))
36 printf("%s:", rec->file);
37 if (fmt & BIT(LOGF_LINE))
38 printf("%d-", rec->line);
Simon Glass5e89ebb2023-07-15 21:39:14 -060039 if (fmt & BIT(LOGF_FUNC)) {
40 if (CONFIG_IS_ENABLED(USE_TINY_PRINTF)) {
41 printf("%s()", rec->func);
42 } else {
43 printf("%*s()", CONFIG_LOGF_FUNC_PAD,
44 rec->func);
45 }
46 }
Simon Glass5fc47e32021-01-20 20:10:53 -070047 }
Heinrich Schuchardtadd83a32020-06-17 21:52:45 +020048 if (fmt & BIT(LOGF_MSG))
Simon Glass5fc47e32021-01-20 20:10:53 -070049 printf("%s%s", add_space ? " " : "", rec->msg);
Simon Glassa68ce922017-12-04 13:48:25 -070050
51 return 0;
52}
53
54LOG_DRIVER(console) = {
55 .name = "console",
56 .emit = log_console_emit,
Simon Glass885cf5f2020-09-12 12:28:47 -060057 .flags = LOGDF_ENABLE,
Simon Glassa68ce922017-12-04 13:48:25 -070058};