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 | |
| 9 | #include <common.h> |
| 10 | #include <log.h> |
| 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; |
| 17 | |
| 18 | /* |
| 19 | * The output format is designed to give someone a fighting chance of |
| 20 | * figuring out which field is which: |
| 21 | * - level is in CAPS |
| 22 | * - cat is lower case and ends with comma |
| 23 | * - file normally has a .c extension and ends with a colon |
| 24 | * - line is integer and ends with a - |
| 25 | * - function is an identifier and ends with () |
| 26 | * - message has a space before it unless it is on its own |
| 27 | */ |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 28 | if (fmt & BIT(LOGF_LEVEL)) |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 29 | printf("%s.", log_get_level_name(rec->level)); |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 30 | if (fmt & BIT(LOGF_CAT)) |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 31 | printf("%s,", log_get_cat_name(rec->cat)); |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 32 | if (fmt & BIT(LOGF_FILE)) |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 33 | printf("%s:", rec->file); |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 34 | if (fmt & BIT(LOGF_LINE)) |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 35 | printf("%d-", rec->line); |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 36 | if (fmt & BIT(LOGF_FUNC)) |
Simon Glass | 44e5763 | 2017-12-28 13:14:18 -0700 | [diff] [blame] | 37 | printf("%s()", rec->func); |
Heinrich Schuchardt | add83a3 | 2020-06-17 21:52:45 +0200 | [diff] [blame] | 38 | if (fmt & BIT(LOGF_MSG)) |
| 39 | printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg); |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | LOG_DRIVER(console) = { |
| 45 | .name = "console", |
| 46 | .emit = log_console_emit, |
Simon Glass | 885cf5f | 2020-09-12 12:28:47 -0600 | [diff] [blame] | 47 | .flags = LOGDF_ENABLE, |
Simon Glass | a68ce92 | 2017-12-04 13:48:25 -0700 | [diff] [blame] | 48 | }; |