mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-16 06:19:24 +00:00
DM: add log macro/func and basic data structure.
also set default logger as console and enabled. Tracked-On: #3012 Signed-off-by: Minggui Cao <minggui.cao@intel.com> Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
53
devicemodel/include/log.h
Normal file
53
devicemodel/include/log.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __LOG_H__
|
||||
#define __LOG_H__
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/* Logging severity levels */
|
||||
#define LOG_ERROR 1U
|
||||
#define LOG_WARNING 2U
|
||||
#define LOG_NOTICE 3U
|
||||
#define LOG_INFO 4U
|
||||
#define LOG_DEBUG 5U
|
||||
|
||||
#define DEFAULT_LOG_LEVEL 4
|
||||
#define MAX_ONE_LOG_SIZE 256
|
||||
|
||||
struct logger_ops {
|
||||
const char *name;
|
||||
bool (*is_enabled)(void);
|
||||
uint8_t (*get_log_level)(void);
|
||||
int (*init)(bool enable, uint8_t log_level);
|
||||
void (*deinit)(void);
|
||||
void (*output)(const char *fmt, va_list args);
|
||||
};
|
||||
|
||||
void init_logger_setting(const char *opt);
|
||||
void output_log(uint8_t level, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
* Put all logger instances' addresses into one section named logger_dev_ops
|
||||
* so that DM could enumerate and initialize each of them.
|
||||
*/
|
||||
#define DECLARE_LOGGER_SECTION() SET_DECLARE(logger_dev_ops, struct logger_ops)
|
||||
#define DEFINE_LOGGER_DEVICE(x) DATA_SET(logger_dev_ops, x)
|
||||
#define FOR_EACH_LOGGER(pp_logger) SET_FOREACH(pp_logger, logger_dev_ops)
|
||||
|
||||
|
||||
#ifndef pr_prefix
|
||||
#define pr_prefix
|
||||
#endif
|
||||
|
||||
#define pr_err(...) output_log(LOG_ERROR, pr_prefix __VA_ARGS__)
|
||||
#define pr_warn(...) output_log(LOG_WARNING, pr_prefix __VA_ARGS__)
|
||||
#define pr_notice(...) output_log(LOG_NOTICE, pr_prefix __VA_ARGS__)
|
||||
#define pr_info(...) output_log(LOG_INFO, pr_prefix __VA_ARGS__)
|
||||
#define pr_dbg(...) output_log(LOG_DEBUG, pr_prefix __VA_ARGS__)
|
||||
|
||||
#endif /* __LOG_H__ */
|
Reference in New Issue
Block a user