Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Logging support |
| 4 | * |
| 5 | * Copyright (c) 2017 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 11 | |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 14 | static int log_console_emit(struct log_device *ldev, struct log_rec *rec) |
| 15 | { |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 16 | int fmt = gd->log_fmt; |
Simon Glass | 5fc47e3 | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 17 | bool add_space = false; |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 18 | |
| 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 Glass | 5fc47e3 | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 29 | 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 Glass | 5e89ebb | 2023-07-15 21:39:14 -0600 | [diff] [blame] | 39 | if (fmt & BIT(LOGF_FUNC)) { |
| 40 | if (CONFIG_IS_ENABLED(USE_TINY_PRINTF)) { |
Simon Glass | fa55f42 | 2024-08-22 07:54:56 -0600 | [diff] [blame] | 41 | printf("%s()", rec->func ?: "?"); |
Simon Glass | 5e89ebb | 2023-07-15 21:39:14 -0600 | [diff] [blame] | 42 | } else { |
| 43 | printf("%*s()", CONFIG_LOGF_FUNC_PAD, |
Simon Glass | fa55f42 | 2024-08-22 07:54:56 -0600 | [diff] [blame] | 44 | rec->func ?: "?"); |
Simon Glass | 5e89ebb | 2023-07-15 21:39:14 -0600 | [diff] [blame] | 45 | } |
| 46 | } |
Simon Glass | 5fc47e3 | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 47 | } |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 48 | if (fmt & BIT(LOGF_MSG)) |
Simon Glass | 5fc47e3 | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 49 | printf("%s%s", add_space ? " " : "", rec->msg); |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | LOG_DRIVER(console) = { |
| 55 | .name = "console", |
| 56 | .emit = log_console_emit, |
Simon Glass | 885cf5f | 2020-09-12 12:28:47 -0600 | [diff] [blame] | 57 | .flags = LOGDF_ENABLE, |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 58 | }; |