Start on log package
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ endif()
|
|||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
add_definitions(
|
add_definitions(
|
||||||
-std=c++11
|
-std=c++14
|
||||||
-Wall
|
-Wall
|
||||||
-nostdlib
|
-nostdlib
|
||||||
-fno-exceptions
|
-fno-exceptions
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ if(OX_USE_STDLIB STREQUAL "ON")
|
|||||||
add_subdirectory(clargs)
|
add_subdirectory(clargs)
|
||||||
endif(OX_USE_STDLIB STREQUAL "ON")
|
endif(OX_USE_STDLIB STREQUAL "ON")
|
||||||
add_subdirectory(fs)
|
add_subdirectory(fs)
|
||||||
|
add_subdirectory(log)
|
||||||
add_subdirectory(mc)
|
add_subdirectory(mc)
|
||||||
add_subdirectory(std)
|
add_subdirectory(std)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ if(OX_BUILD_EXEC STREQUAL "ON")
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
oxfstool
|
oxfstool
|
||||||
OxFS
|
OxFS
|
||||||
|
OxLog
|
||||||
OxStd
|
OxStd
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -20,10 +20,33 @@ add_executable(
|
|||||||
tests.cpp
|
tests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(FileStoreFormat OxFS OxStd)
|
target_link_libraries(
|
||||||
target_link_libraries(FileSystemFormat OxFS OxStd)
|
FileStoreFormat
|
||||||
target_link_libraries(FileStoreIO OxFS OxStd)
|
OxFS
|
||||||
target_link_libraries(FSTests OxFS OxStd)
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
FileSystemFormat
|
||||||
|
OxFS
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
FileStoreIO
|
||||||
|
OxFS
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
FSTests
|
||||||
|
OxFS
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
add_test("FileStoreFormat" FileStoreFormat)
|
add_test("FileStoreFormat" FileStoreFormat)
|
||||||
add_test("FileSystemFormat" FileSystemFormat)
|
add_test("FileSystemFormat" FileSystemFormat)
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
add_library(
|
||||||
|
OxLog
|
||||||
|
log.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TARGET
|
||||||
|
OxLog
|
||||||
|
PROPERTY
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
log.hpp
|
||||||
|
DESTINATION
|
||||||
|
include/ox/mc
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS OxLog
|
||||||
|
LIBRARY DESTINATION lib/ox
|
||||||
|
ARCHIVE DESTINATION lib/ox
|
||||||
|
)
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 - 2017 gtalent2@gmail.com
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
|
|
||||||
|
namespace ox {
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
private:
|
||||||
|
// void* stand-in for FILE*
|
||||||
|
const char *m_path = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Logger(const char *path = nullptr);
|
||||||
|
|
||||||
|
~Logger();
|
||||||
|
|
||||||
|
void log(LogLevel_t level, const char *msg, va_list args);
|
||||||
|
|
||||||
|
void info(const char *msg, ...);
|
||||||
|
|
||||||
|
void debug(const char *msg, ...);
|
||||||
|
|
||||||
|
void error(const char *msg, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
Logger::Logger(const char *path) {
|
||||||
|
m_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::~Logger() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::log(LogLevel_t level, const char *msg, va_list args) {
|
||||||
|
if (m_path) {
|
||||||
|
auto file = fopen(m_path, "a");
|
||||||
|
vfprintf(file, msg, args);
|
||||||
|
fprintf(file, "\n");
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::info(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Info, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::debug(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Debug, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::error(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Error, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Logger logger;
|
||||||
|
|
||||||
|
void logFile(const char *path) {
|
||||||
|
logger = Logger(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(LogLevel_t level, const char *msg, va_list args) {
|
||||||
|
logger.log(level, msg, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void info(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Info, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Debug, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(const char *msg, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, msg);
|
||||||
|
log(LogLevel_t::Error, msg, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 - 2017 gtalent2@gmail.com
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ox {
|
||||||
|
|
||||||
|
enum class LogLevel_t: int {
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
void logFile(const char *path);
|
||||||
|
|
||||||
|
void info(const char *msg, ...);
|
||||||
|
|
||||||
|
void debug(const char *msg, ...);
|
||||||
|
|
||||||
|
void error(const char *msg, ...);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,12 @@ add_executable(
|
|||||||
tests.cpp
|
tests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(McTest OxStd OxMetalClaw)
|
target_link_libraries(
|
||||||
|
McTest
|
||||||
|
OxMetalClaw
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
add_test("Test\\ McTest\\ Writer" McTest MetalClawWriter)
|
add_test("Test\\ McTest\\ Writer" McTest MetalClawWriter)
|
||||||
add_test("Test\\ McTest\\ Reader" McTest MetalClawReader)
|
add_test("Test\\ McTest\\ Reader" McTest MetalClawReader)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ add_executable(
|
|||||||
tests.cpp
|
tests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(StdTest OxStd)
|
target_link_libraries(StdTest OxLog OxStd)
|
||||||
|
|
||||||
add_test("Test\\ ox_memcmp\\ ABCDEFG\\ !=\\ HIJKLMN" StdTest "ABCDEFG != HIJKLMN")
|
add_test("Test\\ ox_memcmp\\ ABCDEFG\\ !=\\ HIJKLMN" StdTest "ABCDEFG != HIJKLMN")
|
||||||
add_test("Test\\ ox_memcmp\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG")
|
add_test("Test\\ ox_memcmp\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG")
|
||||||
@@ -21,14 +21,18 @@ add_executable(
|
|||||||
strops_test.cpp
|
strops_test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(StrOpsTest OxStd)
|
target_link_libraries(
|
||||||
|
StrOpsTest
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
add_test("Test\\ ox_strcmp\\ asdf\\ !=\\ hijk" StrOpsTest "asdf < hijk")
|
add_test("Test\\ ox_strcmp\\ asdf\\ !=\\ hijk" StrOpsTest "asdf < hijk")
|
||||||
add_test("Test\\ ox_strcmp\\ hijk\\ !=\\ asdf" StrOpsTest "hijk > asdf")
|
add_test("Test\\ ox_strcmp\\ hijk\\ !=\\ asdf" StrOpsTest "hijk > asdf")
|
||||||
add_test("Test\\ ox_strcmp\\ read\\ !=\\ resize" StrOpsTest "read < resize")
|
add_test("Test\\ ox_strcmp\\ read\\ !=\\ resize" StrOpsTest "read < resize")
|
||||||
add_test("Test\\ ox_strcmp\\ resize\\ !=\\ read" StrOpsTest "resize > read")
|
add_test("Test\\ ox_strcmp\\ resize\\ !=\\ read" StrOpsTest "resize > read")
|
||||||
add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest "resize == resize")
|
add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest "resize == resize")
|
||||||
add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest " == ")
|
add_test("Test\\ ox_strcmp\\ ''\\ ==\\ ''" StrOpsTest " == ")
|
||||||
add_test("Test\\ ox_strchr\\ 0" StrOpsTest "ox_strchr 0")
|
add_test("Test\\ ox_strchr\\ 0" StrOpsTest "ox_strchr 0")
|
||||||
add_test("Test\\ ox_lastIndexOf\\ aaaa\\ a" StrOpsTest "ox_lastIndexOf aaaa a")
|
add_test("Test\\ ox_lastIndexOf\\ aaaa\\ a" StrOpsTest "ox_lastIndexOf aaaa a")
|
||||||
|
|
||||||
@@ -41,7 +45,11 @@ add_executable(
|
|||||||
byteswap_test.cpp
|
byteswap_test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(ByteSwapTest OxStd)
|
target_link_libraries(
|
||||||
|
ByteSwapTest
|
||||||
|
OxStd
|
||||||
|
OxLog
|
||||||
|
)
|
||||||
|
|
||||||
add_test("Test\\ bigEndianAdapt\\ 0x00ff" ByteSwapTest bigEndianAdapt<uint16_t> 0x00ff)
|
add_test("Test\\ bigEndianAdapt\\ 0x00ff" ByteSwapTest bigEndianAdapt<uint16_t> 0x00ff)
|
||||||
add_test("Test\\ bigEndianAdapt\\ 0xff00" ByteSwapTest bigEndianAdapt<uint16_t> 0xff00)
|
add_test("Test\\ bigEndianAdapt\\ 0xff00" ByteSwapTest bigEndianAdapt<uint16_t> 0xff00)
|
||||||
|
|||||||
Reference in New Issue
Block a user