2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-12-04 20:48:25 +00:00
|
|
|
/*
|
|
|
|
* Logging support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <log.h>
|
|
|
|
|
2017-12-28 20:14:18 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-12-04 20:48:25 +00:00
|
|
|
static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
|
|
|
|
{
|
2017-12-28 20:14:18 +00:00
|
|
|
int fmt = gd->log_fmt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The output format is designed to give someone a fighting chance of
|
|
|
|
* figuring out which field is which:
|
|
|
|
* - level is in CAPS
|
|
|
|
* - cat is lower case and ends with comma
|
|
|
|
* - file normally has a .c extension and ends with a colon
|
|
|
|
* - line is integer and ends with a -
|
|
|
|
* - function is an identifier and ends with ()
|
|
|
|
* - message has a space before it unless it is on its own
|
|
|
|
*/
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_LEVEL))
|
2017-12-28 20:14:18 +00:00
|
|
|
printf("%s.", log_get_level_name(rec->level));
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_CAT))
|
2017-12-28 20:14:18 +00:00
|
|
|
printf("%s,", log_get_cat_name(rec->cat));
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_FILE))
|
2017-12-28 20:14:18 +00:00
|
|
|
printf("%s:", rec->file);
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_LINE))
|
2017-12-28 20:14:18 +00:00
|
|
|
printf("%d-", rec->line);
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_FUNC))
|
2017-12-28 20:14:18 +00:00
|
|
|
printf("%s()", rec->func);
|
2020-06-17 19:52:45 +00:00
|
|
|
if (fmt & BIT(LOGF_MSG))
|
|
|
|
printf("%s%s", fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
|
2017-12-04 20:48:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DRIVER(console) = {
|
|
|
|
.name = "console",
|
|
|
|
.emit = log_console_emit,
|
|
|
|
};
|