xref: /openbmc/u-boot/common/log_console.c (revision aa5e3e22)
1 /*
2  * Logging support
3  *
4  * Copyright (c) 2017 Google, Inc
5  * Written by Simon Glass <sjg@chromium.org>
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <log.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
16 {
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 	 */
29 	if (fmt & (1 << LOGF_LEVEL))
30 		printf("%s.", log_get_level_name(rec->level));
31 	if (fmt & (1 << LOGF_CAT))
32 		printf("%s,", log_get_cat_name(rec->cat));
33 	if (fmt & (1 << LOGF_FILE))
34 		printf("%s:", rec->file);
35 	if (fmt & (1 << LOGF_LINE))
36 		printf("%d-", rec->line);
37 	if (fmt & (1 << LOGF_FUNC))
38 		printf("%s()", rec->func);
39 	if (fmt & (1 << LOGF_MSG))
40 		printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);
41 
42 	return 0;
43 }
44 
45 LOG_DRIVER(console) = {
46 	.name	= "console",
47 	.emit	= log_console_emit,
48 };
49