blob: bb3f8464b986d3eaaf972437b396b72d2b70d8c3 [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>
11
Simon Glassdeca50f2017-12-28 13:14:18 -070012DECLARE_GLOBAL_DATA_PTR;
13
Simon Glassc6d47532017-12-04 13:48:25 -070014static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
15{
Simon Glassdeca50f2017-12-28 13:14:18 -070016 int fmt = gd->log_fmt;
17
18 /*
19 * The output format is designed to give someone a fighting chance of
20 * figuring out which field is which:
21 * - level is in CAPS
22 * - cat is lower case and ends with comma
23 * - file normally has a .c extension and ends with a colon
24 * - line is integer and ends with a -
25 * - function is an identifier and ends with ()
26 * - message has a space before it unless it is on its own
27 */
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020028 if (fmt & BIT(LOGF_LEVEL))
Simon Glassdeca50f2017-12-28 13:14:18 -070029 printf("%s.", log_get_level_name(rec->level));
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020030 if (fmt & BIT(LOGF_CAT))
Simon Glassdeca50f2017-12-28 13:14:18 -070031 printf("%s,", log_get_cat_name(rec->cat));
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020032 if (fmt & BIT(LOGF_FILE))
Simon Glassdeca50f2017-12-28 13:14:18 -070033 printf("%s:", rec->file);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020034 if (fmt & BIT(LOGF_LINE))
Simon Glassdeca50f2017-12-28 13:14:18 -070035 printf("%d-", rec->line);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020036 if (fmt & BIT(LOGF_FUNC))
Simon Glassdeca50f2017-12-28 13:14:18 -070037 printf("%s()", rec->func);
Heinrich Schuchardtdde173a2020-06-17 21:52:45 +020038 if (fmt & BIT(LOGF_MSG))
39 printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
Simon Glassc6d47532017-12-04 13:48:25 -070040
41 return 0;
42}
43
44LOG_DRIVER(console) = {
45 .name = "console",
46 .emit = log_console_emit,
47};