parent
653c06c16f
commit
ac0c0aa295
|
@ -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
|
3
Makefile
3
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:
|
||||
|
|
|
@ -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
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue