9 Commits

10 changed files with 74 additions and 12 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
.vscode/**
bin
build
CMakeUserPresets.json

View File

@@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.28...3.30)
project(logging)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_CLANG_TIDY "clang-tidy")
if(MSVC)
add_compile_options("/source-charset:utf-8")

View File

@@ -5,7 +5,7 @@ import os
class loggingRecipe(ConanFile):
name = "logging"
version = "1.0.0"
version = "1.1.0"
license = "MIT"
author = "321640253@qq.com"
url = "https://github.com/WangZhongDian/logging.git"
@@ -17,7 +17,7 @@ class loggingRecipe(ConanFile):
default_options = {"shared": False, "fPIC": True,"test":True}
exports_sources = "include/*", "CMakeLists.txt", "src/*", "tests/*"
exports_sources = "include/*", "CMakeLists.txt", "src/*", "tests/*", "LICENSE"
def config_options(self):
if self.settings.os == "Windows":
@@ -47,12 +47,8 @@ class loggingRecipe(ConanFile):
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
copy(self, pattern="*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.so", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
copy(self, pattern="*.dylib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["logging"]

View File

@@ -81,6 +81,13 @@ void loggingDestroyAll(void);
*/
void loggingDestroyLogger(Logger *logger);
/**
* @brief 替换默认日志器
* @param logger 日志器
* @return
*/
bool loggingReplaceDefaultLogger(Logger *logger);
#ifdef __cplusplus
}
#endif

View File

@@ -1,6 +1,6 @@
[project]
name = "logging"
version = "1.0.0"
version = "1.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"

View File

@@ -6,7 +6,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define RED "\033[0;31m"
@@ -257,6 +256,20 @@ Logger *loggingGetLogger(const char *name) {
return logger;
}
bool loggingReplaceDefaultLogger(Logger *logger) {
if (logger == NULL) {
return false;
}
if (ROOT_LOGGER == NULL) {
ROOT_LOGGER = logger;
} else {
loggingDestroyLogger(ROOT_LOGGER);
ROOT_LOGGER = logger;
}
return true;
}
void loggingDestroyLogger(Logger *logger) {
if (logger != NULL) {
if (logger->handler != NULL) {

View File

@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.28...3.30)
project(LoggingTest)
find_package(logging CONFIG REQUIRED)
#测试简单基本应用
add_executable(${PROJECT_NAME} src/testExmaple.c)
target_link_libraries(${PROJECT_NAME} logging::logging)

26
test_package/conanfile.py Normal file
View File

@@ -0,0 +1,26 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run
class LoggingTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def layout(self):
cmake_layout(self)
def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "LoggingTest")
self.run(cmd, env="conanrun")

View File

@@ -0,0 +1,12 @@
#include "logging.h"
int main() {
Log_info("This is an info message");
Log_error("This is an error message%s", "123");
Log_fatal("This is an fatal message");
Log_debug("This is a debug message");
Log_warning("This is a warning message%s", "123");
loggingDestroyAll();
return 0;
}

View File

@@ -1,6 +1,5 @@
#include "utils/logging-map.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void foreach_callback(const char *key, void *value, void *user_data) {