From ac0c0aa29527d00cca431c5cc3aaa372864c8fcd Mon Sep 17 00:00:00 2001 From: zhangtaohz Date: Wed, 24 Jul 2019 11:38:32 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=20aaa-12=20add=20ulog=20lib=20code=20RCA?= =?UTF-8?q?=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A?= =?UTF-8?q?zhangtao=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/ulog_api.h | 23 +++++++++ Makefile | 3 ++ Platform/build/user.ulog.api.Makefile | 65 ++++++++++++++++++++++++++ Platform/user/ulog/ulog-api/ulog_api.c | 51 ++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100755 Common/ulog_api.h create mode 100755 Platform/build/user.ulog.api.Makefile create mode 100755 Platform/user/ulog/ulog-api/ulog_api.c diff --git a/Common/ulog_api.h b/Common/ulog_api.h new file mode 100755 index 000000000..f28ef563c --- /dev/null +++ b/Common/ulog_api.h @@ -0,0 +1,23 @@ +#ifndef _ULOG_API_H +#define _ULOG_API_H + +#define MAX_MODULE_NAME_SZ 16 + +typedef struct _ulog { + char module_name[MAX_MODULE_NAME_SZ]; +} ulog_t; + +ulog_t *ulog_init(const char *module_name); +void ulog_close(ulog_t *log); +void ulog_record(const ulog_t *log, int level, const char *fmt, ...); + +#define ULOG_DEBUG(log, fmt, ...) ulog_record(log, LOG_DEBUG, fmt, ##__VA_ARGS__) +#define ULOG_INFO(log, fmt, ...) ulog_record(log, LOG_INFO, fmt, ##__VA_ARGS__) +#define ULOG_NOTICE(log, fmt, ...) ulog_record(log, LOG_NOTICE, fmt, ##__VA_ARGS__) +#define ULOG_WARNING(log, fmt, ...) ulog_record(log, LOG_WARNING, fmt, ##__VA_ARGS__) +#define ULOG_ERR(log, fmt, ...) ulog_record(log, LOG_ERR, fmt, ##__VA_ARGS__) +#define ULOG_CRIT(log, fmt, ...) ulog_record(log, LOG_CRIT, fmt, ##__VA_ARGS__) +#define ULOG_ALERT(log, fmt, ...) ulog_record(log, LOG_ALERT, fmt, ##__VA_ARGS__) +#define ULOG_EMERG(log, fmt, ...) ulog_record(log, LOG_EMERG, fmt, ##__VA_ARGS__) + +#endif diff --git a/Makefile b/Makefile index d58583c63..21adffc41 100755 --- a/Makefile +++ b/Makefile @@ -163,10 +163,13 @@ endif ulog: ifeq ($(OPT), clean) $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=syslog-sched + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=ulog-api else ifeq ($(OPT), install) $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=syslog-sched + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=ulog-api else $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=syslog-sched + $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=ulog-api endif database: diff --git a/Platform/build/user.ulog.api.Makefile b/Platform/build/user.ulog.api.Makefile new file mode 100755 index 000000000..f1827ba94 --- /dev/null +++ b/Platform/build/user.ulog.api.Makefile @@ -0,0 +1,65 @@ +# target name, the target name must have the same name of c source file +TARGET_NAME=libulogapi + +# target +# for linux module driver: KO +# for application: EXE +# for dynamic library: DLL +TARGET_TYPE = DLL + +# target object +# for application: APP +# for device driver: DRV +TARGET_OBJ = APP + +# custom install dir +TARGET_BOX = + +#debug mode or release mode +DEBUG = TRUE + +PLAT_LINUX ?= TRUE +PLAT_ARM64 ?= TRUE + +VPATH = ../user/ulog/ulog-api + +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = ulog_api.c + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := -fPIC -I../../Common +PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) + + +PLAT_ARM64_LDFLAGS := -fPIC -shared +PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS) + + +#gcc libs + +# this line must be at below of thus, because of... +include ../../Common/common.Makefile + +ifneq ($(MAKECMDGOALS), clean) +ifneq ($(MAKECMDGOALS), cleanall) +ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB))) +$(shell $(CP) $(DEPEND_LIB) ./) +endif +endif +endif + +ifeq ($(MAKECMDGOALS), ) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +else +ifeq ($(MAKECMDGOALS), all) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +endif +endif + diff --git a/Platform/user/ulog/ulog-api/ulog_api.c b/Platform/user/ulog/ulog-api/ulog_api.c new file mode 100755 index 000000000..fbf56e0e9 --- /dev/null +++ b/Platform/user/ulog/ulog-api/ulog_api.c @@ -0,0 +1,51 @@ +#include + +#include "common_types.h" +#include "ulog_api.h" + +#define LOG_MSG_SZ 1024 + +ulog_t *ulog_init(const char *module_name) +{ + ulog_t *log; + u32 len = sizeof(module_name); + + if (len > MAX_MODULE_NAME_SZ) { + fprintf(stderr, "The length:%d of module_name can't more than %d", len, MAX_MODULE_NAME_SZ); + return NULL; + } + + log = (ulog_t *)malloc(sizeof(*log)); + if (log == NULL) { + fprintf(stderr, "Allocating log memory is failure"); + return NULL; + } + strncpy(log->module_name, module_name, len); + + return log; +} + +void ulog_close(ulog_t *log) +{ + if (log == NULL) { + return; + } + + free(log); +} + +void ulog_record(const ulog_t *log, int level, const char *fmt, ...) +{ + if (log == NULL) { + perror("Log is null"); + return; + } + + char log_buf[LOG_MSG_SZ]; + va_list args; + va_start(args, fmt); + vsnprintf(log_buf, sizeof(log_buf), log_buf, args); + va_end(args); + syslog(level, "[%s] %s", log->module_name, log_buf); +} +