blob: 3f6177499ef9394e0cc1b52b92eef27e46ac9f54 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc6d47532017-12-04 13:48:25 -07002/*
3 * Logging support
4 *
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
Simon Glassc6d47532017-12-04 13:48:25 -07007 */
8
9#include <common.h>
10#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glassc6d47532017-12-04 13:48:25 -070012
Simon Glassdeca50f2017-12-28 13:14:18 -070013DECLARE_GLOBAL_DATA_PTR;
14
Simon Glassc6d47532017-12-04 13:48:25 -070015static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
16{
Simon Glassdeca50f2017-12-28 13:14:18 -070017 int fmt = gd->log_fmt;
Simon Glass9ad7a6c2021-01-20 20:10:53 -070018 bool add_space = false;
Simon Glassdeca50f2017-12-28 13:14:18 -070019
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 */
Simon Glass9ad7a6c2021-01-20 20:10:53 -070030 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))
41 printf("%s()", rec->func);
42 }
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020043 if (fmt & BIT(LOGF_MSG))
Simon Glass9ad7a6c2021-01-20 20:10:53 -070044 printf("%s%s", add_space ? " " : "", rec->msg);
Simon Glassc6d47532017-12-04 13:48:25 -070045
46 return 0;
47}
48
49LOG_DRIVER(console) = {
50 .name = "console",
51 .emit = log_console_emit,
Simon Glassb4520302020-09-12 12:28:47 -060052 .flags = LOGDF_ENABLE,
Simon Glassc6d47532017-12-04 13:48:25 -070053};