mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-06 18:40:24 +08:00
implement new logging formatter
This commit is contained in:
parent
c590564fd4
commit
ff4f55858d
@ -35,6 +35,8 @@ add_library(oatpp
|
||||
oatpp/base/Config.hpp
|
||||
oatpp/base/Countable.cpp
|
||||
oatpp/base/Countable.hpp
|
||||
oatpp/base/Log.cpp
|
||||
oatpp/base/Log.hpp
|
||||
oatpp/base/ObjectHandle.hpp
|
||||
oatpp/codegen/api_controller/auth_define.hpp
|
||||
oatpp/codegen/api_controller/auth_undef.hpp
|
||||
|
@ -87,8 +87,8 @@ namespace oatpp {
|
||||
|
||||
/**
|
||||
* Interface for system-wide Logger.<br>
|
||||
* All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGD`, `OATPP_DISABLE_LOGI`,
|
||||
* `OATPP_DISABLE_LOGW`, `OATPP_DISABLE_LOGE` will come here.
|
||||
* All calls to `OATPP_LOGV`, `OATPP_LOGD`, `OATPP_LOGI`,
|
||||
* `OATPP_LOGW`, `OATPP_LOGE` will come here.
|
||||
*/
|
||||
class Logger {
|
||||
public:
|
||||
|
@ -22,8 +22,8 @@
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef oatpp_base_Countable
|
||||
#define oatpp_base_Countable
|
||||
#ifndef oatpp_base_Countable_hpp
|
||||
#define oatpp_base_Countable_hpp
|
||||
|
||||
#include "oatpp/Environment.hpp"
|
||||
|
||||
@ -59,4 +59,4 @@ public:
|
||||
|
||||
}}
|
||||
|
||||
#endif /* oatpp_base_Countable */
|
||||
#endif /* oatpp_base_Countable_hpp */
|
||||
|
302
src/oatpp/base/Log.cpp
Normal file
302
src/oatpp/base/Log.cpp
Normal file
@ -0,0 +1,302 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "Log.hpp"
|
||||
|
||||
#include "oatpp/utils/parser/Caret.hpp"
|
||||
#include "oatpp/macro/basic.hpp"
|
||||
|
||||
namespace oatpp::base{
|
||||
|
||||
LogMessage::LogMessage(const oatpp::String& msg)
|
||||
: m_msg(msg != nullptr ? msg : "<null>")
|
||||
, m_stream(256)
|
||||
, m_currParam(0)
|
||||
{
|
||||
|
||||
utils::parser::Caret caret(m_msg);
|
||||
while (caret.canContinue()) {
|
||||
|
||||
if(caret.findText("{}", 2)) {
|
||||
m_params.push_back({caret.getPosition(), caret.getPosition() + 2});
|
||||
caret.inc(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string LogMessage::toStdString() const {
|
||||
if(m_currParam == 0) {
|
||||
m_stream.writeSimple(m_msg->data(), static_cast<v_buff_size>(m_msg->size()));
|
||||
} else if(m_currParam > 0) {
|
||||
auto& prev = m_params.at(m_currParam - 1);
|
||||
m_stream.writeSimple(m_msg->data() + prev.endPos, static_cast<v_buff_size>(m_msg->size()) - prev.endPos);
|
||||
}
|
||||
return m_stream.toStdString();
|
||||
}
|
||||
|
||||
bool LogMessage::writeNextChunk() {
|
||||
|
||||
if(m_currParam >= m_params.size()) return false;
|
||||
|
||||
if(m_currParam == 0) {
|
||||
auto& curr = m_params.at(m_currParam);
|
||||
m_stream.writeSimple(m_msg->data(), curr.startPos);
|
||||
} else if(m_currParam > 0) {
|
||||
auto& prev = m_params.at(m_currParam - 1);
|
||||
auto& curr = m_params.at(m_currParam);
|
||||
m_stream.writeSimple(m_msg->data() + prev.endPos, curr.startPos - prev.endPos);
|
||||
}
|
||||
|
||||
m_currParam ++;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const char* str) {
|
||||
if(writeNextChunk()) {
|
||||
if(str != nullptr) {
|
||||
m_stream.writeSimple(str);
|
||||
} else {
|
||||
m_stream.writeSimple("{<char*(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (bool value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_int8 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_uint8 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_int16 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_uint16 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_int32 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_uint32 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_int64 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_uint64 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_float32 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (v_float64 value) {
|
||||
if(writeNextChunk()) {
|
||||
m_stream.writeAsString(value);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const oatpp::String& str) {
|
||||
if(writeNextChunk()) {
|
||||
if(str != nullptr) {
|
||||
m_stream.writeSimple(str);
|
||||
} else {
|
||||
m_stream.writeSimple("{<String(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Boolean& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Boolean(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Int8& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Int8(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const UInt8& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<UInt8(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Int16& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Int16(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const UInt16& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<UInt16(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Int32& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Int32(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const UInt32& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<UInt32(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Int64& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Int64(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const UInt64& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<UInt64(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Float32& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Float32(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LogMessage& LogMessage::operator << (const Float64& value) {
|
||||
if(writeNextChunk()) {
|
||||
if(value.get() != nullptr) {
|
||||
m_stream.writeAsString(*value);
|
||||
} else {
|
||||
m_stream.writeSimple("{<Float64(null)>}");
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void LogMessage::log(v_uint32 priority, const std::string& tag, const LogMessage& message) {
|
||||
oatpp::Environment::log(priority, tag, message.toStdString());
|
||||
}
|
||||
|
||||
}
|
189
src/oatpp/base/Log.hpp
Normal file
189
src/oatpp/base/Log.hpp
Normal file
@ -0,0 +1,189 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef oatpp_base_Log_hpp
|
||||
#define oatpp_base_Log_hpp
|
||||
|
||||
#include "oatpp/data/stream/BufferStream.hpp"
|
||||
|
||||
namespace oatpp::base{
|
||||
|
||||
class LogMessage {
|
||||
private:
|
||||
|
||||
struct Parameter {
|
||||
v_buff_size startPos;
|
||||
v_buff_size endPos;
|
||||
};
|
||||
|
||||
private:
|
||||
bool writeNextChunk();
|
||||
private:
|
||||
oatpp::String m_msg;
|
||||
mutable data::stream::BufferOutputStream m_stream;
|
||||
v_uint64 m_currParam;
|
||||
std::vector<Parameter> m_params;
|
||||
public:
|
||||
|
||||
explicit LogMessage(const oatpp::String& msg);
|
||||
|
||||
std::string toStdString() const;
|
||||
|
||||
LogMessage& operator << (const char* str);
|
||||
LogMessage& operator << (bool value);
|
||||
LogMessage& operator << (v_int8 value);
|
||||
LogMessage& operator << (v_uint8 value);
|
||||
LogMessage& operator << (v_int16 value);
|
||||
LogMessage& operator << (v_uint16 value);
|
||||
LogMessage& operator << (v_int32 value);
|
||||
LogMessage& operator << (v_uint32 value);
|
||||
LogMessage& operator << (v_int64 value);
|
||||
LogMessage& operator << (v_uint64 value);
|
||||
LogMessage& operator << (v_float32 value);
|
||||
LogMessage& operator << (v_float64 value);
|
||||
|
||||
LogMessage& operator << (const oatpp::String& str);
|
||||
LogMessage& operator << (const Boolean& value);
|
||||
LogMessage& operator << (const Int8& value);
|
||||
LogMessage& operator << (const UInt8& value);
|
||||
LogMessage& operator << (const Int16& value);
|
||||
LogMessage& operator << (const UInt16& value);
|
||||
LogMessage& operator << (const Int32& value);
|
||||
LogMessage& operator << (const UInt32& value);
|
||||
LogMessage& operator << (const Int64& value);
|
||||
LogMessage& operator << (const UInt64& value);
|
||||
LogMessage& operator << (const Float32& value);
|
||||
LogMessage& operator << (const Float64& value);
|
||||
|
||||
public:
|
||||
|
||||
static void log(v_uint32 priority, const std::string& tag, const LogMessage& message);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#define OATPP_LOG_PARAMS(IDX, CNT, P) \
|
||||
<< P
|
||||
|
||||
#define OATPP_LOG_MACRO_0(PRIORITY, TAG, MSG) \
|
||||
oatpp::base::LogMessage::log(PRIORITY, TAG, LogMessage(MSG));
|
||||
|
||||
#define OATPP_LOG_MACRO_1(PRIORITY, TAG, MSG, ...) \
|
||||
oatpp::base::LogMessage::log(PRIORITY, TAG, LogMessage(MSG) OATPP_MACRO_FOREACH_OR_EMPTY(OATPP_LOG_PARAMS, __VA_ARGS__));
|
||||
|
||||
/**
|
||||
* General LOG macro
|
||||
* @param PRIORITY - Http method ("GET", "POST", "PUT", etc.)
|
||||
* @param TAG - Path to endpoint (without host)
|
||||
* @param MSG - Name of the generated method
|
||||
*/
|
||||
#define OATPP_LOG(PRIORITY, TAG, ...) \
|
||||
OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_BINARY_SELECTOR(OATPP_LOG_MACRO_, (__VA_ARGS__)) (PRIORITY, TAG, __VA_ARGS__))
|
||||
|
||||
////////////////////////////
|
||||
////////////////////////////
|
||||
////////////////////////////
|
||||
|
||||
#ifndef OATPP_DISABLE_LOGV
|
||||
|
||||
/**
|
||||
* Log message with &l:Logger::PRIORITY_V; <br>
|
||||
* *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGV`*
|
||||
* @param TAG - message tag.
|
||||
* @param ...(1) - message.
|
||||
* @param ... - optional format parameter.
|
||||
*/
|
||||
#define OATPP_LOGv(TAG, ...) \
|
||||
OATPP_LOG(oatpp::Logger::PRIORITY_V, TAG, __VA_ARGS__);
|
||||
|
||||
#else
|
||||
#define OATPP_LOGv(TAG, ...)
|
||||
#endif
|
||||
|
||||
#ifndef OATPP_DISABLE_LOGD
|
||||
|
||||
/**
|
||||
* Log message with &l:Logger::PRIORITY_D; <br>
|
||||
* *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGD`*
|
||||
* @param TAG - message tag.
|
||||
* @param ...(1) - message
|
||||
* @param ... - optional format parameter.
|
||||
*/
|
||||
#define OATPP_LOGd(TAG, ...) \
|
||||
OATPP_LOG(oatpp::Logger::PRIORITY_D, TAG, __VA_ARGS__);
|
||||
|
||||
#else
|
||||
#define OATPP_LOGd(TAG, ...)
|
||||
#endif
|
||||
|
||||
#ifndef OATPP_DISABLE_LOGI
|
||||
|
||||
/**
|
||||
* Log message with &l:Logger::PRIORITY_I; <br>
|
||||
* *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGI`*
|
||||
* @param TAG - message tag.
|
||||
* @param ...(1) - message.
|
||||
* @param ... - optional format parameter.
|
||||
*/
|
||||
#define OATPP_LOGi(TAG, ...) \
|
||||
OATPP_LOG(oatpp::Logger::PRIORITY_I, TAG, __VA_ARGS__);
|
||||
|
||||
#else
|
||||
#define OATPP_LOGi(TAG, ...)
|
||||
#endif
|
||||
|
||||
#ifndef OATPP_DISABLE_LOGW
|
||||
|
||||
/**
|
||||
* Log message with &l:Logger::PRIORITY_W; <br>
|
||||
* *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGW`*
|
||||
* @param TAG - message tag.
|
||||
* @param ...(1) - message.
|
||||
* @param ... - optional format parameter.
|
||||
*/
|
||||
#define OATPP_LOGw(TAG, ...) \
|
||||
OATPP_LOG(oatpp::Logger::PRIORITY_W, TAG, __VA_ARGS__);
|
||||
|
||||
#else
|
||||
#define OATPP_LOGw(TAG, ...)
|
||||
#endif
|
||||
|
||||
#ifndef OATPP_DISABLE_LOGE
|
||||
|
||||
/**
|
||||
* Log message with &l:Logger::PRIORITY_E; <br>
|
||||
* *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGE`*
|
||||
* @param TAG - message tag.
|
||||
* @param ...(1) - message.
|
||||
* @param ... - optional format parameter.
|
||||
*/
|
||||
#define OATPP_LOGe(TAG, ...) \
|
||||
OATPP_LOG(oatpp::Logger::PRIORITY_E, TAG, __VA_ARGS__);
|
||||
|
||||
#else
|
||||
#define OATPP_LOGe(TAG, ...)
|
||||
#endif
|
||||
|
||||
#endif /* oatpp_base_Log_hpp */
|
@ -129,6 +129,10 @@ oatpp::String BufferOutputStream::toString() {
|
||||
return oatpp::String(reinterpret_cast<const char*>(m_data), m_position);
|
||||
}
|
||||
|
||||
std::string BufferOutputStream::toStdString() const {
|
||||
return std::string(reinterpret_cast<const char*>(m_data), static_cast<unsigned long>(m_position));
|
||||
}
|
||||
|
||||
oatpp::String BufferOutputStream::getSubstring(v_buff_size pos, v_buff_size count) {
|
||||
if(pos + count <= m_position) {
|
||||
return oatpp::String(reinterpret_cast<const char*>(m_data + pos), count);
|
||||
|
@ -127,6 +127,12 @@ public:
|
||||
*/
|
||||
oatpp::String toString();
|
||||
|
||||
/**
|
||||
* Copy data to `std::string`.
|
||||
* @return
|
||||
*/
|
||||
std::string toStdString() const;
|
||||
|
||||
/**
|
||||
* Create &id:oatpp::String; from part of buffer.
|
||||
* @param pos - starting position in buffer.
|
||||
|
@ -6,6 +6,8 @@ add_executable(oatppAllTests
|
||||
oatpp/async/LockTest.hpp
|
||||
oatpp/base/CommandLineArgumentsTest.cpp
|
||||
oatpp/base/CommandLineArgumentsTest.hpp
|
||||
oatpp/base/LogTest.cpp
|
||||
oatpp/base/LogTest.hpp
|
||||
oatpp/data/buffer/ProcessorTest.cpp
|
||||
oatpp/data/buffer/ProcessorTest.hpp
|
||||
oatpp/data/mapping/ObjectRemapperTest.cpp
|
||||
|
@ -66,6 +66,8 @@
|
||||
#include "oatpp/data/buffer/ProcessorTest.hpp"
|
||||
|
||||
#include "oatpp/base/CommandLineArgumentsTest.hpp"
|
||||
#include "oatpp/base/LogTest.hpp"
|
||||
|
||||
#include "oatpp/LoggerTest.hpp"
|
||||
|
||||
#include "oatpp/async/Coroutine.hpp"
|
||||
@ -80,172 +82,182 @@
|
||||
|
||||
namespace {
|
||||
|
||||
//#define LOG_PARAMS \
|
||||
//<< P
|
||||
|
||||
|
||||
|
||||
void runTests() {
|
||||
|
||||
oatpp::Environment::printCompilationConfig();
|
||||
//LOG("AAA", "MSG: {}", param1, param2);
|
||||
|
||||
OATPP_LOGD("Tests", "oatpp::String size=%lu", sizeof(oatpp::String))
|
||||
OATPP_LOGD("Tests", "std::string size=%lu", sizeof(std::string))
|
||||
OATPP_LOGD("Tests", "Vector size=%lu", sizeof(std::vector<int>))
|
||||
OATPP_LOGD("Tests", "Map size=%lu", sizeof(std::unordered_map<oatpp::String, oatpp::String>))
|
||||
OATPP_LOGD("Tests", "Tree size=%lu", sizeof(oatpp::data::mapping::Tree))
|
||||
|
||||
//return;
|
||||
|
||||
OATPP_LOGD("Tests", "coroutine handle size=%lu", sizeof(oatpp::async::CoroutineHandle))
|
||||
OATPP_LOGD("Tests", "coroutine size=%lu", sizeof(oatpp::async::AbstractCoroutine))
|
||||
OATPP_LOGD("Tests", "action size=%lu", sizeof(oatpp::async::Action))
|
||||
OATPP_LOGD("Tests", "class count=%d", oatpp::data::type::ClassId::getClassCount())
|
||||
|
||||
auto names = oatpp::data::type::ClassId::getRegisteredClassNames();
|
||||
v_int32 i = 0;
|
||||
for(auto& name : names) {
|
||||
OATPP_LOGD("CLASS", "%d --> '%s'", i, name)
|
||||
i ++;
|
||||
}
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::LoggerTest);
|
||||
OATPP_RUN_TEST(oatpp::base::CommandLineArgumentsTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::share::MemoryLabelTest);
|
||||
OATPP_RUN_TEST(oatpp::data::share::LazyStringMapTest);
|
||||
OATPP_RUN_TEST(oatpp::data::share::StringTemplateTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::buffer::ProcessorTest);
|
||||
OATPP_RUN_TEST(oatpp::data::stream::BufferStreamTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::mapping::TreeTest);
|
||||
OATPP_RUN_TEST(oatpp::data::mapping::ObjectToTreeMapperTest);
|
||||
OATPP_RUN_TEST(oatpp::data::mapping::TreeToObjectMapperTest);
|
||||
OATPP_RUN_TEST(oatpp::data::mapping::ObjectRemapperTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::type::ObjectWrapperTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::TypeTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::type::StringTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::type::PrimitiveTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::ListTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::VectorTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::UnorderedSetTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::PairListTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::UnorderedMapTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::AnyTest);
|
||||
OATPP_RUN_TEST(oatpp::data::type::EnumTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::type::ObjectTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::type::InterpretationTest);
|
||||
OATPP_RUN_TEST(oatpp::data::mapping::TypeResolverTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::data::resource::InMemoryDataTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::async::ConditionVariableTest);
|
||||
OATPP_RUN_TEST(oatpp::async::LockTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::utils::parser::CaretTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::provider::PoolTest);
|
||||
OATPP_RUN_TEST(oatpp::provider::PoolTemplateTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::json::EnumTest);
|
||||
OATPP_RUN_TEST(oatpp::json::BooleanTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::json::UnorderedSetTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::json::DeserializerTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::json::DTOMapperPerfTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::json::DTOMapperTest);
|
||||
OATPP_RUN_TEST(oatpp::test::encoding::Base64Test);
|
||||
OATPP_RUN_TEST(oatpp::test::encoding::UnicodeTest);
|
||||
OATPP_RUN_TEST(oatpp::test::encoding::UrlTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::network::UrlTest);
|
||||
OATPP_RUN_TEST(oatpp::test::network::ConnectionPoolTest);
|
||||
OATPP_RUN_TEST(oatpp::test::network::monitor::ConnectionMonitorTest);
|
||||
OATPP_RUN_TEST(oatpp::test::network::virtual_::PipeTest);
|
||||
OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::web::protocol::http::encoding::ChunkedTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::web::mime::multipart::StatefulParserTest);
|
||||
OATPP_RUN_TEST(oatpp::web::mime::ContentMappersTest);
|
||||
|
||||
OATPP_RUN_TEST(oatpp::test::web::server::HttpRouterTest);
|
||||
OATPP_RUN_TEST(oatpp::test::web::server::api::ApiControllerTest);
|
||||
OATPP_RUN_TEST(oatpp::test::web::server::handler::AuthorizationHandlerTest);
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::server::ServerStopTest test_virtual(0);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::server::ServerStopTest test_port(8000);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::PipelineTest test_virtual(0, 3000);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::PipelineTest test_port(8000, 3000);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::PipelineAsyncTest test_virtual(0, 3000);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::PipelineAsyncTest test_port(8000, 3000);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::FullTest test_virtual(0, 1000);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::FullTest test_port(8000, 5);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::FullAsyncTest test_virtual(0, 1000);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::FullAsyncTest test_port(8000, 5);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::FullAsyncClientTest test_virtual(0, 1000);
|
||||
test_virtual.run(20);
|
||||
|
||||
oatpp::test::web::FullAsyncClientTest test_port(8000, 5);
|
||||
test_port.run(1);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::web::ClientRetryTest test_virtual(0);
|
||||
test_virtual.run();
|
||||
|
||||
oatpp::test::web::ClientRetryTest test_port(8000);
|
||||
test_port.run();
|
||||
|
||||
}
|
||||
// oatpp::Environment::printCompilationConfig();
|
||||
//
|
||||
// OATPP_LOGD("Tests", "oatpp::String size={}", sizeof(oatpp::String))
|
||||
//
|
||||
// OATPP_LOGD("Tests", "oatpp::String size=%lu", sizeof(oatpp::String))
|
||||
// OATPP_LOGD("Tests", "std::string size=%lu", sizeof(std::string))
|
||||
// OATPP_LOGD("Tests", "Vector size=%lu", sizeof(std::vector<int>))
|
||||
// OATPP_LOGD("Tests", "Map size=%lu", sizeof(std::unordered_map<oatpp::String, oatpp::String>))
|
||||
// OATPP_LOGD("Tests", "Tree size=%lu", sizeof(oatpp::data::mapping::Tree))
|
||||
//
|
||||
// //return;
|
||||
//
|
||||
// OATPP_LOGD("Tests", "coroutine handle size=%lu", sizeof(oatpp::async::CoroutineHandle))
|
||||
// OATPP_LOGD("Tests", "coroutine size=%lu", sizeof(oatpp::async::AbstractCoroutine))
|
||||
// OATPP_LOGD("Tests", "action size=%lu", sizeof(oatpp::async::Action))
|
||||
// OATPP_LOGD("Tests", "class count=%d", oatpp::data::type::ClassId::getClassCount())
|
||||
//
|
||||
// auto names = oatpp::data::type::ClassId::getRegisteredClassNames();
|
||||
// v_int32 i = 0;
|
||||
// for(auto& name : names) {
|
||||
// OATPP_LOGD("CLASS", "%d --> '%s'", i, name)
|
||||
// i ++;
|
||||
// }
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::test::LoggerTest);
|
||||
// OATPP_RUN_TEST(oatpp::base::CommandLineArgumentsTest);
|
||||
OATPP_RUN_TEST(oatpp::base::LogTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::share::MemoryLabelTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::share::LazyStringMapTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::share::StringTemplateTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::buffer::ProcessorTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::stream::BufferStreamTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::mapping::TreeTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::mapping::ObjectToTreeMapperTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::mapping::TreeToObjectMapperTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::mapping::ObjectRemapperTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::type::ObjectWrapperTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::TypeTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::type::StringTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::type::PrimitiveTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::ListTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::VectorTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::UnorderedSetTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::PairListTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::UnorderedMapTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::AnyTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::type::EnumTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::type::ObjectTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::type::InterpretationTest);
|
||||
// OATPP_RUN_TEST(oatpp::data::mapping::TypeResolverTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::data::resource::InMemoryDataTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::async::ConditionVariableTest);
|
||||
// OATPP_RUN_TEST(oatpp::async::LockTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::utils::parser::CaretTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::provider::PoolTest);
|
||||
// OATPP_RUN_TEST(oatpp::provider::PoolTemplateTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::json::EnumTest);
|
||||
// OATPP_RUN_TEST(oatpp::json::BooleanTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::json::UnorderedSetTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::json::DeserializerTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::json::DTOMapperPerfTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::json::DTOMapperTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::encoding::Base64Test);
|
||||
// OATPP_RUN_TEST(oatpp::test::encoding::UnicodeTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::encoding::UrlTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::test::network::UrlTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::network::ConnectionPoolTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::network::monitor::ConnectionMonitorTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::network::virtual_::PipeTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::test::web::protocol::http::encoding::ChunkedTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::test::web::mime::multipart::StatefulParserTest);
|
||||
// OATPP_RUN_TEST(oatpp::web::mime::ContentMappersTest);
|
||||
//
|
||||
// OATPP_RUN_TEST(oatpp::test::web::server::HttpRouterTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::web::server::api::ApiControllerTest);
|
||||
// OATPP_RUN_TEST(oatpp::test::web::server::handler::AuthorizationHandlerTest);
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::server::ServerStopTest test_virtual(0);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::server::ServerStopTest test_port(8000);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::PipelineTest test_virtual(0, 3000);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::PipelineTest test_port(8000, 3000);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::PipelineAsyncTest test_virtual(0, 3000);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::PipelineAsyncTest test_port(8000, 3000);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::FullTest test_virtual(0, 1000);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::FullTest test_port(8000, 5);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::FullAsyncTest test_virtual(0, 1000);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::FullAsyncTest test_port(8000, 5);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::FullAsyncClientTest test_virtual(0, 1000);
|
||||
// test_virtual.run(20);
|
||||
//
|
||||
// oatpp::test::web::FullAsyncClientTest test_port(8000, 5);
|
||||
// test_port.run(1);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// {
|
||||
//
|
||||
// oatpp::test::web::ClientRetryTest test_virtual(0);
|
||||
// test_virtual.run();
|
||||
//
|
||||
// oatpp::test::web::ClientRetryTest test_port(8000);
|
||||
// test_port.run();
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
61
test/oatpp/base/LogTest.cpp
Normal file
61
test/oatpp/base/LogTest.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "LogTest.hpp"
|
||||
|
||||
#include "oatpp/base/Log.hpp"
|
||||
|
||||
namespace oatpp::base {
|
||||
|
||||
void LogTest::onRun() {
|
||||
|
||||
// oatpp::String val = "hello";
|
||||
// oatpp::Float64 fv;
|
||||
//
|
||||
// LogMessage msg("{} double={}, float={}");
|
||||
//
|
||||
// //msg << val << fv << "<end>";
|
||||
//
|
||||
// LogMessage::log(0, TAG, msg << 1 << 2 << 3);
|
||||
//
|
||||
// //std::cout << msg.toStdString() << std::endl;
|
||||
|
||||
OATPP_LOGv(TAG, "1={}, 2={}, 3={}", 1, 2, 3)
|
||||
OATPP_LOGv(TAG, "empty params")
|
||||
|
||||
OATPP_LOGd(TAG, "1={}, 2={}, 3={}", 1, 2, 3)
|
||||
OATPP_LOGd(TAG, "empty params")
|
||||
|
||||
OATPP_LOGi(TAG, "1={}, 2={}, 3={}", 1, 2, 3)
|
||||
OATPP_LOGi(TAG, "empty params")
|
||||
|
||||
OATPP_LOGw(TAG, "1={}, 2={}, 3={}", 1, 2, 3)
|
||||
OATPP_LOGw(TAG, "empty params")
|
||||
|
||||
OATPP_LOGe(TAG, "1={}, 2={}, 3={}", 1, 2, 3)
|
||||
OATPP_LOGe(TAG, "empty params")
|
||||
|
||||
}
|
||||
|
||||
}
|
45
test/oatpp/base/LogTest.hpp
Normal file
45
test/oatpp/base/LogTest.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef oatpp_base_LogTest_hpp
|
||||
#define oatpp_base_LogTest_hpp
|
||||
|
||||
#include "oatpp-test/UnitTest.hpp"
|
||||
|
||||
namespace oatpp::base {
|
||||
|
||||
/**
|
||||
* Test command line arguments parsing.
|
||||
*/
|
||||
class LogTest : public oatpp::test::UnitTest{
|
||||
public:
|
||||
|
||||
LogTest():UnitTest("TEST[base::LogTest]"){}
|
||||
void onRun() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* oatpp_base_LogTest_hpp */
|
Loading…
x
Reference in New Issue
Block a user