]> Git Repo - J-u-boot.git/blob - common/log_console.c
xyz-modem: Add missing fallthrough annotation
[J-u-boot.git] / common / log_console.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Logging support
4  *
5  * Copyright (c) 2017 Google, Inc
6  * Written by Simon Glass <[email protected]>
7  */
8
9 #include <log.h>
10 #include <asm/global_data.h>
11
12 DECLARE_GLOBAL_DATA_PTR;
13
14 static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
15 {
16         int fmt = gd->log_fmt;
17         bool add_space = false;
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          */
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);
39                 if (fmt & BIT(LOGF_FUNC)) {
40                         if (CONFIG_IS_ENABLED(USE_TINY_PRINTF)) {
41                                 printf("%s()", rec->func ?: "?");
42                         } else {
43                                 printf("%*s()", CONFIG_LOGF_FUNC_PAD,
44                                        rec->func ?: "?");
45                         }
46                 }
47         }
48         if (fmt & BIT(LOGF_MSG))
49                 printf("%s%s", add_space ? " " : "", rec->msg);
50
51         return 0;
52 }
53
54 LOG_DRIVER(console) = {
55         .name   = "console",
56         .emit   = log_console_emit,
57         .flags  = LOGDF_ENABLE,
58 };
This page took 0.026145 seconds and 4 git commands to generate.