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; |
| 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 | */ |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 29 | if (fmt & BIT(LOGF_LEVEL)) |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 30 | printf("%s.", log_get_level_name(rec->level)); |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 31 | if (fmt & BIT(LOGF_CAT)) |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 32 | printf("%s,", log_get_cat_name(rec->cat)); |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 33 | if (fmt & BIT(LOGF_FILE)) |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 34 | printf("%s:", rec->file); |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 35 | if (fmt & BIT(LOGF_LINE)) |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 36 | printf("%d-", rec->line); |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 37 | if (fmt & BIT(LOGF_FUNC)) |
Simon Glass | deca50f | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 38 | printf("%s()", rec->func); |
Heinrich Schuchardt | dde173a | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 39 | if (fmt & BIT(LOGF_MSG)) |
| 40 | printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg); |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | LOG_DRIVER(console) = { |
| 46 | .name = "console", |
| 47 | .emit = log_console_emit, |
Simon Glass | b452030 | 2020-09-12 12:28:47 -0600 | [diff] [blame] | 48 | .flags = LOGDF_ENABLE, |
Simon Glass | c6d4753 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 49 | }; |