aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee')
-rw-r--r--contrib/epee/include/console_handler.h6
-rw-r--r--contrib/epee/include/misc_log_ex.h1435
-rw-r--r--contrib/epee/include/net/abstract_tcp_server.h3
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h4
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl85
-rw-r--r--contrib/epee/include/net/abstract_tcp_server_cp.h3
-rw-r--r--contrib/epee/include/net/abstract_tcp_server_cp.inl3
-rw-r--r--contrib/epee/include/net/http_auth.h3
-rw-r--r--contrib/epee/include/net/http_base.h4
-rw-r--r--contrib/epee/include/net/http_client.h17
-rw-r--r--contrib/epee/include/net/http_client_abstract_invoke.h3
-rw-r--r--contrib/epee/include/net/http_client_base.h3
-rw-r--r--contrib/epee/include/net/http_client_via_api_helper.h3
-rw-r--r--contrib/epee/include/net/http_protocol_handler.h3
-rw-r--r--contrib/epee/include/net/http_protocol_handler.inl19
-rw-r--r--contrib/epee/include/net/http_server_cp.h4
-rw-r--r--contrib/epee/include/net/http_server_cp2.h4
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h9
-rw-r--r--contrib/epee/include/net/http_server_impl_base.h8
-rw-r--r--contrib/epee/include/net/levin_client.inl4
-rw-r--r--contrib/epee/include/net/levin_client_async.h3
-rw-r--r--contrib/epee/include/net/levin_helper.h3
-rw-r--r--contrib/epee/include/net/levin_protocol_handler.h11
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h30
-rw-r--r--contrib/epee/include/net/net_helper.h17
-rw-r--r--contrib/epee/include/net/net_parse_helpers.h2
-rw-r--r--contrib/epee/include/net/net_utils_base.h43
-rw-r--r--contrib/epee/include/profile_tools.h6
-rw-r--r--contrib/epee/include/storages/levin_abstract_invoke2.h7
-rw-r--r--contrib/epee/include/storages/portable_storage_from_json.h4
-rw-r--r--contrib/epee/src/CMakeLists.txt2
-rw-r--r--contrib/epee/src/mlog.cpp319
32 files changed, 603 insertions, 1467 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 554a48488..54e3e966d 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -277,11 +277,11 @@ namespace epee
{
if (!m_prompt.empty())
{
- epee::log_space::set_console_color(epee::log_space::console_color_yellow, true);
+ epee::set_console_color(epee::console_color_yellow, true);
std::cout << m_prompt;
if (' ' != m_prompt.back())
std::cout << ' ';
- epee::log_space::reset_console_color();
+ epee::reset_console_color();
std::cout.flush();
}
}
@@ -310,7 +310,7 @@ namespace epee
}
if (!get_line_ret)
{
- LOG_PRINT("Failed to read line.", LOG_LEVEL_0);
+ MERROR("Failed to read line.");
}
string_tools::trim(command);
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index 82760dfff..f04282438 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -28,9 +28,13 @@
#ifndef _MISC_LOG_EX_H_
#define _MISC_LOG_EX_H_
-//#include <windows.h>
-#include <atomic>
-#include <string>
+#include "static_initializer.h"
+#include "string_tools.h"
+#include "time_helper.h"
+#include "misc_os_dependent.h"
+
+#include "syncobj.h"
+
#include <iostream>
#include <sstream>
#include <iomanip>
@@ -38,42 +42,79 @@
#include <algorithm>
#include <list>
#include <map>
+#include <string>
#include <time.h>
#include <boost/cstdint.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
-#if defined(WIN32)
-#include <io.h>
-#else
-#include <unistd.h>
-#endif
-
-#include "static_initializer.h"
-#include "string_tools.h"
-#include "time_helper.h"
-#include "misc_os_dependent.h"
-
-#include "syncobj.h"
-
-
-#define LOG_LEVEL_SILENT -1
-#define LOG_LEVEL_0 0
-#define LOG_LEVEL_1 1
-#define LOG_LEVEL_2 2
-#define LOG_LEVEL_3 3
-#define LOG_LEVEL_4 4
-#define LOG_LEVEL_MIN LOG_LEVEL_SILENT
-#define LOG_LEVEL_MAX LOG_LEVEL_4
-
-
-#define LOGGER_NULL 0
-#define LOGGER_FILE 1
-#define LOGGER_DEBUGGER 2
-#define LOGGER_CONSOLE 3
-#define LOGGER_DUMP 4
-
+#define ELPP_THREAD_SAFE
+#define ELPP_DEFAULT_LOG_FILE ""
+#define ELPP_STACKTRACE 0
+#define ELPP_DISABLE_DEFAULT_CRASH_HANDLING
+#define ELPP_DISABLE_CHECK_MACROS
+#include "easylogging++.h"
+
+#define MONERO_DEFAULT_LOG_CATEGORY "default"
+
+#define MCFATAL(cat,x) CLOG(FATAL,cat) << x
+#define MCERROR(cat,x) CLOG(ERROR,cat) << x
+#define MCWARNING(cat,x) CLOG(WARNING,cat) << x
+#define MCINFO(cat,x) CLOG(INFO,cat) << x
+#define MCDEBUG(cat,x) CLOG(DEBUG,cat) << x
+#define MCTRACE(cat,x) CLOG(TRACE,cat) << x
+#define MCLOG(level,cat,x) ELPP_WRITE_LOG(el::base::Writer, level, el::base::DispatchAction::NormalLog, cat) << x
+
+#define MCLOG_COLOR(level,cat,color,x) MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")
+#define MCLOG_RED(level,cat,x) MCLOG_COLOR(level,cat,"31",x)
+#define MCLOG_GREEN(level,cat,x) MCLOG_COLOR(level,cat,"32",x)
+#define MCLOG_YELLOW(level,cat,x) MCLOG_COLOR(level,cat,"33",x)
+#define MCLOG_BLUE(level,cat,x) MCLOG_COLOR(level,cat,"34",x)
+#define MCLOG_MAGENTA(level,cat,x) MCLOG_COLOR(level,cat,"35",x)
+#define MCLOG_CYAN(level,cat,x) MCLOG_COLOR(level,cat,"36",x)
+
+#define MLOG_RED(level,x) MCLOG_RED(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG_GREEN(level,x) MCLOG_GREEN(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG_YELLOW(level,x) MCLOG_YELLOW(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG_BLUE(level,x) MCLOG_BLUE(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG_MAGENTA(level,x) MCLOG_MAGENTA(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG_CYAN(level,x) MCLOG_CYAN(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+
+#define MFATAL(x) MCFATAL(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MERROR(x) MCERROR(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MWARNING(x) MCWARNING(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MINFO(x) MCINFO(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MDEBUG(x) MCDEBUG(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MTRACE(x) MCTRACE(MONERO_DEFAULT_LOG_CATEGORY,x)
+#define MLOG(level,x) MCLOG(level,MONERO_DEFAULT_LOG_CATEGORY,x)
+
+#define MGINFO(x) MCINFO("global",x)
+#define MGINFO_RED(x) MCLOG_RED(el::Level::Info, "global",x)
+#define MGINFO_GREEN(x) MCLOG_GREEN(el::Level::Info, "global",x)
+#define MGINFO_YELLOW(x) MCLOG_YELLOW(el::Level::Info, "global",x)
+#define MGINFO_BLUE(x) MCLOG_BLUE(el::Level::Info, "global",x)
+#define MGINFO_MAGENTA(x) MCLOG_MAGENTA(el::Level::Info, "global",x)
+#define MGINFO_CYAN(x) MCLOG_CYAN(el::Level::Info, "global",x)
+
+#define LOG_ERROR(x) MERROR(x)
+#define LOG_PRINT_L0(x) MWARNING(x)
+#define LOG_PRINT_L1(x) MINFO(x)
+#define LOG_PRINT_L2(x) MDEBUG(x)
+#define LOG_PRINT_L3(x) MTRACE(x)
+#define LOG_PRINT_L4(x) MTRACE(x)
+
+#define _dbg3(x) MTRACE(x)
+#define _dbg2(x) MDEBUG(x)
+#define _dbg1(x) MDEBUG(x)
+#define _info(x) MINFO(x)
+#define _note(x) MINFO(x)
+#define _fact(x) MINFO(x)
+#define _mark(x) MINFO(x)
+#define _warn(x) MWARNING(x)
+#define _erro(x) MERROR(x)
+
+#define MLOG_SET_THREAD_NAME(x) el::Loggers::setThreadName(x)
#ifndef LOCAL_ASSERT
#include <assert.h>
@@ -85,6 +126,12 @@
#endif
+std::string mlog_get_default_log_path(const char *default_filename);
+void mlog_configure(const std::string &filename_base, bool console);
+void mlog_set_categories(const char *categories);
+void mlog_set_log_level(int level);
+void mlog_set_log(const char *log);
+
namespace epee
{
namespace debug
@@ -97,1312 +144,8 @@ namespace debug
return e;
}
}
-namespace log_space
-{
- class logger;
- class log_message;
- class log_singletone;
-
- /************************************************************************/
- /* */
- /************************************************************************/
- enum console_colors
- {
- console_color_default,
- console_color_white,
- console_color_red,
- console_color_green,
- console_color_blue,
- console_color_cyan,
- console_color_magenta,
- console_color_yellow
- };
-
-
- struct ibase_log_stream
- {
- ibase_log_stream(){}
- virtual ~ibase_log_stream(){}
- virtual bool out_buffer( const char* buffer, int buffer_len , int log_level, int color, const char* plog_name = NULL)=0;
- virtual int get_type(){return 0;}
-
- virtual bool set_max_logfile_size(uint64_t max_size){return true;};
- virtual bool set_log_rotate_cmd(const std::string& cmd){return true;};
- };
-
- /************************************************************************/
- /* */
- /************************************************************************/
- /*struct ibase_log_value
- {
- public:
- virtual void debug_out( std::stringstream* p_stream)const = 0;
- };*/
-
- /************************************************************************/
- /* */
- /************************************************************************/
- /*class log_message: public std::stringstream
- {
- public:
- log_message(const log_message& lm): std::stringstream(), std::stringstream::basic_ios()
- {}
- log_message(){}
-
- template<class T>
- log_message& operator<< (T t)
- {
- std::stringstream* pstrstr = this;
- (*pstrstr) << t;
-
- return *this;
- }
- };
- inline
- log_space::log_message& operator<<(log_space::log_message& sstream, const ibase_log_value& log_val)
- {
- log_val.debug_out(&sstream);
- return sstream;
- }
- */
- /************************************************************************/
- /* */
- /************************************************************************/
- struct delete_ptr
- {
- template <class P>
- void operator() (P p)
- {
- delete p.first;
- }
- };
-
- /************************************************************************/
- /* */
- /************************************************************************/
- //------------------------------------------------------------------------
-#define max_dbg_str_len 80
-#ifdef _MSC_VER
- class debug_output_stream: public ibase_log_stream
- {
- virtual bool out_buffer( const char* buffer, int buffer_len , int log_level, int color, const char* plog_name = NULL)
- {
- for ( int i = 0; i < buffer_len; i = i + max_dbg_str_len )
- {
- std::string s( buffer + i, buffer_len- i < max_dbg_str_len ?
- buffer_len - i : max_dbg_str_len );
-
- ::OutputDebugStringA( s.c_str() );
- }
- return true;
- }
-
- };
-#endif
-
- inline bool is_stdout_a_tty()
- {
- static std::atomic<bool> initialized(false);
- static std::atomic<bool> is_a_tty(false);
-
- if (!initialized.load(std::memory_order_acquire))
- {
-#if defined(WIN32)
- is_a_tty.store(0 != _isatty(_fileno(stdout)), std::memory_order_relaxed);
-#else
- is_a_tty.store(0 != isatty(fileno(stdout)), std::memory_order_relaxed);
-#endif
- initialized.store(true, std::memory_order_release);
- }
-
- return is_a_tty.load(std::memory_order_relaxed);
- }
-
- inline void set_console_color(int color, bool bright)
- {
- if (!is_stdout_a_tty())
- return;
-
- switch(color)
- {
- case console_color_default:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE| (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;37m";
- else
- std::cout << "\033[0m";
-#endif
- }
- break;
- case console_color_white:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;37m";
- else
- std::cout << "\033[0;37m";
-#endif
- }
- break;
- case console_color_red:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;31m";
- else
- std::cout << "\033[0;31m";
-#endif
- }
- break;
- case console_color_green:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;32m";
- else
- std::cout << "\033[0;32m";
-#endif
- }
- break;
-
- case console_color_blue:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_INTENSITY);//(bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;34m";
- else
- std::cout << "\033[0;34m";
-#endif
- }
- break;
-
- case console_color_cyan:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;36m";
- else
- std::cout << "\033[0;36m";
-#endif
- }
- break;
-
- case console_color_magenta:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;35m";
- else
- std::cout << "\033[0;35m";
-#endif
- }
- break;
-
- case console_color_yellow:
- {
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
-#else
- if(bright)
- std::cout << "\033[1;33m";
- else
- std::cout << "\033[0;33m";
-#endif
- }
- break;
-
- }
- }
-
- inline void reset_console_color() {
- if (!is_stdout_a_tty())
- return;
-
-#ifdef WIN32
- HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
-#else
- std::cout << "\033[0m";
- std::cout.flush();
-#endif
- }
-
- class console_output_stream: public ibase_log_stream
- {
-#ifdef _MSC_VER
- bool m_have_to_kill_console;
-#endif
-
- public:
- console_output_stream()
- {
-#ifdef _MSC_VER
-
- if(!::GetStdHandle(STD_OUTPUT_HANDLE))
- m_have_to_kill_console = true;
- else
- m_have_to_kill_console = false;
-
- ::AllocConsole();
-#endif
- }
-
- ~console_output_stream()
- {
-#ifdef _MSC_VER
- if(m_have_to_kill_console)
- ::FreeConsole();
-#endif
- }
- int get_type(){return LOGGER_CONSOLE;}
-
-
-
- virtual bool out_buffer( const char* buffer, int buffer_len , int log_level, int color, const char* plog_name = NULL)
- {
- if(plog_name)
- return true; //skip alternative logs from console
-
- set_console_color(color, log_level < 1);
-
-#ifdef _MSC_VER
- const char* ptarget_buf = NULL;
- char* pallocated_buf = NULL;
-
- //
- int i = 0;
- for(; i < buffer_len; i++)
- if(buffer[i] == '\a') break;
- if(i == buffer_len)
- ptarget_buf = buffer;
- else
- {
- pallocated_buf = new char[buffer_len];
- ptarget_buf = pallocated_buf;
- for(i = 0; i < buffer_len; i++)
- {
- if(buffer[i] == '\a')
- pallocated_buf[i] = '^';
- else
- pallocated_buf[i] = buffer[i];
- }
- }
-
- //uint32_t b = 0;
- //::WriteConsoleA(::GetStdHandle(STD_OUTPUT_HANDLE), ptarget_buf, buffer_len, (DWORD*)&b, 0);
- std::cout << ptarget_buf;
- if(pallocated_buf) delete [] pallocated_buf;
-#else
- std::string buf(buffer, buffer_len);
- for(size_t i = 0; i!= buf.size(); i++)
- {
- if(buf[i] == 7 || (buf[i]&0xff) == 0x95)
- buf[i] = '^';
- }
-
- std::cout << buf;
- std::cout << std::flush;
-#endif
- reset_console_color();
- return true;
- }
-
-
- };
-
- inline bool rotate_log_file(const char* pfile_path)
- {
-#ifdef _MSC_VER
- if(!pfile_path)
- return false;
-
- std::string file_path = pfile_path;
- std::string::size_type a = file_path .rfind('.');
- if ( a != std::string::npos )
- file_path .erase( a, file_path .size());
-
- ::DeleteFileA( (file_path + ".0").c_str() );
- ::MoveFileA( (file_path + ".log").c_str(), (file_path + ".0").c_str() );
-#else
- return false;//not implemented yet
-#endif
- return true;
- }
-
-
-
-
- //--------------------------------------------------------------------------//
- class file_output_stream : public ibase_log_stream
- {
- public:
- typedef std::map<std::string, std::ofstream*> named_log_streams;
-
- file_output_stream( std::string default_log_file_name, std::string log_path )
- {
- m_default_log_filename = default_log_file_name;
- m_max_logfile_size = 0;
- m_default_log_path = log_path;
- m_pdefault_file_stream = add_new_stream_and_open(default_log_file_name.c_str());
- }
-
- ~file_output_stream()
- {
- for(named_log_streams::iterator it = m_log_file_names.begin(); it!=m_log_file_names.end(); it++)
- {
- if ( it->second->is_open() )
- {
- it->second->flush();
- it->second->close();
- }
- delete it->second;
- }
- }
- private:
- named_log_streams m_log_file_names;
- std::string m_default_log_path;
- std::ofstream* m_pdefault_file_stream;
- std::string m_log_rotate_cmd;
- std::string m_default_log_filename;
- uint64_t m_max_logfile_size;
-
-
- std::ofstream* add_new_stream_and_open(const char* pstream_name)
- {
- //log_space::rotate_log_file((m_default_log_path + "\\" + pstream_name).c_str());
-
- std::ofstream* pstream = (m_log_file_names[pstream_name] = new std::ofstream);
- std::string target_path = m_default_log_path + "/" + pstream_name;
- pstream->open( target_path.c_str(), std::ios_base::out | std::ios::app /*ios_base::trunc */);
- if(pstream->fail())
- return NULL;
- return pstream;
- }
-
- bool set_max_logfile_size(uint64_t max_size)
- {
- m_max_logfile_size = max_size;
- return true;
- }
-
- bool set_log_rotate_cmd(const std::string& cmd)
- {
- m_log_rotate_cmd = cmd;
- return true;
- }
-
-
-
- virtual bool out_buffer( const char* buffer, int buffer_len, int log_level, int color, const char* plog_name = NULL )
- {
- std::ofstream* m_target_file_stream = m_pdefault_file_stream;
- if(plog_name)
- { //find named stream
- named_log_streams::iterator it = m_log_file_names.find(plog_name);
- if(it == m_log_file_names.end())
- m_target_file_stream = add_new_stream_and_open(plog_name);
- else
- m_target_file_stream = it->second;
- }
- if(!m_target_file_stream || !m_target_file_stream->is_open())
- return false;//TODO: add assert here
-
- m_target_file_stream->write(buffer, buffer_len );
- m_target_file_stream->flush();
-
- if(m_max_logfile_size)
- {
- std::ofstream::pos_type pt = m_target_file_stream->tellp();
- uint64_t current_sz = pt;
- if(current_sz > m_max_logfile_size)
- {
- std::cout << "current_sz= " << current_sz << " m_max_logfile_size= " << m_max_logfile_size << std::endl;
- std::string log_file_name;
- if(!plog_name)
- log_file_name = m_default_log_filename;
- else
- log_file_name = plog_name;
-
- m_target_file_stream->close();
- std::string new_log_file_name = log_file_name;
-
- time_t tm = 0;
- time(&tm);
-
- int err_count = 0;
- boost::system::error_code ec;
- do
- {
- new_log_file_name = string_tools::cut_off_extension(log_file_name);
- if(err_count)
- new_log_file_name += misc_utils::get_time_str_v2(tm) + "(" + boost::lexical_cast<std::string>(err_count) + ")" + ".log";
- else
- new_log_file_name += misc_utils::get_time_str_v2(tm) + ".log";
-
- err_count++;
- }while(boost::filesystem::exists(m_default_log_path + "/" + new_log_file_name, ec));
-
- std::string new_log_file_path = m_default_log_path + "/" + new_log_file_name;
- boost::filesystem::rename(m_default_log_path + "/" + log_file_name, new_log_file_path, ec);
- if(ec)
- {
- std::cout << "Filed to rename, ec = " << ec.message() << std::endl;
- }
-
- if(m_log_rotate_cmd.size())
- {
-
- std::string m_log_rotate_cmd_local_copy = m_log_rotate_cmd;
- //boost::replace_all(m_log_rotate_cmd, "[*SOURCE*]", new_log_file_path);
- boost::replace_all(m_log_rotate_cmd_local_copy, "[*TARGET*]", new_log_file_path);
-
- misc_utils::call_sys_cmd(m_log_rotate_cmd_local_copy);
- }
-
- m_target_file_stream->open( (m_default_log_path + "/" + log_file_name).c_str(), std::ios_base::out | std::ios::app /*ios_base::trunc */);
- if(m_target_file_stream->fail())
- return false;
- }
- }
-
- return true;
- }
- int get_type(){return LOGGER_FILE;}
- };
- /************************************************************************/
- /* */
- /************************************************************************/
- class log_stream_splitter
- {
- public:
- typedef std::list<std::pair<ibase_log_stream*, int> > streams_container;
-
- log_stream_splitter(){}
- ~log_stream_splitter()
- {
- //free pointers
- std::for_each(m_log_streams.begin(), m_log_streams.end(), delete_ptr());
- }
-
- bool set_max_logfile_size(uint64_t max_size)
- {
- for(streams_container::iterator it = m_log_streams.begin(); it!=m_log_streams.end();it++)
- it->first->set_max_logfile_size(max_size);
- return true;
- }
-
- bool set_log_rotate_cmd(const std::string& cmd)
- {
- for(streams_container::iterator it = m_log_streams.begin(); it!=m_log_streams.end();it++)
- it->first->set_log_rotate_cmd(cmd);
- return true;
- }
-
- bool do_log_message(const std::string& rlog_mes, int log_level, int color, const char* plog_name = NULL)
- {
- std::string str_mess = rlog_mes;
- size_t str_len = str_mess.size();
- const char* pstr = str_mess.c_str();
- for(streams_container::iterator it = m_log_streams.begin(); it!=m_log_streams.end();it++)
- if(it->second >= log_level)
- it->first->out_buffer(pstr, (int)str_len, log_level, color, plog_name);
- return true;
- }
-
- bool add_logger( int type, const char* pdefault_file_name, const char* pdefault_log_folder, int log_level_limit = LOG_LEVEL_4 )
- {
- ibase_log_stream* ls = NULL;
-
- switch( type )
- {
- case LOGGER_FILE:
- ls = new file_output_stream( pdefault_file_name, pdefault_log_folder );
- break;
-
- case LOGGER_DEBUGGER:
-#ifdef _MSC_VER
- ls = new debug_output_stream( );
-#else
- return false;//not implemented yet
-#endif
- break;
- case LOGGER_CONSOLE:
- ls = new console_output_stream( );
- break;
- }
-
- if ( ls ) {
- m_log_streams.push_back(streams_container::value_type(ls, log_level_limit));
- return true;
- }
- return ls ? true:false;
- }
- bool add_logger( ibase_log_stream* pstream, int log_level_limit = LOG_LEVEL_4 )
- {
- m_log_streams.push_back(streams_container::value_type(pstream, log_level_limit) );
- return true;
- }
-
- bool remove_logger(int type)
- {
- streams_container::iterator it = m_log_streams.begin();
- for(;it!=m_log_streams.end(); it++)
- {
- if(it->first->get_type() == type)
- {
- delete it->first;
- m_log_streams.erase(it);
- return true;
- }
- }
- return false;
-
- }
-
- protected:
- private:
-
- streams_container m_log_streams;
- };
-
- /************************************************************************/
- /* */
- /************************************************************************/
- inline int get_set_log_detalisation_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1);
- inline int get_set_time_level(bool is_need_set = false, int time_log_level = LOG_LEVEL_0);
- inline bool get_set_need_thread_id(bool is_need_set = false, bool is_need_val = false);
- inline bool get_set_need_proc_name(bool is_need_set = false, bool is_need_val = false);
-
-
- inline std::string get_daytime_string2()
- {
- boost::posix_time::ptime p = boost::posix_time::microsec_clock::local_time();
- return misc_utils::get_time_str_v3(p);
- }
- inline std::string get_day_time_string()
- {
- return get_daytime_string2();
- //time_t tm = 0;
- //time(&tm);
- //return misc_utils::get_time_str(tm);
- }
-
- inline std::string get_time_string()
- {
- return get_daytime_string2();
-
- }
-#ifdef _MSC_VER
- inline std::string get_time_string_adv(SYSTEMTIME* pst = NULL)
- {
- SYSTEMTIME st = {0};
- if(!pst)
- {
- pst = &st;
- GetSystemTime(&st);
- }
- std::stringstream str_str;
- str_str.fill('0');
- str_str << std::setw(2) << pst->wHour << "_"
- << std::setw(2) << pst->wMinute << "_"
- << std::setw(2) << pst->wSecond << "_"
- << std::setw(3) << pst->wMilliseconds;
- return str_str.str();
- }
-#endif
-
-
-
-
-
- class logger
- {
- public:
- friend class log_singletone;
-
- logger()
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- init();
- CRITICAL_REGION_END();
- }
- ~logger()
- {
- }
-
- bool set_max_logfile_size(uint64_t max_size)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- m_log_target.set_max_logfile_size(max_size);
- CRITICAL_REGION_END();
- return true;
- }
-
- bool set_log_rotate_cmd(const std::string& cmd)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- m_log_target.set_log_rotate_cmd(cmd);
- CRITICAL_REGION_END();
- return true;
- }
-
- bool take_away_journal(std::list<std::string>& journal)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- m_journal.swap(journal);
- CRITICAL_REGION_END();
- return true;
- }
-
- bool do_log_message(const std::string& rlog_mes, int log_level, int color, bool add_to_journal = false, const char* plog_name = NULL)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- m_log_target.do_log_message(rlog_mes, log_level, color, plog_name);
- if(add_to_journal)
- m_journal.push_back(rlog_mes);
-
- return true;
- CRITICAL_REGION_END();
- }
-
- bool add_logger( int type, const char* pdefault_file_name, const char* pdefault_log_folder , int log_level_limit = LOG_LEVEL_4)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- return m_log_target.add_logger( type, pdefault_file_name, pdefault_log_folder, log_level_limit);
- CRITICAL_REGION_END();
- }
- bool add_logger( ibase_log_stream* pstream, int log_level_limit = LOG_LEVEL_4)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- return m_log_target.add_logger(pstream, log_level_limit);
- CRITICAL_REGION_END();
- }
-
- bool remove_logger(int type)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- return m_log_target.remove_logger(type);
- CRITICAL_REGION_END();
- }
-
-
- bool set_thread_prefix(const std::string& prefix)
- {
- CRITICAL_REGION_BEGIN(m_critical_sec);
- m_thr_prefix_strings[misc_utils::get_thread_string_id()] = prefix;
- CRITICAL_REGION_END();
- return true;
- }
-
-
- std::string get_default_log_file()
- {
- return m_default_log_file;
- }
-
- std::string get_default_log_folder()
- {
- return m_default_log_folder;
- }
-
- protected:
- private:
- bool init()
- {
- //
-
- m_process_name = string_tools::get_current_module_name();
-
- init_log_path_by_default();
-
- //init default set of loggers
- init_default_loggers();
-
- std::stringstream ss;
- ss << get_time_string() << " Init logging. Level=" << get_set_log_detalisation_level()
- << " Log path=" << m_default_log_folder << std::endl;
- this->do_log_message(ss.str(), console_color_white, LOG_LEVEL_0);
- return true;
- }
- bool init_default_loggers()
- {
- //TODO:
- return true;
- }
-
- bool init_log_path_by_default()
- {
- //load process name
- m_default_log_folder = string_tools::get_current_module_folder();
-
- m_default_log_file = m_process_name;
- std::string::size_type a = m_default_log_file.rfind('.');
- if ( a != std::string::npos )
- m_default_log_file.erase( a, m_default_log_file.size());
- if ( ! m_default_log_file.empty() )
- m_default_log_file += ".log";
-
- return true;
- }
-
- log_stream_splitter m_log_target;
-
- std::string m_default_log_folder;
- std::string m_default_log_file;
- std::string m_process_name;
- std::map<std::string, std::string> m_thr_prefix_strings;
- std::list<std::string> m_journal;
- critical_section m_critical_sec;
- };
- /************************************************************************/
- /* */
- /************************************************************************/
- class log_singletone
- {
- public:
- friend class initializer<log_singletone>;
- friend class logger;
- static int get_log_detalisation_level()
- {
- get_or_create_instance();//to initialize logger, if it not initialized
- return get_set_log_detalisation_level();
- }
-
- static bool is_filter_error(int error_code)
- {
- return false;
- }
-
-
- static bool do_log_message(const std::string& rlog_mes, int log_level, int color, bool keep_in_journal, const char* plog_name = NULL)
- {
- logger* plogger = get_or_create_instance();
- bool res = false;
- if(plogger)
- res = plogger->do_log_message(rlog_mes, log_level, color, keep_in_journal, plog_name);
- else
- { //globally uninitialized, create new logger for each call of do_log_message() and then delete it
- plogger = new logger();
- //TODO: some extra initialization
- res = plogger->do_log_message(rlog_mes, log_level, color, keep_in_journal, plog_name);
- delete plogger;
- plogger = NULL;
- }
- return res;
- }
-
- static bool take_away_journal(std::list<std::string>& journal)
- {
- logger* plogger = get_or_create_instance();
- bool res = false;
- if(plogger)
- res = plogger->take_away_journal(journal);
-
- return res;
- }
-
- static bool set_max_logfile_size(uint64_t file_size)
- {
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->set_max_logfile_size(file_size);
- }
-
-
- static bool set_log_rotate_cmd(const std::string& cmd)
- {
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->set_log_rotate_cmd(cmd);
- }
-
-
- static bool add_logger( int type, const char* pdefault_file_name, const char* pdefault_log_folder, int log_level_limit = LOG_LEVEL_4)
- {
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->add_logger(type, pdefault_file_name, pdefault_log_folder, log_level_limit);
- }
-
- static std::string get_default_log_file()
- {
- logger* plogger = get_or_create_instance();
- if(plogger)
- return plogger->get_default_log_file();
-
- return "";
- }
-
- static std::string get_default_log_folder()
- {
- logger* plogger = get_or_create_instance();
- if(plogger)
- return plogger->get_default_log_folder();
-
- return "";
- }
-
- static bool add_logger( ibase_log_stream* pstream, int log_level_limit = LOG_LEVEL_4 )
- {
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->add_logger(pstream, log_level_limit);
- }
-
-
- static bool remove_logger( int type )
- {
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->remove_logger(type);
- }
-PUSH_WARNINGS
-DISABLE_GCC_WARNING(maybe-uninitialized)
- static int get_set_log_detalisation_level(bool is_need_set = false, int log_level_to_set = LOG_LEVEL_1)
- {
- static int log_detalisation_level = LOG_LEVEL_1;
- if(is_need_set)
- log_detalisation_level = log_level_to_set;
- return log_detalisation_level;
- }
-POP_WARNINGS
- static int get_set_time_level(bool is_need_set = false, int time_log_level = LOG_LEVEL_0)
- {
- static int val_time_log_level = LOG_LEVEL_0;
- if(is_need_set)
- val_time_log_level = time_log_level;
-
- return val_time_log_level;
- }
-
- static int get_set_process_level(bool is_need_set = false, int process_log_level = LOG_LEVEL_0)
- {
- static int val_process_log_level = LOG_LEVEL_0;
- if(is_need_set)
- val_process_log_level = process_log_level;
-
- return val_process_log_level;
- }
-
- /*static int get_set_tid_level(bool is_need_set = false, int tid_log_level = LOG_LEVEL_0)
- {
- static int val_tid_log_level = LOG_LEVEL_0;
- if(is_need_set)
- val_tid_log_level = tid_log_level;
-
- return val_tid_log_level;
- }*/
-
- static bool get_set_need_thread_id(bool is_need_set = false, bool is_need_val = false)
- {
- static bool is_need = false;
- if(is_need_set)
- is_need = is_need_val;
-
- return is_need;
- }
-
- static bool get_set_need_proc_name(bool is_need_set = false, bool is_need_val = false)
- {
- static bool is_need = true;
- if(is_need_set)
- is_need = is_need_val;
-
- return is_need;
- }
- static uint64_t get_set_err_count(bool is_need_set = false, uint64_t err_val = false)
- {
- static uint64_t err_count = 0;
- if(is_need_set)
- err_count = err_val;
-
- return err_count;
- }
-
-
-#ifdef _MSC_VER
-
-
- static void SetThreadName( DWORD dwThreadID, const char* threadName)
- {
-#define MS_VC_EXCEPTION 0x406D1388
-
-#pragma pack(push,8)
- typedef struct tagTHREADNAME_INFO
- {
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
- } THREADNAME_INFO;
-#pragma pack(pop)
-
-
-
- Sleep(10);
- THREADNAME_INFO info;
- info.dwType = 0x1000;
- info.szName = (char*)threadName;
- info.dwThreadID = dwThreadID;
- info.dwFlags = 0;
-
- __try
- {
- RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- }
- }
-#endif
-
- static bool set_thread_log_prefix(const std::string& prefix)
- {
-#ifdef _MSC_VER
- SetThreadName(-1, prefix.c_str());
-#endif
-
-
- logger* plogger = get_or_create_instance();
- if(!plogger) return false;
- return plogger->set_thread_prefix(prefix);
- }
-
-
- static std::string get_prefix_entry()
- {
- std::stringstream str_prefix;
- //write time entry
- if ( get_set_time_level() <= get_set_log_detalisation_level() )
- str_prefix << get_day_time_string() << " ";
-
- //write process info
- logger* plogger = get_or_create_instance();
- //bool res = false;
- if(!plogger)
- { //globally uninitialized, create new logger for each call of get_prefix_entry() and then delete it
- plogger = new logger();
- }
-
- //if ( get_set_need_proc_name() && get_set_process_level() <= get_set_log_detalisation_level() )
- // str_prefix << "[" << plogger->m_process_name << " (id=" << GetCurrentProcessId() << ")] ";
-//#ifdef _MSC_VER_EX
- if ( get_set_need_thread_id() /*&& get_set_tid_level() <= get_set_log_detalisation_level()*/ )
- str_prefix << "tid:" << misc_utils::get_thread_string_id() << " ";
-//#endif
-
- if(plogger->m_thr_prefix_strings.size())
- {
- CRITICAL_REGION_LOCAL(plogger->m_critical_sec);
- std::string thr_str = misc_utils::get_thread_string_id();
- std::map<std::string, std::string>::iterator it = plogger->m_thr_prefix_strings.find(thr_str);
- if(it!=plogger->m_thr_prefix_strings.end())
- {
- str_prefix << it->second;
- }
- }
-
-
- if(get_set_is_uninitialized())
- delete plogger;
-
- return str_prefix.str();
- }
-
- private:
- log_singletone(){}//restric to create an instance
- //static initializer<log_singletone> m_log_initializer;//must be in one .cpp file (for example main.cpp) via DEFINE_LOGGING macro
-
- static bool init()
- {
- return true;/*do nothing here*/
- }
- static bool un_init()
- {
- //delete object
- logger* plogger = get_set_instance_internal();
- if(plogger) delete plogger;
- //set uninitialized
- get_set_is_uninitialized(true, true);
- get_set_instance_internal(true, NULL);
- return true;
- }
-
- static logger* get_or_create_instance()
- {
- logger* plogger = get_set_instance_internal();
- if(!plogger)
- if(!get_set_is_uninitialized())
- get_set_instance_internal(true, plogger = new logger);
-
- return plogger;
- }
-
- static logger* get_set_instance_internal(bool is_need_set = false, logger* pnew_logger_val = NULL)
- {
- static logger* val_plogger = NULL;
-
- if(is_need_set)
- val_plogger = pnew_logger_val;
-
- return val_plogger;
- }
-
- static bool get_set_is_uninitialized(bool is_need_set = false, bool is_uninitialized = false)
- {
- static bool val_is_uninitialized = false;
-
- if(is_need_set)
- val_is_uninitialized = is_uninitialized;
-
- return val_is_uninitialized;
- }
- //static int get_set_error_filter(bool is_need_set = false)
- };
-
- const static initializer<log_singletone> log_initializer;
- /************************************************************************/
- /* */
-// /************************************************************************/
-// class log_array_value
-// {
-// int num;
-// log_message& m_ref_log_mes;
-//
-// public:
-//
-// log_array_value( log_message& log_mes ) : num(0), m_ref_log_mes(log_mes) {}
-//
-// void operator ( )( ibase_log_value *val ) {
-// m_ref_log_mes << "\n[" << num++ << "] "/* << val*/; }
-//
-//
-// template<class T>
-// void operator ()(T &value )
-// {
-// m_ref_log_mes << "\n[" << num++ << "] " << value;
-// }
-// };
-
- class log_frame
- {
- std::string m_name;
- int m_level;
- const char* m_plog_name;
- public:
-
- log_frame(const std::string& name, int dlevel = LOG_LEVEL_2 , const char* plog_name = NULL)
- {
-#ifdef _MSC_VER
- int lasterr=::GetLastError();
-#endif
- m_plog_name = plog_name;
- if ( dlevel <= log_singletone::get_log_detalisation_level() )
- {
- m_name = name;
- std::stringstream ss;
- ss << log_space::log_singletone::get_prefix_entry() << "-->>" << m_name << std::endl;
- log_singletone::do_log_message(ss.str(), dlevel, console_color_default, false, m_plog_name);
- }
- m_level = dlevel;
-#ifdef _MSC_VER
- ::SetLastError(lasterr);
-#endif
- }
- ~log_frame()
- {
-#ifdef _MSC_VER
- int lasterr=::GetLastError();
-#endif
-
- if (m_level <= log_singletone::get_log_detalisation_level() )
- {
- std::stringstream ss;
- ss << log_space::log_singletone::get_prefix_entry() << "<<--" << m_name << std::endl;
- log_singletone::do_log_message(ss.str(), m_level, console_color_default, false,m_plog_name);
- }
-#ifdef _MSC_VER
- ::SetLastError(lasterr);
-#endif
- }
- };
-
- inline int get_set_time_level(bool is_need_set, int time_log_level)
- {
- return log_singletone::get_set_time_level(is_need_set, time_log_level);
- }
- inline int get_set_log_detalisation_level(bool is_need_set, int log_level_to_set)
- {
- return log_singletone::get_set_log_detalisation_level(is_need_set, log_level_to_set);
- }
- inline std::string get_prefix_entry()
- {
- return log_singletone::get_prefix_entry();
- }
- inline bool get_set_need_thread_id(bool is_need_set, bool is_need_val)
- {
- return log_singletone::get_set_need_thread_id(is_need_set, is_need_val);
- }
- inline bool get_set_need_proc_name(bool is_need_set, bool is_need_val )
- {
- return log_singletone::get_set_need_proc_name(is_need_set, is_need_val);
- }
-
- inline std::string get_win32_err_descr(int err_no)
- {
-#ifdef _MSC_VER
- LPVOID lpMsgBuf;
-
- FormatMessageA(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- err_no,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (char*) &lpMsgBuf,
- 0, NULL );
-
- std::string fix_sys_message = "(null)";
- if(lpMsgBuf) fix_sys_message = (char*)lpMsgBuf;
- std::string::size_type a;
- if ( (a = fix_sys_message.rfind( '\n' )) != std::string::npos )
- fix_sys_message.erase(a);
- if ( (a = fix_sys_message.rfind( '\r' )) != std::string::npos )
- fix_sys_message.erase(a);
-
- LocalFree(lpMsgBuf);
- return fix_sys_message;
-#else
- return "Not implemented yet";
-#endif
- }
-
- inline bool getwin32_err_text(std::stringstream& ref_message, int error_no)
- {
- ref_message << "win32 error:" << get_win32_err_descr(error_no);
- return true;
- }
-}
-#if defined(_DEBUG) || defined(__GNUC__)
- #define ENABLE_LOGGING_INTERNAL
-#endif
-#if defined(ENABLE_RELEASE_LOGGING)
- #define ENABLE_LOGGING_INTERNAL
-#endif
-
-
-#if defined(ENABLE_LOGGING_INTERNAL)
-
-#define LOG_PRINT_NO_PREFIX2(log_name, x, y) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str() , y, epee::log_space::console_color_default, false, log_name);}} while(0)
-
-#define LOG_PRINT_NO_PREFIX_NO_POSTFIX2(log_name, x, y) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}} while(0)
-
-
-#define LOG_PRINT_NO_POSTFIX2(log_name, x, y) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}} while(0)
-
-
-#define LOG_PRINT2(log_name, x, y) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}} while(0)
-
-#define LOG_PRINT_COLOR2(log_name, x, y, color) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);}} while(0)
-
-
-#define LOG_PRINT2_JORNAL(log_name, x, y) do {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() )\
- {std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);}} while(0)
-
-
-#define LOG_ERROR2(log_name, x) do { \
- std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "ERROR " << __FILE__ << ":" << __LINE__ << " " << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name);LOCAL_ASSERT(0); epee::log_space::log_singletone::get_set_err_count(true, epee::log_space::log_singletone::get_set_err_count()+1);} while(0)
-
-#define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name)
-
-#else
-
-
-#define LOG_PRINT_NO_PREFIX2(log_name, x, y) ((void)0)
-
-#define LOG_PRINT_NO_PREFIX_NO_POSTFIX2(log_name, x, y) ((void)0)
-
-#define LOG_PRINT_NO_POSTFIX2(log_name, x, y) ((void)0)
-#define LOG_PRINT_COLOR2(log_name, x, y, color) ((void)0)
-
-#define LOG_PRINT2_JORNAL(log_name, x, y) ((void)0)
-
-#define LOG_PRINT2(log_name, x, y) ((void)0)
-
-#define LOG_ERROR2(log_name, x) ((void)0)
-
-
-#define LOG_FRAME2(log_name, x, y) ((void)0)
-
-
-#endif
-
-
-#ifndef LOG_DEFAULT_TARGET
- #define LOG_DEFAULT_TARGET NULL
-#endif
-
-
-#define LOG_PRINT_NO_POSTFIX(mess, level) LOG_PRINT_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level)
-#define LOG_PRINT_NO_PREFIX(mess, level) LOG_PRINT_NO_PREFIX2(LOG_DEFAULT_TARGET, mess, level)
-#define LOG_PRINT_NO_PREFIX_NO_POSTFIX(mess, level) LOG_PRINT_NO_PREFIX_NO_POSTFIX2(LOG_DEFAULT_TARGET, mess, level)
-#define LOG_PRINT(mess, level) LOG_PRINT2(LOG_DEFAULT_TARGET, mess, level)
-
-#define LOG_PRINT_COLOR(mess, level, color) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, color)
-#define LOG_PRINT_RED(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_red)
-#define LOG_PRINT_GREEN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_green)
-#define LOG_PRINT_BLUE(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_blue)
-#define LOG_PRINT_YELLOW(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_yellow)
-#define LOG_PRINT_CYAN(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_cyan)
-#define LOG_PRINT_MAGENTA(mess, level) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, level, epee::log_space::console_color_magenta)
-
-#define LOG_PRINT_RED_L0(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_0, epee::log_space::console_color_red)
-#define LOG_PRINT_RED_L1(mess) LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, mess, LOG_LEVEL_1, epee::log_space::console_color_red)
-
-#define LOG_PRINT_L0(mess) LOG_PRINT(mess, LOG_LEVEL_0)
-#define LOG_PRINT_L1(mess) LOG_PRINT(mess, LOG_LEVEL_1)
-#define LOG_PRINT_L2(mess) LOG_PRINT(mess, LOG_LEVEL_2)
-#define LOG_PRINT_L3(mess) LOG_PRINT(mess, LOG_LEVEL_3)
-#define LOG_PRINT_L4(mess) LOG_PRINT(mess, LOG_LEVEL_4)
-#define LOG_PRINT_J(mess, level) LOG_PRINT2_JORNAL(LOG_DEFAULT_TARGET, mess, level)
-
-#define LOG_ERROR(mess) LOG_ERROR2(LOG_DEFAULT_TARGET, mess)
-#define LOG_FRAME(mess, level) LOG_FRAME2(LOG_DEFAULT_TARGET, mess, level)
-#define LOG_VALUE(mess, level) LOG_VALUE2(LOG_DEFAULT_TARGET, mess, level)
-#define LOG_ARRAY(mess, level) LOG_ARRAY2(LOG_DEFAULT_TARGET, mess, level)
-//#define LOGWIN_PLATFORM_ERROR(err_no) LOGWINDWOS_PLATFORM_ERROR2(LOG_DEFAULT_TARGET, err_no)
-#define LOG_SOCKET_ERROR(err_no) LOG_SOCKET_ERROR2(LOG_DEFAULT_TARGET, err_no)
-//#define LOGWIN_PLATFORM_ERROR_UNCRITICAL(mess) LOGWINDWOS_PLATFORM_ERROR_UNCRITICAL2(LOG_DEFAULT_TARGET, mess)
#define ENDL std::endl
@@ -1435,8 +178,6 @@ POP_WARNINGS
#define CHECK_AND_ASSERT(expr, fail_ret_val) do{if(!(expr)){LOCAL_ASSERT(expr); return fail_ret_val;};}while(0)
#endif
-#define NOTHING
-
#ifndef CHECK_AND_ASSERT_MES
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message) do{if(!(expr)) {LOG_ERROR(message); return fail_ret_val;};}while(0)
#endif
@@ -1463,5 +204,21 @@ POP_WARNINGS
#define CHECK_AND_ASSERT_MES2(expr, message) do{if(!(expr)) {LOG_ERROR(message); };}while(0)
#endif
+enum console_colors
+{
+ console_color_default,
+ console_color_white,
+ console_color_red,
+ console_color_green,
+ console_color_blue,
+ console_color_cyan,
+ console_color_magenta,
+ console_color_yellow
+};
+
+bool is_stdout_a_tty();
+void set_console_color(int color, bool bright);
+void reset_console_color();
+
}
#endif //_MISC_LOG_EX_H_
diff --git a/contrib/epee/include/net/abstract_tcp_server.h b/contrib/epee/include/net/abstract_tcp_server.h
index c74444c8e..1efd5091c 100644
--- a/contrib/epee/include/net/abstract_tcp_server.h
+++ b/contrib/epee/include/net/abstract_tcp_server.h
@@ -38,6 +38,9 @@
#pragma comment(lib, "Ws2_32.lib")
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index f0a1ddd7c..506949dbd 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -55,9 +55,11 @@
#include "net_utils_base.h"
#include "syncobj.h"
#include "../../../../src/p2p/connection_basic.hpp"
-#include "../../../../contrib/otshell_utils/utils.hpp"
#include "../../../../src/p2p/network_throttle-detail.hpp"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
#define ABSTRACT_SERVER_SEND_QUE_MAX_COUNT 1000
namespace epee
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 834b5a7a6..75a9c5be9 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -51,9 +51,8 @@
#include "../../../../src/cryptonote_core/cryptonote_core.h" // e.g. for the send_stop_signal()
-#include "../../../../contrib/otshell_utils/utils.hpp"
-#include "../../../../src/p2p/data_logger.hpp"
-using namespace nOT::nUtils; // TODO
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
#define CONNECTION_CLEANUP_TIME 30 // seconds
@@ -83,7 +82,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
m_throttle_speed_in("speed_in", "throttle_speed_in"),
m_throttle_speed_out("speed_out", "throttle_speed_out")
{
- _info_c("net/sleepRPC", "test, connection constructor set m_connection_type="<<m_connection_type);
+ MINFO("test, connection constructor set m_connection_type="<<m_connection_type);
}
PRAGMA_WARNING_DISABLE_VS(4355)
//---------------------------------------------------------------------------------
@@ -229,7 +228,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
TRY_ENTRY();
boost::shared_ptr<connection<t_protocol_handler> > back_connection_copy;
- LOG_PRINT_L4("[sock " << socket_.native_handle() << "] release");
+ LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] release");
CRITICAL_REGION_BEGIN(m_self_refs_lock);
CHECK_AND_ASSERT_MES(m_self_refs.size(), false, "[sock " << socket_.native_handle() << "] m_self_refs empty at connection<t_protocol_handler>::release() call");
//erasing from container without additional copy can cause start deleting object, including m_self_refs
@@ -266,8 +265,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
address = endpoint.address().to_string();
port = boost::lexical_cast<std::string>(endpoint.port());
}
- _mark_c("net/kind" ,
- " connection type " << to_string( m_connection_type ) << " "
+ MINFO(" connection type " << to_string( m_connection_type ) << " "
<< socket_.local_endpoint().address().to_string() << ":" << socket_.local_endpoint().port()
<< " <--> " << address << ":" << port);
}
@@ -306,7 +304,6 @@ PRAGMA_WARNING_DISABLE_VS(4355)
delay *= 0.5;
if (delay > 0) {
long int ms = (long int)(delay * 100);
- epee::net_utils::data_logger::get_instance().add_data("sleep_down", ms);
boost::this_thread::sleep_for(boost::chrono::milliseconds(ms));
}
} while(delay > 0);
@@ -397,14 +394,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
const t_safe chunksize_max = chunksize_good * 2 ;
const bool allow_split = (m_connection_type == e_connection_type_RPC) ? false : true; // do not split RPC data
- ASRT(! (chunksize_max<0) ); // make sure it is unsigned before removin sign with cast:
+ CHECK_AND_ASSERT_MES(! (chunksize_max<0), false, "Negative chunksize_max" ); // make sure it is unsigned before removin sign with cast:
long long unsigned int chunksize_max_unsigned = static_cast<long long unsigned int>( chunksize_max ) ;
if (allow_split && (cb > chunksize_max_unsigned)) {
{ // LOCK: chunking
epee::critical_region_t<decltype(m_chunking_lock)> send_guard(m_chunking_lock); // *** critical ***
- _dbg3_c("net/out/size", "do_send() will SPLIT into small chunks, from packet="<<cb<<" B for ptr="<<ptr);
+ MDEBUG("do_send() will SPLIT into small chunks, from packet="<<cb<<" B for ptr="<<ptr);
t_safe all = cb; // all bytes to send
t_safe pos = 0; // current sending position
// 01234567890
@@ -419,39 +416,39 @@ PRAGMA_WARNING_DISABLE_VS(4355)
while (pos < all) {
t_safe lenall = all-pos; // length from here to end
t_safe len = std::min( chunksize_good , lenall); // take a smaller part
- ASRT(len<=chunksize_good);
+ CHECK_AND_ASSERT_MES(len<=chunksize_good, false, "len too large");
// pos=8; len=4; all=10; len=3;
- ASRT(! (len<0) ); // check before we cast away sign:
+ CHECK_AND_ASSERT_MES(! (len<0), false, "negative len"); // check before we cast away sign:
unsigned long long int len_unsigned = static_cast<long long int>( len );
- ASRT(len>0); // (redundand)
- ASRT(len_unsigned < std::numeric_limits<size_t>::max()); // yeap we want strong < then max size, to be sure
+ CHECK_AND_ASSERT_MES(len>0, false, "len not strictly positive"); // (redundant)
+ CHECK_AND_ASSERT_MES(len_unsigned < std::numeric_limits<size_t>::max(), false, "Invalid len_unsigned"); // yeap we want strong < then max size, to be sure
void *chunk_start = ((char*)ptr) + pos;
- _fact_c("net/out/size","chunk_start="<<chunk_start<<" ptr="<<ptr<<" pos="<<pos);
- ASRT(chunk_start >= ptr); // not wrapped around address?
+ MDEBUG("chunk_start="<<chunk_start<<" ptr="<<ptr<<" pos="<<pos);
+ CHECK_AND_ASSERT_MES(chunk_start >= ptr, false, "Pointer wraparound"); // not wrapped around address?
//std::memcpy( (void*)buf, chunk_start, len);
- _dbg3_c("net/out/size", "part of " << lenall << ": pos="<<pos << " len="<<len);
+ MDEBUG("part of " << lenall << ": pos="<<pos << " len="<<len);
bool ok = do_send_chunk(chunk_start, len); // <====== ***
all_ok = all_ok && ok;
if (!all_ok) {
- _dbg1_c("net/out/size", "do_send() DONE ***FAILED*** from packet="<<cb<<" B for ptr="<<ptr);
- _dbg1("do_send() SEND was aborted in middle of big package - this is mostly harmless "
+ MDEBUG("do_send() DONE ***FAILED*** from packet="<<cb<<" B for ptr="<<ptr);
+ MDEBUG("do_send() SEND was aborted in middle of big package - this is mostly harmless "
<< " (e.g. peer closed connection) but if it causes trouble tell us at #monero-dev. " << cb);
return false; // partial failure in sending
}
- pos = pos+len; ASRT(pos >0);
+ pos = pos+len;
+ CHECK_AND_ASSERT_MES(pos >0, false, "pos <= 0");
// (in catch block, or uniq pointer) delete buf;
} // each chunk
- _dbg3_c("net/out/size", "do_send() DONE SPLIT from packet="<<cb<<" B for ptr="<<ptr);
- _dbg3 ( "do_send() DONE SPLIT from packet="<<cb<<" B for ptr="<<ptr);
+ MDEBUG("do_send() DONE SPLIT from packet="<<cb<<" B for ptr="<<ptr);
- _info_c("net/sleepRPC", "do_send() m_connection_type = " << m_connection_type);
+ MDEBUG("do_send() m_connection_type = " << m_connection_type);
return all_ok; // done - e.g. queued - all the chunks of current do_send call
} // LOCK: chunking
@@ -505,15 +502,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}*/
long int ms = 250 + (rand()%50);
- _info_c("net/sleep", "Sleeping because QUEUE is FULL, in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<cb); // XXX debug sleep
+ MDEBUG("Sleeping because QUEUE is FULL, in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<cb); // XXX debug sleep
m_send_que_lock.unlock();
boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
m_send_que_lock.lock();
_dbg1("sleep for queue: " << ms);
if (retry > retry_limit) {
- _erro("send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
- // _dbg1_c("net/sleep", "send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
+ MWARNING("send que size is more than ABSTRACT_SERVER_SEND_QUE_MAX_COUNT(" << ABSTRACT_SERVER_SEND_QUE_MAX_COUNT << "), shutting down connection");
shutdown();
return false;
}
@@ -525,10 +521,10 @@ PRAGMA_WARNING_DISABLE_VS(4355)
if(m_send_que.size() > 1)
{ // active operation should be in progress, nothing to do, just wait last operation callback
auto size_now = cb;
- _info_c("net/out/size", "do_send() NOW just queues: packet="<<size_now<<" B, is added to queue-size="<<m_send_que.size());
+ MDEBUG("do_send() NOW just queues: packet="<<size_now<<" B, is added to queue-size="<<m_send_que.size());
//do_send_handler_delayed( ptr , size_now ); // (((H))) // empty function
- LOG_PRINT_L4("[sock " << socket_.native_handle() << "] Async send requested " << m_send_que.front().size());
+ LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] Async send requested " << m_send_que.front().size());
}
else
{ // no active operation
@@ -540,11 +536,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
auto size_now = m_send_que.front().size();
- _dbg1_c("net/out/size", "do_send() NOW SENSD: packet="<<size_now<<" B");
+ MDEBUG("do_send() NOW SENSD: packet="<<size_now<<" B");
if (speed_limit_is_enabled())
do_send_handler_write( ptr , size_now ); // (((H)))
- ASRT( size_now == m_send_que.front().size() );
+ CHECK_AND_ASSERT_MES( size_now == m_send_que.front().size(), false, "Unexpected queue size");
boost::asio::async_write(socket_, boost::asio::buffer(m_send_que.front().data(), size_now ) ,
//strand_.wrap(
boost::bind(&connection<t_protocol_handler>::handle_write, self, _1, _2)
@@ -602,7 +598,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
void connection<t_protocol_handler>::handle_write(const boost::system::error_code& e, size_t cb)
{
TRY_ENTRY();
- LOG_PRINT_L4("[sock " << socket_.native_handle() << "] Async send calledback " << cb);
+ LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] Async send calledback " << cb);
if (e)
{
@@ -635,10 +631,10 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
//have more data to send
auto size_now = m_send_que.front().size();
- _dbg1_c("net/out/size", "handle_write() NOW SENDS: packet="<<size_now<<" B" <<", from queue size="<<m_send_que.size());
+ MDEBUG("handle_write() NOW SENDS: packet="<<size_now<<" B" <<", from queue size="<<m_send_que.size());
if (speed_limit_is_enabled())
do_send_handler_write_from_queue(e, m_send_que.front().size() , m_send_que.size()); // (((H)))
- ASRT( size_now == m_send_que.front().size() );
+ CHECK_AND_ASSERT_MES( size_now == m_send_que.front().size(), void(), "Unexpected queue size");
boost::asio::async_write(socket_, boost::asio::buffer(m_send_que.front().data(), size_now) ,
// strand_.wrap(
boost::bind(&connection<t_protocol_handler>::handle_write, connection<t_protocol_handler>::shared_from_this(), _1, _2)
@@ -660,8 +656,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
void connection<t_protocol_handler>::setRpcStation()
{
m_connection_type = e_connection_type_RPC;
- _fact_c("net/sleepRPC", "set m_connection_type = RPC ");
- _info_c("net/kind", "set m_connection_type = RPC ");
+ MDEBUG("set m_connection_type = RPC ");
}
@@ -735,7 +730,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
acceptor_.listen();
boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_.local_endpoint();
m_port = binded_endpoint.port();
- _fact_c("net/RPClog", "start accept");
+ MDEBUG("start accept");
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
@@ -753,7 +748,7 @@ DISABLE_GCC_WARNING(maybe-uninitialized)
uint32_t p = 0;
if (port.size() && !string_tools::get_xtype_from_string(p, port)) {
- LOG_ERROR("Failed to convert port no = " << port);
+ MERROR("Failed to convert port no = " << port);
return false;
}
return this->init_server(p, address);
@@ -767,7 +762,7 @@ POP_WARNINGS
uint32_t local_thr_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
std::string thread_name = std::string("[") + m_thread_name_prefix;
thread_name += boost::to_string(local_thr_index) + "]";
- log_space::log_singletone::set_thread_log_prefix(thread_name);
+ MLOG_SET_THREAD_NAME(thread_name);
// _fact("Thread name: " << m_thread_name_prefix);
while(!m_stop_signal_sent)
{
@@ -796,8 +791,7 @@ POP_WARNINGS
auto it = server_type_map.find(m_thread_name_prefix);
if (it==server_type_map.end()) throw std::runtime_error("Unknown prefix/server type:" + std::string(prefix_name));
auto connection_type = it->second; // the value of type
- _info_c("net/RPClog", "Set server type to: " << connection_type << " from name: " << m_thread_name_prefix);
- _info_c("net/RPClog", "prefix_name = " << prefix_name);
+ MINFO("Set server type to: " << connection_type << " from name: " << m_thread_name_prefix << ", prefix_name = " << prefix_name);
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
@@ -812,7 +806,7 @@ POP_WARNINGS
TRY_ENTRY();
m_threads_count = threads_count;
m_main_thread_id = boost::this_thread::get_id();
- log_space::log_singletone::set_thread_log_prefix("[SRV_MAIN]");
+ MLOG_SET_THREAD_NAME("[SRV_MAIN]");
add_idle_handler(boost::bind(&boosted_tcp_server::cleanup_connections, this), 5000);
while(!m_stop_signal_sent)
{
@@ -933,13 +927,12 @@ POP_WARNINGS
template<class t_protocol_handler>
void boosted_tcp_server<t_protocol_handler>::handle_accept(const boost::system::error_code& e)
{
- _fact_c("net/RPClog", "handle_accept");
+ MDEBUG("handle_accept");
TRY_ENTRY();
if (!e)
{
if (m_connection_type == e_connection_type_RPC) {
- _note_c("net/rpc", "New server for RPC connections");
- _fact_c("net/RPClog", "New server for RPC connections");
+ MDEBUG("New server for RPC connections");
new_connection_->setRpcStation(); // hopefully this is not needed actually
}
connection_ptr conn(std::move(new_connection_));
@@ -965,7 +958,7 @@ POP_WARNINGS
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type) );
connections_mutex.lock();
connections_.push_back(std::make_pair(boost::get_system_time(), new_connection_l));
- LOG_PRINT_L2("connections_ size now " << connections_.size());
+ MDEBUG("connections_ size now " << connections_.size());
connections_mutex.unlock();
boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
@@ -1069,7 +1062,7 @@ POP_WARNINGS
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_config, m_sock_count, m_sock_number, m_pfilter, m_connection_type) );
connections_mutex.lock();
connections_.push_back(std::make_pair(boost::get_system_time(), new_connection_l));
- LOG_PRINT_L2("connections_ size now " << connections_.size());
+ MDEBUG("connections_ size now " << connections_.size());
connections_mutex.unlock();
boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
diff --git a/contrib/epee/include/net/abstract_tcp_server_cp.h b/contrib/epee/include/net/abstract_tcp_server_cp.h
index b6410e120..f10f4203f 100644
--- a/contrib/epee/include/net/abstract_tcp_server_cp.h
+++ b/contrib/epee/include/net/abstract_tcp_server_cp.h
@@ -42,6 +42,9 @@
#include "net_utils_base.h"
#include "pragma_comp_defs.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
#define LEVIN_DEFAULT_DATA_BUFF_SIZE 2000
namespace epee
diff --git a/contrib/epee/include/net/abstract_tcp_server_cp.inl b/contrib/epee/include/net/abstract_tcp_server_cp.inl
index a582c660a..ba201e3bf 100644
--- a/contrib/epee/include/net/abstract_tcp_server_cp.inl
+++ b/contrib/epee/include/net/abstract_tcp_server_cp.inl
@@ -27,6 +27,9 @@
#pragma comment(lib, "Ws2_32.lib")
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_auth.h b/contrib/epee/include/net/http_auth.h
index bdbfa7524..f43a19457 100644
--- a/contrib/epee/include/net/http_auth.h
+++ b/contrib/epee/include/net/http_auth.h
@@ -36,6 +36,9 @@
#include "http_base.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_base.h b/contrib/epee/include/net/http_base.h
index 4ff74fe27..d8e31521f 100644
--- a/contrib/epee/include/net/http_base.h
+++ b/contrib/epee/include/net/http_base.h
@@ -31,6 +31,10 @@
#include <boost/regex.hpp>
#include "string_tools.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h
index 336153384..a54318ebb 100644
--- a/contrib/epee/include/net/http_client.h
+++ b/contrib/epee/include/net/http_client.h
@@ -52,6 +52,9 @@
//#pragma comment(lib, "shlwapi.lib")
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
extern epee::critical_section gregexp_lock;
@@ -325,10 +328,10 @@ using namespace std;
CRITICAL_REGION_LOCAL(m_lock);
if(!is_connected())
{
- LOG_PRINT("Reconnecting...", LOG_LEVEL_3);
+ MDEBUG("Reconnecting...");
if(!connect(m_host_buff, m_port, m_timeout))
{
- LOG_PRINT("Failed to connect to " << m_host_buff << ":" << m_port, LOG_LEVEL_3);
+ MDEBUG("Failed to connect to " << m_host_buff << ":" << m_port);
return false;
}
}
@@ -376,7 +379,7 @@ using namespace std;
{
if(!m_net_client.recv(recv_buffer))
{
- LOG_PRINT("Unexpected reciec fail", LOG_LEVEL_3);
+ MERROR("Unexpected recv fail");
m_state = reciev_machine_state_error;
}
if(!recv_buffer.size())
@@ -464,7 +467,7 @@ using namespace std;
CRITICAL_REGION_LOCAL(m_lock);
if(!recv_buff.size())
{
- LOG_PRINT("Warning: Content-Len mode, but connection unexpectedly closed", LOG_LEVEL_3);
+ MERROR("Warning: Content-Len mode, but connection unexpectedly closed");
m_state = reciev_machine_state_done;
return true;
}
@@ -578,7 +581,7 @@ using namespace std;
CRITICAL_REGION_LOCAL(m_lock);
if(!recv_buff.size())
{
- LOG_PRINT("Warning: CHUNKED mode, but connection unexpectedly closed", LOG_LEVEL_3);
+ MERROR("Warning: CHUNKED mode, but connection unexpectedly closed");
m_state = reciev_machine_state_done;
return true;
}
@@ -665,7 +668,7 @@ using namespace std;
inline
bool parse_header(http_header_info& body_info, const std::string& m_cache_to_process)
{
- LOG_FRAME("http_stream_filter::parse_cached_header(*)", LOG_LEVEL_4);
+ MTRACE("http_stream_filter::parse_cached_header(*)");
STATIC_REGEXP_EXPR_1(rexp_mach_field,
"\n?((Connection)|(Referer)|(Content-Length)|(Content-Type)|(Transfer-Encoding)|(Content-Encoding)|(Host)|(Cookie)|(User-Agent)"
@@ -833,7 +836,7 @@ using namespace std;
}else
{ //Apparently there are no signs of the form of transfer, will receive data until the connection is closed
m_state = reciev_machine_state_error;
- LOG_PRINT("Undefinded transfer type, consider http_body_transfer_connection_close method. header: " << m_header_cache, LOG_LEVEL_2);
+ MERROR("Undefinded transfer type, consider http_body_transfer_connection_close method. header: " << m_header_cache);
return false;
}
return false;
diff --git a/contrib/epee/include/net/http_client_abstract_invoke.h b/contrib/epee/include/net/http_client_abstract_invoke.h
index 425a355ee..9b6ab4db8 100644
--- a/contrib/epee/include/net/http_client_abstract_invoke.h
+++ b/contrib/epee/include/net/http_client_abstract_invoke.h
@@ -28,6 +28,9 @@
#pragma once
#include "storages/serializeble_struct_helper.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_client_base.h b/contrib/epee/include/net/http_client_base.h
index 450d44823..f5fb57d03 100644
--- a/contrib/epee/include/net/http_client_base.h
+++ b/contrib/epee/include/net/http_client_base.h
@@ -26,6 +26,9 @@
#pragma once
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_client_via_api_helper.h b/contrib/epee/include/net/http_client_via_api_helper.h
index 391c44964..3242e4162 100644
--- a/contrib/epee/include/net/http_client_via_api_helper.h
+++ b/contrib/epee/include/net/http_client_via_api_helper.h
@@ -32,6 +32,9 @@
#include <atlutil.h>
#pragma comment(lib, "Wininet.lib")
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_protocol_handler.h b/contrib/epee/include/net/http_protocol_handler.h
index 69ea04fbe..c2e44c536 100644
--- a/contrib/epee/include/net/http_protocol_handler.h
+++ b/contrib/epee/include/net/http_protocol_handler.h
@@ -37,6 +37,9 @@
#include "http_auth.h"
#include "http_base.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index 6beff0109..5bfaf4767 100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
@@ -33,6 +33,9 @@
#include "file_io_utils.h"
#include "net_parse_helpers.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
#define HTTP_MAX_URI_LEN 9000
#define HTTP_MAX_HEADER_LEN 100000
@@ -133,7 +136,7 @@ namespace net_utils
std::string boundary;
if(!match_boundary(content_type, boundary))
{
- LOG_PRINT("Failed to match boundary in content type: " << content_type, LOG_LEVEL_0);
+ MERROR("Failed to match boundary in content type: " << content_type);
return false;
}
@@ -155,7 +158,7 @@ namespace net_utils
pos = body.find(boundary, std::distance(body.begin(), it_begin));
if(std::string::npos == pos)
{
- LOG_PRINT("Error: Filed to match closing multipart tag", LOG_LEVEL_0);
+ MERROR("Error: Filed to match closing multipart tag");
it_end = body.end();
}else
{
@@ -177,7 +180,7 @@ namespace net_utils
out_values.push_back(multipart_entry());
if(!handle_part_of_multipart(it_begin, it_end, out_values.back()))
{
- LOG_PRINT("Failed to handle_part_of_multipart", LOG_LEVEL_0);
+ MERROR("Failed to handle_part_of_multipart");
return false;
}
@@ -331,8 +334,6 @@ namespace net_utils
template<class t_connection_context>
bool simple_http_connection_handler<t_connection_context>::handle_invoke_query_line()
{
- LOG_FRAME("simple_http_connection_handler<t_connection_context>::handle_recognize_protocol_out(*)", LOG_LEVEL_3);
-
STATIC_REGEXP_EXPR_1(rexp_match_command_line, "^(((OPTIONS)|(GET)|(HEAD)|(POST)|(PUT)|(DELETE)|(TRACE)) (\\S+) HTTP/(\\d+).(\\d+))\r?\n", boost::regex::icase | boost::regex::normal);
// 123 4 5 6 7 8 9 10 11 12
//size_t match_len = 0;
@@ -379,8 +380,6 @@ namespace net_utils
{
//LOG_PRINT_L4("HTTP HEAD:\r\n" << m_cache.substr(0, pos));
- LOG_FRAME("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(*)", LOG_LEVEL_3);
-
m_query_info.m_full_request_buf_size = pos;
m_query_info.m_request_head.assign(m_cache.begin(), m_cache.begin()+pos);
@@ -479,8 +478,6 @@ namespace net_utils
template<class t_connection_context>
bool simple_http_connection_handler<t_connection_context>::parse_cached_header(http_header_info& body_info, const std::string& m_cache_to_process, size_t pos)
{
- LOG_FRAME("http_stream_filter::parse_cached_header(*)", LOG_LEVEL_3);
-
STATIC_REGEXP_EXPR_1(rexp_mach_field,
"\n?((Connection)|(Referer)|(Content-Length)|(Content-Type)|(Transfer-Encoding)|(Content-Encoding)|(Host)|(Cookie)|(User-Agent)"
// 12 3 4 5 6 7 8 9 10
@@ -576,7 +573,7 @@ namespace net_utils
m_config.m_lock.unlock();
if(!file_io_utils::load_file_to_string(destination_file_path.c_str(), response.m_body))
{
- LOG_PRINT("URI \""<< query_info.m_full_request_str.substr(0, query_info.m_full_request_str.size()-2) << "\" [" << destination_file_path << "] Not Found (404 )" , LOG_LEVEL_1);
+ MWARNING("URI \""<< query_info.m_full_request_str.substr(0, query_info.m_full_request_str.size()-2) << "\" [" << destination_file_path << "] Not Found (404 )");
response.m_body = get_not_found_response_body(query_info.m_URI);
response.m_response_code = 404;
response.m_response_comment = "Not found";
@@ -584,7 +581,7 @@ namespace net_utils
return true;
}
- LOG_PRINT(" -->> " << query_info.m_full_request_str << "\r\n<<--OK" , LOG_LEVEL_3);
+ MDEBUG(" -->> " << query_info.m_full_request_str << "\r\n<<--OK");
response.m_response_code = 200;
response.m_response_comment = "OK";
response.m_mime_tipe = get_file_mime_tipe(uri_to_path);
diff --git a/contrib/epee/include/net/http_server_cp.h b/contrib/epee/include/net/http_server_cp.h
index bbb167f9f..1ac2223c7 100644
--- a/contrib/epee/include/net/http_server_cp.h
+++ b/contrib/epee/include/net/http_server_cp.h
@@ -32,6 +32,10 @@
#include "abstract_tcp_server_cp.h"
#include "http_server.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_server_cp2.h b/contrib/epee/include/net/http_server_cp2.h
index 1a503a4de..8dfd43a16 100644
--- a/contrib/epee/include/net/http_server_cp2.h
+++ b/contrib/epee/include/net/http_server_cp2.h
@@ -32,6 +32,10 @@
#include "abstract_tcp_server2.h"
#include "http_protocol_handler.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
namespace net_utils
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 3a7d5333b..8e39b4104 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -31,6 +31,9 @@
#include "storages/portable_storage.h"
#include "storages/portable_storage_template_helper.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
#define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
epee::net_utils::http::http_response_info& response, \
@@ -77,7 +80,7 @@
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
- LOG_PRINT( s_pattern << " processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ MDEBUG( s_pattern << " processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
}
#define MAP_URI_AUTO_JON2(s_pattern, callback_f, command_type) MAP_URI_AUTO_JON2_IF(s_pattern, callback_f, command_type, true)
@@ -104,7 +107,7 @@
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = " application/octet-stream"; \
response_info.m_header_info.m_content_type = " application/octet-stream"; \
- LOG_PRINT( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
+ MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \
}
#define CHAIN_URI_MAP2(callback) else {callback(query_info, response_info, m_conn_context);handled = true;}
@@ -166,7 +169,7 @@
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
- LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2);
+ MDEBUG( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms");
#define MAP_JON_RPC_WE_IF(method_name, callback_f, command_type, cond) \
else if((callback_name == method_name) && (cond)) \
diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h
index a5cc1a917..f2a580167 100644
--- a/contrib/epee/include/net/http_server_impl_base.h
+++ b/contrib/epee/include/net/http_server_impl_base.h
@@ -36,6 +36,9 @@
#include "net/http_server_cp2.h"
#include "net/http_server_handlers_map2.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
+
namespace epee
{
@@ -79,15 +82,14 @@ namespace epee
bool run(size_t threads_count, bool wait = true)
{
//go to loop
- LOG_PRINT("Run net_service loop( " << threads_count << " threads)...", LOG_LEVEL_0);
- _fact_c("net/RPClog", "Run net_service loop( " << threads_count << " threads)...");
+ MINFO("Run net_service loop( " << threads_count << " threads)...");
if(!m_net_server.run_server(threads_count, wait))
{
LOG_ERROR("Failed to run net tcp server!");
}
if(wait)
- LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0);
+ MINFO("net_service loop stopped.");
return true;
}
diff --git a/contrib/epee/include/net/levin_client.inl b/contrib/epee/include/net/levin_client.inl
index a802d55fa..50a01aaa5 100644
--- a/contrib/epee/include/net/levin_client.inl
+++ b/contrib/epee/include/net/levin_client.inl
@@ -30,6 +30,10 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#include "string_tools.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace levin
diff --git a/contrib/epee/include/net/levin_client_async.h b/contrib/epee/include/net/levin_client_async.h
index be5847c74..2cbdb4587 100644
--- a/contrib/epee/include/net/levin_client_async.h
+++ b/contrib/epee/include/net/levin_client_async.h
@@ -31,6 +31,9 @@
#include "net_helper.h"
#include "levin_base.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
diff --git a/contrib/epee/include/net/levin_helper.h b/contrib/epee/include/net/levin_helper.h
index 53b19c9fa..c51d7244b 100644
--- a/contrib/epee/include/net/levin_helper.h
+++ b/contrib/epee/include/net/levin_helper.h
@@ -31,6 +31,9 @@
#include "levin_base.h"
#include "serializeble_struct_helper.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace levin
diff --git a/contrib/epee/include/net/levin_protocol_handler.h b/contrib/epee/include/net/levin_protocol_handler.h
index 512ba1c3c..3e1b8493a 100644
--- a/contrib/epee/include/net/levin_protocol_handler.h
+++ b/contrib/epee/include/net/levin_protocol_handler.h
@@ -32,6 +32,9 @@
#include <boost/uuid/uuid_generators.hpp>
#include "levin_base.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace levin
@@ -85,7 +88,7 @@ namespace levin
{
if(!m_config.m_pcommands_handler)
{
- LOG_ERROR("Command handler not set!");
+ LOG_ERROR_CC(m_conn_context, "Command handler not set!");
return false;
}
m_cach_in_buffer.append((const char*)ptr, cb);
@@ -100,7 +103,7 @@ namespace levin
{
if(m_cach_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cach_in_buffer.data()) != LEVIN_SIGNATURE)
{
- LOG_ERROR("Signature missmatch on accepted connection");
+ LOG_ERROR_CC(m_conn_context, "Signature missmatch on accepted connection");
return false;
}
is_continue = false;
@@ -110,7 +113,7 @@ namespace levin
bucket_head* phead = (bucket_head*)m_cach_in_buffer.data();
if(LEVIN_SIGNATURE != phead->m_signature)
{
- LOG_ERROR("Signature missmatch on accepted connection");
+ LOG_ERROR_CC(m_conn_context, "Signature missmatch on accepted connection");
return false;
}
m_current_head = *phead;
@@ -154,7 +157,7 @@ namespace levin
m_state = conn_state_reading_head;
break;
default:
- LOG_ERROR("Undefined state in levin_server_impl::connection_handler, m_state=" << m_state);
+ LOG_ERROR_CC(m_conn_context, "Undefined state in levin_server_impl::connection_handler, m_state=" << m_state);
return false;
}
}
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index 67daceaf5..cc6987e8f 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -38,6 +38,8 @@
#include <random>
#include <chrono>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
namespace epee
{
@@ -151,7 +153,7 @@ public:
{
if(ec == boost::asio::error::operation_aborted)
return;
- LOG_PRINT_CC(con.get_context_ref(), "Timeout on invoke operation happened, command: " << command, LOG_LEVEL_2);
+ MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command);
std::string fake;
cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
con.close();
@@ -244,15 +246,15 @@ public:
}
CHECK_AND_ASSERT_MES_NO_RET(0 == boost::interprocess::ipcdetail::atomic_read32(&m_wait_count), "Failed to wait for operation completion. m_wait_count = " << m_wait_count);
- LOG_PRINT_CC(m_connection_context, "~async_protocol_handler()", LOG_LEVEL_4);
+ MTRACE(m_connection_context << "~async_protocol_handler()");
}
bool start_outer_call()
{
- LOG_PRINT_CC_L4(m_connection_context, "[levin_protocol] -->> start_outer_call");
+ MTRACE(m_connection_context << "[levin_protocol] -->> start_outer_call");
if(!m_pservice_endpoint->add_ref())
{
- LOG_PRINT_CC_RED(m_connection_context, "[levin_protocol] -->> start_outer_call failed", LOG_LEVEL_4);
+ MERROR(m_connection_context << "[levin_protocol] -->> start_outer_call failed");
return false;
}
boost::interprocess::ipcdetail::atomic_inc32(&m_wait_count);
@@ -260,7 +262,7 @@ public:
}
bool finish_outer_call()
{
- LOG_PRINT_CC_L4(m_connection_context, "[levin_protocol] <<-- finish_outer_call");
+ MTRACE(m_connection_context << "[levin_protocol] <<-- finish_outer_call");
boost::interprocess::ipcdetail::atomic_dec32(&m_wait_count);
m_pservice_endpoint->release();
return true;
@@ -316,13 +318,13 @@ public:
if(!m_config.m_pcommands_handler)
{
- LOG_ERROR_CC(m_connection_context, "Commands handler not set!");
+ MERROR(m_connection_context << "Commands handler not set!");
return false;
}
if(m_cache_in_buffer.size() + cb > m_config.m_max_packet_size)
{
- LOG_ERROR_CC(m_connection_context, "Maximum packet size exceed!, m_max_packet_size = " << m_config.m_max_packet_size
+ MWARNING(m_connection_context << "Maximum packet size exceed!, m_max_packet_size = " << m_config.m_max_packet_size
<< ", packet received " << m_cache_in_buffer.size() + cb
<< ", connection will be closed.");
return false;
@@ -353,7 +355,7 @@ public:
bool is_response = (m_oponent_protocol_ver == LEVIN_PROTOCOL_VER_1 && m_current_head.m_flags&LEVIN_PACKET_RESPONSE);
- LOG_PRINT_CC_L4(m_connection_context, "LEVIN_PACKET_RECIEVED. [len=" << m_current_head.m_cb
+ MDEBUG(m_connection_context << "LEVIN_PACKET_RECIEVED. [len=" << m_current_head.m_cb
<< ", flags" << m_current_head.m_flags
<< ", r?=" << m_current_head.m_have_to_return_data
<<", cmd = " << m_current_head.m_command
@@ -381,7 +383,7 @@ public:
//use sync call scenario
if(!boost::interprocess::ipcdetail::atomic_read32(&m_wait_count) && !boost::interprocess::ipcdetail::atomic_read32(&m_close_called))
{
- LOG_ERROR_CC(m_connection_context, "no active invoke when response came, wtf?");
+ MERROR(m_connection_context << "no active invoke when response came, wtf?");
return false;
}else
{
@@ -413,7 +415,7 @@ public:
if(!m_pservice_endpoint->do_send(send_buff.data(), send_buff.size()))
return false;
CRITICAL_REGION_END();
- LOG_PRINT_CC_L4(m_connection_context, "LEVIN_PACKET_SENT. [len=" << m_current_head.m_cb
+ MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << m_current_head.m_cb
<< ", flags" << m_current_head.m_flags
<< ", r?=" << m_current_head.m_have_to_return_data
<<", cmd = " << m_current_head.m_command
@@ -431,7 +433,7 @@ public:
{
if(m_cache_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cache_in_buffer.data()) != LEVIN_SIGNATURE)
{
- LOG_ERROR_CC(m_connection_context, "Signature mismatch, connection will be closed");
+ MWARNING(m_connection_context << "Signature mismatch, connection will be closed");
return false;
}
is_continue = false;
@@ -585,7 +587,7 @@ public:
}
CRITICAL_REGION_END();
- LOG_PRINT_CC_L4(m_connection_context, "LEVIN_PACKET_SENT. [len=" << head.m_cb
+ MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb
<< ", f=" << head.m_flags
<< ", r?=" << head.m_have_to_return_data
<< ", cmd = " << head.m_command
@@ -597,7 +599,7 @@ public:
{
if(misc_utils::get_tick_count() - ticks_start > m_config.m_invoke_timeout)
{
- LOG_PRINT_CC_L2(m_connection_context, "invoke timeout (" << m_config.m_invoke_timeout << "), closing connection ");
+ MWARNING(m_connection_context << "invoke timeout (" << m_config.m_invoke_timeout << "), closing connection ");
close();
return LEVIN_ERROR_CONNECTION_TIMEDOUT;
}
@@ -650,7 +652,7 @@ public:
return -1;
}
CRITICAL_REGION_END();
- LOG_PRINT_CC_L4(m_connection_context, "LEVIN_PACKET_SENT. [len=" << head.m_cb <<
+ LOG_DEBUG_CC(m_connection_context, "LEVIN_PACKET_SENT. [len=" << head.m_cb <<
", f=" << head.m_flags <<
", r?=" << head.m_have_to_return_data <<
", cmd = " << head.m_command <<
diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h
index a0ade10a3..22cea122f 100644
--- a/contrib/epee/include/net/net_helper.h
+++ b/contrib/epee/include/net/net_helper.h
@@ -46,6 +46,9 @@
//#include "profile_tools.h"
#include "../string_tools.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
#ifndef MAKE_IP
#define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(a4<<24))
#endif
@@ -180,19 +183,19 @@ namespace net_utils
return true;
}else
{
- LOG_PRINT("Some problems at connect, message: " << ec.message(), LOG_LEVEL_3);
+ MWARNING("Some problems at connect, message: " << ec.message());
return false;
}
}
catch(const boost::system::system_error& er)
{
- LOG_PRINT("Some problems at connect, message: " << er.what(), LOG_LEVEL_4);
+ MDEBUG("Some problems at connect, message: " << er.what());
return false;
}
catch(...)
{
- LOG_PRINT("Some fatal problems.", LOG_LEVEL_4);
+ MDEBUG("Some fatal problems.");
return false;
}
@@ -387,20 +390,20 @@ namespace net_utils
if (ec)
{
- LOG_PRINT_L4("READ ENDS: Connection err_code " << ec.value());
+ MTRACE("READ ENDS: Connection err_code " << ec.value());
if(ec == boost::asio::error::eof)
{
- LOG_PRINT_L4("Connection err_code eof.");
+ MTRACE("Connection err_code eof.");
//connection closed there, empty
return true;
}
- LOG_PRINT_L3("Problems at read: " << ec.message());
+ MDEBUG("Problems at read: " << ec.message());
m_connected = false;
return false;
}else
{
- LOG_PRINT_L4("READ ENDS: Success. bytes_tr: " << bytes_transfered);
+ MTRACE("READ ENDS: Success. bytes_tr: " << bytes_transfered);
m_deadline.expires_at(boost::posix_time::pos_infin);
}
diff --git a/contrib/epee/include/net/net_parse_helpers.h b/contrib/epee/include/net/net_parse_helpers.h
index ce6ca60dc..08d2a2000 100644
--- a/contrib/epee/include/net/net_parse_helpers.h
+++ b/contrib/epee/include/net/net_parse_helpers.h
@@ -31,6 +31,8 @@
#include "http_base.h"
#include "reg_exp_definer.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
namespace epee
{
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index 78e555fac..cfa51e10d 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -31,6 +31,10 @@
#include <boost/uuid/uuid.hpp>
#include "string_tools.h"
+#include "misc_log_ex.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
#ifndef MAKE_IP
#define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(a4<<24))
@@ -142,20 +146,24 @@ namespace net_utils
return ss.str();
}
-#define LOG_PRINT_CC(ct, message, log_level) LOG_PRINT("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_GREEN(ct, message, log_level) LOG_PRINT_GREEN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_RED(ct, message, log_level) LOG_PRINT_RED("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_BLUE(ct, message, log_level) LOG_PRINT_BLUE("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_YELLOW(ct, message, log_level) LOG_PRINT_YELLOW("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_CYAN(ct, message, log_level) LOG_PRINT_CYAN("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_PRINT_CC_MAGENTA(ct, message, log_level) LOG_PRINT_MAGENTA("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, log_level)
-#define LOG_ERROR_CC(ct, message) LOG_PRINT_RED("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message, LOG_LEVEL_2)
-
-#define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
-#define LOG_PRINT_CC_L1(ct, message) LOG_PRINT_L1("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
-#define LOG_PRINT_CC_L2(ct, message) LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
-#define LOG_PRINT_CC_L3(ct, message) LOG_PRINT_L3("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
-#define LOG_PRINT_CC_L4(ct, message) LOG_PRINT_L4("[" << epee::net_utils::print_connection_context_short(ct) << "]" << message)
+inline MAKE_LOGGABLE(connection_context_base, ct, os)
+{
+ os << "[" << epee::net_utils::print_connection_context_short(ct) << "] ";
+ return os;
+}
+
+#define LOG_ERROR_CC(ct, message) MERROR(ct << message)
+#define LOG_WARNING_CC(ct, message) MWARNING(ct << message)
+#define LOG_INFO_CC(ct, message) MINFO(ct << message)
+#define LOG_DEBUG_CC(ct, message) MDEBUG(ct << message)
+#define LOG_TRACE_CC(ct, message) MTRACE(ct << message)
+#define LOG_CC(level, ct, message) MLOG(level, ct << message)
+
+#define LOG_PRINT_CC_L0(ct, message) LOG_PRINT_L0(epee::net_utils::print_connection_context_short(ct) << message)
+#define LOG_PRINT_CC_L1(ct, message) LOG_PRINT_L1(epee::net_utils::print_connection_context_short(ct) << message)
+#define LOG_PRINT_CC_L2(ct, message) LOG_PRINT_L2(epee::net_utils::print_connection_context_short(ct) << message)
+#define LOG_PRINT_CC_L3(ct, message) LOG_PRINT_L3(epee::net_utils::print_connection_context_short(ct) << message)
+#define LOG_PRINT_CC_L4(ct, message) LOG_PRINT_L4(epee::net_utils::print_connection_context_short(ct) << message)
#define LOG_PRINT_CCONTEXT_L0(message) LOG_PRINT_CC_L0(context, message)
#define LOG_PRINT_CCONTEXT_L1(message) LOG_PRINT_CC_L1(context, message)
@@ -163,13 +171,6 @@ namespace net_utils
#define LOG_PRINT_CCONTEXT_L3(message) LOG_PRINT_CC_L3(context, message)
#define LOG_ERROR_CCONTEXT(message) LOG_ERROR_CC(context, message)
-#define LOG_PRINT_CCONTEXT_GREEN(message, log_level) LOG_PRINT_CC_GREEN(context, message, log_level)
-#define LOG_PRINT_CCONTEXT_RED(message, log_level) LOG_PRINT_CC_RED(context, message, log_level)
-#define LOG_PRINT_CCONTEXT_BLUE(message, log_level) LOG_PRINT_CC_BLUE(context, message, log_level)
-#define LOG_PRINT_CCONTEXT_YELLOW(message, log_level) LOG_PRINT_CC_YELLOW(context, message, log_level)
-#define LOG_PRINT_CCONTEXT_CYAN(message, log_level) LOG_PRINT_CC_CYAN(context, message, log_level)
-#define LOG_PRINT_CCONTEXT_MAGENTA(message, log_level) LOG_PRINT_CC_MAGENTA(context, message, log_level)
-
#define CHECK_AND_ASSERT_MES_CC(condition, return_val, err_message) CHECK_AND_ASSERT_MES(condition, return_val, "[" << epee::net_utils::print_connection_context_short(context) << "]" << err_message)
}
diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h
index 0e1646f60..d3b1e4db4 100644
--- a/contrib/epee/include/profile_tools.h
+++ b/contrib/epee/include/profile_tools.h
@@ -52,8 +52,8 @@ namespace epee
#endif
#define START_WAY_POINTS() uint64_t _____way_point_time = epee::misc_utils::get_tick_count();
-#define WAY_POINT(name) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
-#define WAY_POINT2(name, avrg_obj) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
+#define WAY_POINT(name) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; MDEBUG("Way point " << name << ": " << delta);_____way_point_time = misc_utils::get_tick_count();}
+#define WAY_POINT2(name, avrg_obj) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); MDEBUG("Way point " << name << ": " << delta);_____way_point_time = misc_utils::get_tick_count();}
#define TIME_MEASURE_START(var_name) uint64_t var_name = epee::misc_utils::get_tick_count();
@@ -67,7 +67,7 @@ namespace profile_tools
{}
~local_call_account()
{
- LOG_PRINT2("profile_details.log", "PROFILE "<<m_pname<<":av_time:\t" << (m_count_of_call ? (m_summary_time_used/m_count_of_call):0) <<" sum_time:\t"<<m_summary_time_used<<" call_count:\t" << m_count_of_call, LOG_LEVEL_0);
+ MINFO("PROFILE "<<m_pname<<":av_time:\t" << (m_count_of_call ? (m_summary_time_used/m_count_of_call):0) <<" sum_time:\t"<<m_summary_time_used<<" call_count:\t" << m_count_of_call);
}
size_t m_count_of_call;
diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h
index 8c4fb9ccd..14e7d402a 100644
--- a/contrib/epee/include/storages/levin_abstract_invoke2.h
+++ b/contrib/epee/include/storages/levin_abstract_invoke2.h
@@ -30,6 +30,9 @@
#include <boost/utility/value_init.hpp>
#include "net/levin_base.h"
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net"
+
namespace epee
{
namespace net_utils
@@ -48,7 +51,7 @@ namespace epee
int res = transport.invoke(command, buff_to_send, buff_to_recv);
if( res <=0 )
{
- LOG_PRINT_RED("Failed to invoke command " << command << " return code " << res, LOG_LEVEL_1);
+ MERROR("Failed to invoke command " << command << " return code " << res);
return false;
}
serialization::portable_storage stg_ret;
@@ -154,7 +157,7 @@ namespace epee
int res = transport.notify(command, buff_to_send, conn_id);
if(res <=0 )
{
- LOG_PRINT_RED_L0("Failed to notify command " << command << " return code " << res);
+ MERROR("Failed to notify command " << command << " return code " << res);
return false;
}
return true;
diff --git a/contrib/epee/include/storages/portable_storage_from_json.h b/contrib/epee/include/storages/portable_storage_from_json.h
index 41f270627..04b57376c 100644
--- a/contrib/epee/include/storages/portable_storage_from_json.h
+++ b/contrib/epee/include/storages/portable_storage_from_json.h
@@ -365,12 +365,12 @@ namespace epee
}
catch(const std::exception& ex)
{
- LOG_PRINT_RED_L0("Failed to parse json, what: " << ex.what());
+ MERROR("Failed to parse json, what: " << ex.what());
return false;
}
catch(...)
{
- LOG_PRINT_RED_L0("Failed to parse json");
+ MERROR("Failed to parse json");
return false;
}
}
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 8426cd45d..8bc512893 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -26,4 +26,4 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-add_library(epee STATIC http_auth.cpp)
+add_library(epee STATIC http_auth.cpp mlog.cpp)
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
new file mode 100644
index 000000000..37a15bbd5
--- /dev/null
+++ b/contrib/epee/src/mlog.cpp
@@ -0,0 +1,319 @@
+// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the Andrey N. Sabelnikov nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+
+#ifndef _MLOG_H_
+#define _MLOG_H_
+
+#include <atomic>
+#include "misc_log_ex.h"
+
+INITIALIZE_EASYLOGGINGPP
+
+//#define MLOG_BASE_FORMAT "%datetime{%Y-%M-%d %H:%m:%s.%g}\t%thread\t%level\t%logger\t%fbase:%line\t%msg"
+#define MLOG_BASE_FORMAT "%datetime{%Y-%M-%d %H:%m:%s.%g}\t%thread\t%level\t%logger\t%loc\t%msg"
+
+using namespace epee;
+
+static std::string generate_log_filename(const char *base)
+{
+ std::string filename(base);
+ char tmp[200];
+ struct tm tm;
+ time_t now = time(NULL);
+ if (!gmtime_r(&now, &tm))
+ strcpy(tmp, "unknown");
+ else
+ strftime(tmp, sizeof(tmp), "%Y-%m-%d-%H-%M-%S", &tm);
+ filename += "-";
+ filename += tmp;
+ return filename;
+}
+
+std::string mlog_get_default_log_path(const char *default_filename)
+{
+ std::string process_name = epee::string_tools::get_current_module_name();
+ std::string default_log_folder = epee::string_tools::get_current_module_folder();
+ std::string default_log_file = process_name;
+ std::string::size_type a = default_log_file.rfind('.');
+ if ( a != std::string::npos )
+ default_log_file.erase( a, default_log_file.size());
+ if ( ! default_log_file.empty() )
+ default_log_file += ".log";
+ else
+ default_log_file = default_filename;
+
+ return (boost::filesystem::path(default_log_folder) / boost::filesystem::path(default_log_file)).string();
+}
+
+static void mlog_set_common_prefix()
+{
+ static const char * const expected_filename = "contrib/epee/src/mlog.cpp";
+ const char *path = __FILE__, *expected_ptr = strstr(path, expected_filename);
+ if (!expected_ptr)
+ return;
+ el::Loggers::setFilenameCommonPrefix(std::string(path, expected_ptr - path));
+}
+
+void mlog_configure(const std::string &filename_base, bool console)
+{
+ el::Configurations c;
+ c.setGlobally(el::ConfigurationType::Filename, filename_base);
+ c.setGlobally(el::ConfigurationType::ToFile, "true");
+ c.setGlobally(el::ConfigurationType::Format, MLOG_BASE_FORMAT);
+ c.setGlobally(el::ConfigurationType::ToStandardOutput, console ? "true" : "false");
+ c.setGlobally(el::ConfigurationType::MaxLogFileSize, "104850000"); // 100 MB - 7600 bytes
+ el::Loggers::setDefaultConfigurations(c, true);
+
+ el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
+ el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);
+ el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog);
+ el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
+ el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
+ el::Helpers::installPreRollOutCallback([&filename_base](const char *name, size_t){
+ std::string rname = generate_log_filename(filename_base.c_str());
+ rename(name, rname.c_str());
+ });
+ mlog_set_common_prefix();
+ const char *monero_log = getenv("MONERO_LOGS");
+ if (!monero_log)
+ {
+ monero_log = "*:WARNING,net*:FATAL,global:INFO,verify:FATAL";
+ }
+ mlog_set_categories(monero_log);
+}
+
+void mlog_set_categories(const char *categories)
+{
+ el::Loggers::setCategories(categories);
+ MINFO("Mew log categories: " << categories);
+}
+
+// maps epee style log level to new logging system
+void mlog_set_log_level(int level)
+{
+ const char *settings = NULL;
+ switch (level)
+ {
+ case 0:
+ settings = "*:FATAL,net*:FATAL,global:INFO,verify:FATAL";
+ break;
+ case 1:
+ settings = "*:WARNING,global:INFO";
+ break;
+ case 2:
+ settings = "*:INFO";
+ break;
+ case 3:
+ settings = "*:DEBUG";
+ break;
+ case 4:
+ settings = "*:TRACE";
+ break;
+ default:
+ return;
+ }
+
+ el::Loggers::setCategories(settings);
+ MINFO("Mew log categories: " << settings);
+}
+
+void mlog_set_log(const char *log)
+{
+ long level;
+ char *ptr = NULL;
+
+ level = strtoll(log, &ptr, 10);
+ if (ptr && *ptr)
+ {
+ mlog_set_categories(log);
+ }
+ else if (level >= 0 && level <= 4)
+ {
+ mlog_set_log_level(level);
+ }
+ else
+ {
+ MERROR("Invalid numerical log level: " << log);
+ }
+}
+
+namespace epee
+{
+
+bool is_stdout_a_tty()
+{
+ static std::atomic<bool> initialized(false);
+ static std::atomic<bool> is_a_tty(false);
+
+ if (!initialized.load(std::memory_order_acquire))
+ {
+#if defined(WIN32)
+ is_a_tty.store(0 != _isatty(_fileno(stdout)), std::memory_order_relaxed);
+#else
+ is_a_tty.store(0 != isatty(fileno(stdout)), std::memory_order_relaxed);
+#endif
+ initialized.store(true, std::memory_order_release);
+ }
+
+ return is_a_tty.load(std::memory_order_relaxed);
+}
+
+void set_console_color(int color, bool bright)
+{
+ if (!is_stdout_a_tty())
+ return;
+
+ switch(color)
+ {
+ case console_color_default:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE| (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;37m";
+ else
+ std::cout << "\033[0m";
+#endif
+ }
+ break;
+ case console_color_white:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;37m";
+ else
+ std::cout << "\033[0;37m";
+#endif
+ }
+ break;
+ case console_color_red:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;31m";
+ else
+ std::cout << "\033[0;31m";
+#endif
+ }
+ break;
+ case console_color_green:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;32m";
+ else
+ std::cout << "\033[0;32m";
+#endif
+ }
+ break;
+
+ case console_color_blue:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_INTENSITY);//(bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;34m";
+ else
+ std::cout << "\033[0;34m";
+#endif
+ }
+ break;
+
+ case console_color_cyan:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_GREEN | FOREGROUND_BLUE | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;36m";
+ else
+ std::cout << "\033[0;36m";
+#endif
+ }
+ break;
+
+ case console_color_magenta:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_BLUE | FOREGROUND_RED | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;35m";
+ else
+ std::cout << "\033[0;35m";
+#endif
+ }
+ break;
+
+ case console_color_yellow:
+ {
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | (bright ? FOREGROUND_INTENSITY:0));
+#else
+ if(bright)
+ std::cout << "\033[1;33m";
+ else
+ std::cout << "\033[0;33m";
+#endif
+ }
+ break;
+
+ }
+}
+
+void reset_console_color() {
+ if (!is_stdout_a_tty())
+ return;
+
+#ifdef WIN32
+ HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
+#else
+ std::cout << "\033[0m";
+ std::cout.flush();
+#endif
+}
+
+}
+
+#endif //_MLOG_H_