[DEV] continue removing stl
This commit is contained in:
parent
41b0948466
commit
2bcb9068aa
@ -10,7 +10,7 @@
|
||||
#include <elog/elog.hpp>
|
||||
#include <elog/debug.hpp>
|
||||
|
||||
static elog::level getLogLevel(const std::string& _value) {
|
||||
static elog::level getLogLevel(const etk::String& _value) {
|
||||
if (_value == "0") {
|
||||
return elog::level_none;
|
||||
} else if (_value == "1") {
|
||||
@ -30,7 +30,7 @@ static elog::level getLogLevel(const std::string& _value) {
|
||||
return elog::level_verbose;
|
||||
}
|
||||
|
||||
static bool startWith(const std::string& _obj, const std::string& _val) {
|
||||
static bool startWith(const etk::String& _obj, const etk::String& _val) {
|
||||
if (_val.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -47,20 +47,6 @@ static bool startWith(const std::string& _obj, const std::string& _val) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(const std::string& _input, char _val) {
|
||||
std::vector<std::string> list;
|
||||
size_t lastStartPos = 0;
|
||||
for(size_t iii=0; iii<_input.size(); iii++) {
|
||||
if (_input[iii]==_val) {
|
||||
list.push_back(std::string(_input, lastStartPos, iii - lastStartPos));
|
||||
lastStartPos = iii+1;
|
||||
}
|
||||
}
|
||||
if (lastStartPos<_input.size()) {
|
||||
list.push_back(std::string(_input, lastStartPos));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
static int32_t nbTimeInit = 0;
|
||||
|
||||
void elog::unInit() {
|
||||
@ -88,7 +74,7 @@ void elog::init(int _argc, const char** _argv) {
|
||||
nbTimeInit++;
|
||||
ELOG_INFO("E-log system init (BEGIN)");
|
||||
// retrive application Name:
|
||||
std::string applName = "noApplicationName";
|
||||
etk::String applName = "noApplicationName";
|
||||
#if !defined(__TARGET_OS__Android) and !defined(__TARGET_OS__IOs)
|
||||
if (_argc >= 1) {
|
||||
applName = _argv[0];
|
||||
@ -99,12 +85,12 @@ void elog::init(int _argc, const char** _argv) {
|
||||
// get name: applName
|
||||
bool userSpecifyLogFile = false;
|
||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||
std::string data = _argv[iii];
|
||||
etk::String data = _argv[iii];
|
||||
if (startWith(data, "--elog-level=")) {
|
||||
ELOG_INFO("Change global level at " << getLogLevel(std::string(data.begin()+13, data.end())));
|
||||
elog::setLevel(getLogLevel(std::string(data.begin()+13, data.end())));
|
||||
ELOG_INFO("Change global level at " << getLogLevel(etk::String(data.begin()+13, data.end())));
|
||||
elog::setLevel(getLogLevel(etk::String(data.begin()+13, data.end())));
|
||||
} else if (startWith(data, "--elog-max-line=")) {
|
||||
std::string dataToParse = &data[16];
|
||||
etk::String dataToParse = &data[16];
|
||||
int value = 0;
|
||||
sscanf(dataToParse.c_str(), "%d", &value);
|
||||
elog::setMaxLineNumberInFile(value);
|
||||
@ -115,7 +101,7 @@ void elog::init(int _argc, const char** _argv) {
|
||||
} else if (data == "--elog-back-trace") {
|
||||
elog::setBackTrace(true);
|
||||
} else if (startWith(data, "--elog-file=")) {
|
||||
std::string value(data.begin()+12, data.end());
|
||||
etk::String value(data.begin()+12, data.end());
|
||||
if (value.size() == 0) {
|
||||
elog::unsetLogInFile();
|
||||
} else {
|
||||
@ -123,7 +109,7 @@ void elog::init(int _argc, const char** _argv) {
|
||||
}
|
||||
userSpecifyLogFile = true;
|
||||
} else if (startWith(data, "--elog-config=")) {
|
||||
std::string value(data.begin()+14, data.end());
|
||||
etk::String value(data.begin()+14, data.end());
|
||||
elog::setTime(false);
|
||||
elog::setLine(false);
|
||||
elog::setFunction(false);
|
||||
@ -148,12 +134,12 @@ void elog::init(int _argc, const char** _argv) {
|
||||
}
|
||||
}
|
||||
} else if (startWith(data, "--elog-lib=")) {
|
||||
std::string value(data.begin()+11, data.end());
|
||||
std::vector<std::string> list = split(value, '/');
|
||||
etk::String value(data.begin()+11, data.end());
|
||||
etk::Vector<etk::String> list = value.split('/');
|
||||
if (list.size() != 2) {
|
||||
list = split(value, ':');
|
||||
list = value.split(':');
|
||||
if (list.size() != 2) {
|
||||
list = split(value, '+');
|
||||
list = value.split('+');
|
||||
if (list.size() != 2) {
|
||||
ELOG_ERROR("Can not set the --elog-lib= with value='" << value << "' not formated name:X or name/X or name+X");
|
||||
continue;
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <etk/String.hpp>
|
||||
/**
|
||||
* @brief basic namespace of the elog library. (it might contain all the elog fuctions without macro)
|
||||
*/
|
||||
|
58
elog/log.cpp
58
elog/log.cpp
@ -11,7 +11,7 @@
|
||||
#include <time.h>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <etk/Map.hpp>
|
||||
#include <inttypes.h>
|
||||
#ifdef ELOG_BUILD_ETHREAD
|
||||
#include <ethread/tools.hpp>
|
||||
@ -137,18 +137,18 @@ size_t& getNameSizeLog() {
|
||||
return g_val;
|
||||
}
|
||||
|
||||
static std::vector<std::pair<std::string, enum elog::level> >& getList() {
|
||||
static std::vector<std::pair<std::string, enum elog::level> > g_val;
|
||||
static etk::Vector<etk::Pair<etk::String, enum elog::level> >& getList() {
|
||||
static etk::Vector<etk::Pair<etk::String, enum elog::level> > g_val;
|
||||
return g_val;
|
||||
}
|
||||
|
||||
int32_t elog::registerInstance(const std::string& _name) {
|
||||
int32_t elog::registerInstance(const etk::String& _name) {
|
||||
for (size_t iii = 0; iii < getList().size(); ++iii) {
|
||||
if (getList()[iii].first == _name) {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
getList().push_back(std::make_pair(_name, getDefaultLevel()));
|
||||
getList().pushBack(etk::makePair(_name, getDefaultLevel()));
|
||||
if (_name.size() >= getNameSizeLog()) {
|
||||
getNameSizeLog() = _name.size()+1;
|
||||
}
|
||||
@ -156,14 +156,14 @@ int32_t elog::registerInstance(const std::string& _name) {
|
||||
return getList().size()-1;
|
||||
}
|
||||
|
||||
void elog::setLevel(const std::string& _name, enum level _level) {
|
||||
void elog::setLevel(const etk::String& _name, enum level _level) {
|
||||
for (size_t iii = 0; iii < getList().size(); ++iii) {
|
||||
if (getList()[iii].first == _name) {
|
||||
getList()[iii].second = _level;
|
||||
return;
|
||||
}
|
||||
}
|
||||
getList().push_back(std::make_pair(_name, _level));
|
||||
getList().pushBack(etk::makePair(_name, _level));
|
||||
}
|
||||
|
||||
void elog::setLevel(enum level _level) {
|
||||
@ -190,30 +190,24 @@ int32_t elog::getLevel(int32_t _id) {
|
||||
return (int32_t)getList()[_id].second;
|
||||
}
|
||||
|
||||
std::vector<std::string> elog::getListInstance() {
|
||||
std::vector<std::string> out;
|
||||
etk::Vector<etk::String> elog::getListInstance() {
|
||||
etk::Vector<etk::String> out;
|
||||
for (size_t iii = 0; iii < getList().size(); ++iii) {
|
||||
out.push_back(getList()[iii].first);
|
||||
out.pushBack(getList()[iii].first);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void elog::logStream(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const std::ostream& _log) {
|
||||
std::ostringstream oss;
|
||||
oss << _log.rdbuf();
|
||||
std::string sss =oss.str();
|
||||
elog::logChar(_id, _level, _ligne, _funcName, sss.c_str());
|
||||
void elog::logStream(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const etk::Stream& _log) {
|
||||
elog::logChar(_id, _level, _ligne, _funcName, _log.c_str());
|
||||
}
|
||||
|
||||
void elog::logChar1(int32_t _id, int32_t _level, const char* _log) {
|
||||
elog::logChar(_id, _level, -1, nullptr, _log);
|
||||
}
|
||||
|
||||
void elog::logStream1(int32_t _id, int32_t _level, const std::ostream& _log) {
|
||||
std::ostringstream oss;
|
||||
oss << _log.rdbuf();
|
||||
std::string sss =oss.str();
|
||||
elog::logChar(_id, _level, -1, nullptr, sss.c_str());
|
||||
void elog::logStream1(int32_t _id, int32_t _level, const etk::Stream& _log) {
|
||||
elog::logChar(_id, _level, -1, nullptr, _log.c_str());
|
||||
}
|
||||
|
||||
static bool& getColor() {
|
||||
@ -298,8 +292,8 @@ static void getDisplayTime(char* data) {
|
||||
static std::mutex g_lock;
|
||||
static elog::callbackLog callbackUserLog(nullptr);
|
||||
|
||||
static std::string& getLogFileName() {
|
||||
static std::string g_val="";
|
||||
static etk::String& getLogFileName() {
|
||||
static etk::String g_val="";
|
||||
return g_val;
|
||||
}
|
||||
static FILE*& getLogFile() {
|
||||
@ -378,7 +372,7 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) {
|
||||
return (status);
|
||||
}
|
||||
|
||||
static bool FSNODE_LOCAL_exist(const std::string& _path) {
|
||||
static bool FSNODE_LOCAL_exist(const etk::String& _path) {
|
||||
struct stat st;
|
||||
int32_t status = 0;
|
||||
if (stat(_path.c_str(), &st) != 0) {
|
||||
@ -388,14 +382,14 @@ static bool FSNODE_LOCAL_exist(const std::string& _path) {
|
||||
}
|
||||
// Copy for ETK FSNODE ... [END]
|
||||
|
||||
void elog::setLogInFile(const std::string& _filename) {
|
||||
void elog::setLogInFile(const etk::String& _filename) {
|
||||
elog::unsetLogInFile();
|
||||
ELOG_PRINT("Log in file: '" << _filename << "'");
|
||||
getLogFileName() = _filename;
|
||||
FILE*& file = getLogFile();
|
||||
// create path of the file:
|
||||
size_t found=_filename.find_last_of("/\\");
|
||||
std::string path = _filename.substr(0,found);
|
||||
size_t found=_filename.rfind("/\\");
|
||||
etk::String path = _filename.extract(0,found);
|
||||
if (FSNODE_LOCAL_exist(path) == false) {
|
||||
FSNODE_LOCAL_mkPath(path.c_str(), 0760);
|
||||
}
|
||||
@ -568,7 +562,7 @@ void elog::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _fun
|
||||
}
|
||||
if(getThreadNameEnable() == true) {
|
||||
// display thread ID
|
||||
std::string name = ethread::getName();
|
||||
etk::String name = ethread::getName();
|
||||
if (name.size() >= getThreadSizeLog() ) {
|
||||
getThreadSizeLog() = name.size() + 1;
|
||||
}
|
||||
@ -610,16 +604,16 @@ void elog::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _fun
|
||||
startPos2 = strchr(startPos+1, ' ');
|
||||
}
|
||||
if(uint64_t(stopPos) < uint64_t(startPos)) {
|
||||
snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)), "%s", _funcName);
|
||||
snprintf(tmpPointer, etk::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)), "%s", _funcName);
|
||||
} else {
|
||||
snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(startPos)), "%s", startPos+1);
|
||||
snprintf(tmpPointer, etk::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(startPos)), "%s", startPos+1);
|
||||
}
|
||||
} else {
|
||||
snprintf(tmpPointer, 1024, "%s", startPos);
|
||||
}
|
||||
} else {
|
||||
if (stopPos != nullptr) {
|
||||
snprintf(tmpPointer, std::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)+1), "%s", _funcName);
|
||||
snprintf(tmpPointer, etk::min(uint64_t(1024), uint64_t(stopPos)-uint64_t(_funcName)+1), "%s", _funcName);
|
||||
} else {
|
||||
snprintf(tmpPointer, 1024, "%s", _funcName);
|
||||
}
|
||||
@ -682,10 +676,10 @@ void elog::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char* _fun
|
||||
fileCurrentCount = 0;
|
||||
fflush(file);
|
||||
fclose(file);
|
||||
std::string tmpFileName = getLogFileName();
|
||||
etk::String tmpFileName = getLogFileName();
|
||||
if ( tmpFileName.size() > 0
|
||||
&& tmpFileName[tmpFileName.size()-1] == '2') {
|
||||
getLogFileName().pop_back();
|
||||
getLogFileName().popBack();
|
||||
} else {
|
||||
getLogFileName() += "2";
|
||||
}
|
||||
|
23
elog/log.hpp
23
elog/log.hpp
@ -8,8 +8,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <etk/Stream.hpp>
|
||||
#include <etk/Vector.hpp>
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/Stream.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace elog {
|
||||
@ -32,7 +34,7 @@ namespace elog {
|
||||
* @param[in] _name Name of the module
|
||||
* @return reference Id of an instance name
|
||||
*/
|
||||
int32_t registerInstance(const std::string& _name);
|
||||
int32_t registerInstance(const etk::String& _name);
|
||||
/**
|
||||
* @brief Set the log level of a specific instance
|
||||
* @param[in] _name Name of the intance
|
||||
@ -41,7 +43,7 @@ namespace elog {
|
||||
* elog::setLevel("ewol", elog::level_critical);
|
||||
* @endcode
|
||||
*/
|
||||
void setLevel(const std::string& _name, enum elog::level _level);
|
||||
void setLevel(const etk::String& _name, enum elog::level _level);
|
||||
/**
|
||||
* @brief Set the log level of a specific instance
|
||||
* @param[in] _id Id of the intance
|
||||
@ -66,7 +68,7 @@ namespace elog {
|
||||
* @brief Get list of all intance
|
||||
* @return the name list of all intance
|
||||
*/
|
||||
std::vector<std::string> getListInstance();
|
||||
etk::Vector<etk::String> getListInstance();
|
||||
/**
|
||||
* @brief Set Color enable or disable.
|
||||
* @param[in] _status New value of color.
|
||||
@ -129,7 +131,7 @@ namespace elog {
|
||||
* @param[in] _funcName Function name for debug (compleate decorate signature)
|
||||
* @param[in] _log Stream to log
|
||||
*/
|
||||
void logStream(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const std::ostream& _log);
|
||||
void logStream(int32_t _id, int32_t _level, int32_t _ligne, const char* _funcName, const etk::Stream& _log);
|
||||
/**
|
||||
* @brief Call log to display
|
||||
* @param[in] _id Id of the instance type
|
||||
@ -143,7 +145,7 @@ namespace elog {
|
||||
* @param[in] _level Level debug
|
||||
* @param[in] _log Stream to log
|
||||
*/
|
||||
void logStream1(int32_t _id, int32_t _level, const std::ostream& _log);
|
||||
void logStream1(int32_t _id, int32_t _level, const etk::Stream& _log);
|
||||
/**
|
||||
* @brief Display the current backtrace
|
||||
* @param[in] _breakAtEnd assert program when backtrace is printed
|
||||
@ -169,7 +171,7 @@ namespace elog {
|
||||
* @param[in] _filename Name of the file to log (if not set the log system select alone the log file)
|
||||
* @note in release the log is automatically store in a file in the system. (windows log is done in file automatically)
|
||||
*/
|
||||
void setLogInFile(const std::string& _filename="");
|
||||
void setLogInFile(const etk::String& _filename="");
|
||||
/**
|
||||
* @brief Disable log in a file
|
||||
*/
|
||||
@ -184,13 +186,12 @@ namespace elog {
|
||||
* @brief Basic macro of all logs macros
|
||||
* @param[in] logId Id of the library that log
|
||||
* @param[in] info Log level of this log: elog::level
|
||||
* @param[in] data Stream separaated with "<<" convertible in std::ostream
|
||||
* @param[in] data Stream separaated with "<<" convertible in etk::Stream
|
||||
*/
|
||||
#define ELOG_BASE(logId,info,data) \
|
||||
do { \
|
||||
if (info <= elog::getLevel(logId)) { \
|
||||
std::stringbuf sb; \
|
||||
std::ostream tmpStream(&sb); \
|
||||
etk::Stream tmpStream; \
|
||||
tmpStream << data; \
|
||||
elog::logStream(logId, info, __LINE__, __PRETTY_FUNCTION__, tmpStream); \
|
||||
} \
|
||||
|
@ -20,17 +20,10 @@ namespace test {
|
||||
#define TEST_CRITICAL(data) TEST_BASE(1, data)
|
||||
#define TEST_ERROR(data) TEST_BASE(2, data)
|
||||
#define TEST_WARNING(data) TEST_BASE(3, data)
|
||||
#ifdef DEBUG
|
||||
#define TEST_INFO(data) TEST_BASE(4, data)
|
||||
#define TEST_DEBUG(data) TEST_BASE(5, data)
|
||||
#define TEST_VERBOSE(data) TEST_BASE(6, data)
|
||||
#define TEST_TODO(data) TEST_BASE(4, "TODO : " << data)
|
||||
#else
|
||||
#define TEST_INFO(data) do { } while(false)
|
||||
#define TEST_DEBUG(data) do { } while(false)
|
||||
#define TEST_VERBOSE(data) do { } while(false)
|
||||
#define TEST_TODO(data) do { } while(false)
|
||||
#endif
|
||||
#define TEST_INFO(data) TEST_BASE(4, data)
|
||||
#define TEST_DEBUG(data) TEST_BASE(5, data)
|
||||
#define TEST_VERBOSE(data) TEST_BASE(6, data)
|
||||
#define TEST_TODO(data) TEST_BASE(4, "TODO : " << data)
|
||||
|
||||
#define TEST_HIDDEN(data) do { } while(false)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user