add timestamp
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <forward_list>
|
#include <forward_list>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
|
||||||
@@ -48,5 +49,4 @@ namespace hack::concepts
|
|||||||
is_forward_list<T> ||
|
is_forward_list<T> ||
|
||||||
std::is_array<T>() ||
|
std::is_array<T>() ||
|
||||||
is_string<T>), bool>() == true;
|
is_string<T>), bool>() == true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,24 +25,24 @@ namespace hack
|
|||||||
|
|
||||||
void log()
|
void log()
|
||||||
{
|
{
|
||||||
std::cout << view::color::bold << view::color::red <<"["+m_service+"] " << view::color::reset
|
std::cout << utils::color::bold << utils::color::red <<"["+m_service+"] " << utils::color::reset
|
||||||
<< m_location.file_name() << ":"
|
<< m_location.file_name() << ":"
|
||||||
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
|
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
|
||||||
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
|
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
|
||||||
<< m_title << std::endl;
|
<< m_title << std::endl;
|
||||||
|
|
||||||
if (!m_description.empty())
|
if (!m_description.empty())
|
||||||
std::cout << view::color::bold << view::color::red <<"["+m_service+"] " << view::color::reset
|
std::cout << utils::color::bold << utils::color::red <<"["+m_service+"] " << utils::color::reset
|
||||||
<< m_location.file_name() << ":"
|
<< m_location.file_name() << ":"
|
||||||
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
|
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
|
||||||
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
|
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
|
||||||
<< m_description << std::endl;
|
<< m_description << std::endl;
|
||||||
|
|
||||||
if (!m_system_error.empty())
|
if (!m_system_error.empty())
|
||||||
std::cout << view::color::bold << view::color::red <<"["+m_service+"] " << view::color::reset
|
std::cout << utils::color::bold << utils::color::red <<"["+m_service+"] " << utils::color::reset
|
||||||
<< m_location.file_name() << ":"
|
<< m_location.file_name() << ":"
|
||||||
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
|
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
|
||||||
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
|
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
|
||||||
<< m_system_error << std::endl;
|
<< m_system_error << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,16 +42,16 @@ namespace hack
|
|||||||
void prepare(T t, U u)
|
void prepare(T t, U u)
|
||||||
{
|
{
|
||||||
std::cout << t
|
std::cout << t
|
||||||
<< u.file_name() << ":" << view::color::reset
|
<< u.file_name() << ":" << utils::color::reset
|
||||||
<< view::color::italic << view::color::yellow << u.function_name() << "()" << view::color::reset
|
<< utils::color::italic << utils::color::yellow << u.function_name() << "()" << utils::color::reset
|
||||||
<< view::color::bold << view::color::blue << "[" << u.line() << "]" << view::color::reset << ": ";
|
<< utils::color::bold << utils::color::blue << "[" << u.line() << "]" << utils::color::reset << ": ";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print() { std::cout << std::endl; }
|
static void print() { std::cout << std::endl; }
|
||||||
|
|
||||||
static std::ostream& make_type_view(std::ostream &os)
|
static std::ostream& make_type_view(std::ostream &os)
|
||||||
{
|
{
|
||||||
os << view::color::bold << view::color::green << "[ok]" << view::color::reset << view::color::green;
|
os << utils::color::bold << utils::color::green << "[ok]" << utils::color::reset << utils::color::green;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ namespace hack
|
|||||||
private:
|
private:
|
||||||
static std::ostream& make_type_view(std::ostream &os)
|
static std::ostream& make_type_view(std::ostream &os)
|
||||||
{
|
{
|
||||||
os << view::color::bold << view::color::yellow << "[WARN]" << view::color::reset << view::color::yellow;
|
os << utils::color::bold << utils::color::yellow << "[WARN]" << utils::color::reset << utils::color::yellow;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -201,7 +201,7 @@ namespace hack
|
|||||||
private:
|
private:
|
||||||
static std::ostream& make_type_view(std::ostream &os)
|
static std::ostream& make_type_view(std::ostream &os)
|
||||||
{
|
{
|
||||||
os << view::color::bold << view::color::red << "[ERROR]" << view::color::reset << view::color::red;
|
os << utils::color::bold << utils::color::red << "[ERROR]" << utils::color::reset << utils::color::red;
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace hack::view::color
|
namespace hack::utils::color
|
||||||
{
|
{
|
||||||
template<typename CharT, typename Traits>
|
template<typename CharT, typename Traits>
|
||||||
std::basic_ostream<CharT, Traits>& reset(std::basic_ostream<CharT, Traits> &os)
|
std::basic_ostream<CharT, Traits>& reset(std::basic_ostream<CharT, Traits> &os)
|
||||||
|
|||||||
17
src/hack/utils/timestamp.hpp
Normal file
17
src/hack/utils/timestamp.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace hack::utils
|
||||||
|
{
|
||||||
|
// return current time
|
||||||
|
inline std::string timestamp()
|
||||||
|
{
|
||||||
|
auto now = std::chrono::system_clock::now();
|
||||||
|
auto in_time_t = std::chrono::system_clock::to_time_t(now);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::put_time(std::localtime(&in_time_t), "%Y-%m-%d-%H.%M.%S");
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user