add timestamp

This commit is contained in:
2025-02-21 13:39:18 +03:00
parent 9bf9ffc6af
commit 709d2ce3df
5 changed files with 34 additions and 17 deletions

View File

@@ -7,6 +7,7 @@
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
#include <string_view>
#include <concepts>
@@ -48,5 +49,4 @@ namespace hack::concepts
is_forward_list<T> ||
std::is_array<T>() ||
is_string<T>), bool>() == true;
}

View File

@@ -25,24 +25,24 @@ namespace hack
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() << ":"
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
<< m_title << std::endl;
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() << ":"
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
<< m_description << std::endl;
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() << ":"
<< view::color::italic << view::color::yellow << m_location.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << m_location.line() << "]" << view::color::reset << ": "
<< utils::color::italic << utils::color::yellow << m_location.function_name() << "()" << utils::color::reset
<< utils::color::bold << utils::color::blue << "[" << m_location.line() << "]" << utils::color::reset << ": "
<< m_system_error << std::endl;
}

View File

@@ -42,16 +42,16 @@ namespace hack
void prepare(T t, U u)
{
std::cout << t
<< u.file_name() << ":" << view::color::reset
<< view::color::italic << view::color::yellow << u.function_name() << "()" << view::color::reset
<< view::color::bold << view::color::blue << "[" << u.line() << "]" << view::color::reset << ": ";
<< u.file_name() << ":" << utils::color::reset
<< utils::color::italic << utils::color::yellow << u.function_name() << "()" << utils::color::reset
<< utils::color::bold << utils::color::blue << "[" << u.line() << "]" << utils::color::reset << ": ";
}
static void print() { std::cout << std::endl; }
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;
}
@@ -171,7 +171,7 @@ namespace hack
private:
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;
}
};
@@ -201,7 +201,7 @@ namespace hack
private:
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;
}
};

View File

@@ -2,7 +2,7 @@
#include <iostream>
namespace hack::view::color
namespace hack::utils::color
{
template<typename CharT, typename Traits>
std::basic_ostream<CharT, Traits>& reset(std::basic_ostream<CharT, Traits> &os)

View 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();
}
}