blob: 6abb13c93b80b418e1f35c481ee0d821d570ca57 [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;
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 */
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020029 if (fmt & BIT(LOGF_LEVEL))
Simon Glassdeca50f2017-12-28 13:14:18 -070030 printf("%s.", log_get_level_name(rec->level));
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020031 if (fmt & BIT(LOGF_CAT))
Simon Glassdeca50f2017-12-28 13:14:18 -070032 printf("%s,", log_get_cat_name(rec->cat));
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020033 if (fmt & BIT(LOGF_FILE))
Simon Glassdeca50f2017-12-28 13:14:18 -070034 printf("%s:", rec->file);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020035 if (fmt & BIT(LOGF_LINE))
Simon Glassdeca50f2017-12-28 13:14:18 -070036 printf("%d-", rec->line);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020037 if (fmt & BIT(LOGF_FUNC))
Simon Glassdeca50f2017-12-28 13:14:18 -070038 printf("%s()", rec->func);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020039 if (fmt & BIT(LOGF_MSG))
40 printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
Simon Glassc6d47532017-12-04 13:48:25 -070041
42 return 0;
43}
44
45LOG_DRIVER(console) = {
46 .name = "console",
47 .emit = log_console_emit,
Simon Glassb4520302020-09-12 12:28:47 -060048 .flags = LOGDF_ENABLE,
Simon Glassc6d47532017-12-04 13:48:25 -070049};