From 5833d66f6540e7b34e10ddef37c2b67bd501994b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 1 Jan 2017 16:34:23 +0000 Subject: Change logging to easylogging++ This replaces the epee and data_loggers logging systems with a single one, and also adds filename:line and explicit severity levels. Categories may be defined, and logging severity set by category (or set of categories). epee style 0-4 log level maps to a sensible severity configuration. Log files now also rotate when reaching 100 MB. To select which logs to output, use the MONERO_LOGS environment variable, with a comma separated list of categories (globs are supported), with their requested severity level after a colon. If a log matches more than one such setting, the last one in the configuration string applies. A few examples: This one is (mostly) silent, only outputting fatal errors: MONERO_LOGS=*:FATAL This one is very verbose: MONERO_LOGS=*:TRACE This one is totally silent (logwise): MONERO_LOGS="" This one outputs all errors and warnings, except for the "verify" category, which prints just fatal errors (the verify category is used for logs about incoming transactions and blocks, and it is expected that some/many will fail to verify, hence we don't want the spam): MONERO_LOGS=*:WARNING,verify:FATAL Log levels are, in decreasing order of priority: FATAL, ERROR, WARNING, INFO, DEBUG, TRACE Subcategories may be added using prefixes and globs. This example will output net.p2p logs at the TRACE level, but all other net* logs only at INFO: MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE Logs which are intended for the user (which Monero was using a lot through epee, but really isn't a nice way to go things) should use the "global" category. There are a few helper macros for using this category, eg: MGINFO("this shows up by default") or MGINFO_RED("this is red"), to try to keep a similar look and feel for now. Existing epee log macros still exist, and map to the new log levels, but since they're used as a "user facing" UI element as much as a logging system, they often don't map well to log severities (ie, a log level 0 log may be an error, or may be something we want the user to see, such as an important info). In those cases, I tried to use the new macros. In other cases, I left the existing macros in. When modifying logs, it is probably best to switch to the new macros with explicit levels. The --log-level options and set_log commands now also accept category settings, in addition to the epee style log levels. --- contrib/epee/include/net/http_protocol_handler.inl | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'contrib/epee/include/net/http_protocol_handler.inl') 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 bool simple_http_connection_handler::handle_invoke_query_line() { - LOG_FRAME("simple_http_connection_handler::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::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 bool simple_http_connection_handler::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); -- cgit v1.2.3