]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
c6d47535 SG |
2 | /* |
3 | * Logging support | |
4 | * | |
5 | * Copyright (c) 2017 Google, Inc | |
6 | * Written by Simon Glass <[email protected]> | |
c6d47535 SG |
7 | */ |
8 | ||
9 | #include <common.h> | |
10 | #include <log.h> | |
401d1c4f | 11 | #include <asm/global_data.h> |
c6d47535 | 12 | |
deca50fb SG |
13 | DECLARE_GLOBAL_DATA_PTR; |
14 | ||
c6d47535 SG |
15 | static int log_console_emit(struct log_device *ldev, struct log_rec *rec) |
16 | { | |
deca50fb | 17 | int fmt = gd->log_fmt; |
9ad7a6c2 | 18 | bool add_space = false; |
deca50fb SG |
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 | */ | |
9ad7a6c2 SG |
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); | |
40 | if (fmt & BIT(LOGF_FUNC)) | |
72fa1ad8 | 41 | printf("%*s()", CONFIG_LOGF_FUNC_PAD, rec->func); |
9ad7a6c2 | 42 | } |
dde173a2 | 43 | if (fmt & BIT(LOGF_MSG)) |
9ad7a6c2 | 44 | printf("%s%s", add_space ? " " : "", rec->msg); |
c6d47535 SG |
45 | |
46 | return 0; | |
47 | } | |
48 | ||
49 | LOG_DRIVER(console) = { | |
50 | .name = "console", | |
51 | .emit = log_console_emit, | |
b4520300 | 52 | .flags = LOGDF_ENABLE, |
c6d47535 | 53 | }; |