acrn-hypervisor/misc/services/life_mngr/log.h
Ziheng Li eb8bcb06b3 Update copyright year range in code headers
Modified the copyright year range in code, and corrected "int32_tel"
into "Intel" in two "hypervisor/include/debug/profiling.h" and
"hypervisor/include/debug/profiling_internal.h".

Tracked-On: #7559
Signed-off-by: Ziheng Li <ziheng.li@intel.com>
2022-07-15 11:48:35 +08:00

45 lines
914 B
C

/*
* Copyright (C)2021-2022 Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _LOG_H_
#define _LOG_H_
#include <time.h>
extern FILE *log_fd;
static inline void output_timestamp(void)
{
struct tm *t;
time_t tt;
time(&tt);
t = localtime(&tt);
fprintf(log_fd, "[%4d-%02d-%02d %02d:%02d:%02d]", t->tm_year + 1900, \
t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
}
#define LOG_PRINTF(format, args...) \
do { output_timestamp(); \
fprintf(log_fd, format, args); \
fflush(log_fd); } while (0)
#define LOG_WRITE(args) \
do { output_timestamp(); \
fwrite(args, 1, sizeof(args), log_fd); \
fflush(log_fd); } while (0)
static inline bool open_log(const char *path)
{
bool ret = false;
log_fd = fopen("/var/log/life_mngr.log", "a+");
if (log_fd != NULL)
ret = true;
return ret;
}
static inline void close_log(void)
{
if (log_fd != NULL)
fclose(log_fd);
}
#endif