Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c6d4753 | 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 | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 12 | |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 15 | static int log_console_emit(struct log_device *ldev, struct log_rec *rec) |
| 16 | { |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 17 | int fmt = gd->log_fmt; |
Simon Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 18 | bool add_space = false; |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 19 | |
| 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 Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 30 | 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 Glass | f9ebfd7 | 2023-07-15 21:39:14 -0600 | [diff] [blame] | 40 | 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 Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 48 | } |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 49 | if (fmt & BIT(LOGF_MSG)) |
Simon Glass | 9ad7a6c | 2021-01-20 20:10:53 -0700 | [diff] [blame] | 50 | printf("%s%s", add_space ? " " : "", rec->msg); |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | LOG_DRIVER(console) = { |
| 56 | .name = "console", |
| 57 | .emit = log_console_emit, |
Simon Glass | b452030 | 2020-09-12 12:28:47 -0600 | [diff] [blame] | 58 | .flags = LOGDF_ENABLE, |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 59 | }; |