summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-28 14:02:57 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-28 14:02:57 +0300
commit4ff3b34839c52ff6bd4e3ee65f3e48c2a2cd9237 (patch)
treec9ad6a7788a562d8fee6066793a56f50223042cc /segget/log.cpp
parentShow network_type in tui. (diff)
downloadidfetch-4ff3b34839c52ff6bd4e3ee65f3e48c2a2cd9237.tar.gz
idfetch-4ff3b34839c52ff6bd4e3ee65f3e48c2a2cd9237.tar.bz2
idfetch-4ff3b34839c52ff6bd4e3ee65f3e48c2a2cd9237.zip
Add options: GENERAL_LOG_TIME_FORMAT, ERROR_LOG_TIME_FORMAT and DEBUG_LOG_TIME_FORMAT to segget.conf file
GENERAL_LOG_TIME_FORMAT Set time format for general log as a string containing any combination of regular characters and special format specifiers. These format specifiers are replaced by the function to the corresponding values to represent the time specified in timeptr. They all begin with a percentage (%) sign, and are: %a Abbreviated weekday name [For example: Thu] %A Full weekday name [For example: Thursday] %b Abbreviated month name [For example: Aug] %B Full month name [For example: August] %c Date and time representation [For example: Thu Aug 23 14:55:02 2001] %d Day of the month (01-31) [For example: 23] %H Hour in 24h format (00-23) [For example: 14] %I Hour in 12h format (01-12) [For example: 02] %j Day of the year (001-366) [For example: 235] %m Month as a decimal number (01-12) [For example: 08] %M Minute (00-59) [For example: 55] %p AM or PM designation [For example: PM] %S Second (00-61) [For example: 02] %U Week number with the first Sunday as the first day of week one (00-53) [For example: 33] %w Weekday as a decimal number with Sunday as 0 (0-6) [For example: 4] %W Week number with the first Monday as the first day of week one (00-53) [For example: 34] %x Date representation [For example: 08/23/01] %X Time representation [For example: 14:55:02] %y Year, last two digits (00-99) [For example: 01] %Y Year [For example: 2001] %Z Timezone name or abbreviation [For example: CDT] %% A % sign [For example: %] For instace general_log_time_format=Time: %m/%d %X Default: general_log_time_format=%m/%d %X ERROR_LOG_TIME_FORMAT Set time format for error log as a string containing any combination of regular characters and special format specifiers. See GENERAL_LOG_TIME_FORMAT for details on format specifiers. Default: error_log_time_format=%m/%d %X DEBUG_LOG_TIME_FORMAT Set time format for debug log as a string containing any combination of regular characters and special format specifiers. See GENERAL_LOG_TIME_FORMAT for details on format specifiers. Default: debug_log_time_format=%m/%d %X
Diffstat (limited to 'segget/log.cpp')
-rw-r--r--segget/log.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/segget/log.cpp b/segget/log.cpp
index 6af0ffa..4d1edfe 100644
--- a/segget/log.cpp
+++ b/segget/log.cpp
@@ -26,6 +26,22 @@
#include "log.h"
+string get_time(string time_format){
+ try{
+ time_format=time_format+" ";
+ time_t rawtime;
+ struct tm * timeinfo;
+ char buffer [80];
+ time ( &rawtime );
+ timeinfo = localtime ( &rawtime );
+ strftime(buffer,80,time_format.c_str(),timeinfo);
+ return buffer;
+ }catch(...){
+ error_log("Error in log.cpp: get_time()");
+ return "";
+ }
+}
+
void log_no_msg(string log_msg_text){
try{
if (settings.general_log_file!="none"){
@@ -38,7 +54,7 @@ void log_no_msg(string log_msg_text){
return;
}
try{
- file << log_msg_text << endl;
+ file << get_time(settings.general_log_time_format) << log_msg_text << endl;
file.close();
}
catch(...){
@@ -47,16 +63,16 @@ void log_no_msg(string log_msg_text){
}
}
}catch(...){
- error_log("Error in tui.cpp: log()");
+ error_log("Error in log.cpp: log()");
}
}
void log(string log_msg_text){
log_no_msg(log_msg_text);
try{
- msg_log(log_msg_text);
+ msg_log(get_time(settings.general_log_time_format)+log_msg_text);
}catch(...){
- error_log("Error in tui.cpp: log()");
+ error_log("Error in log.cpp: log()");
}
}
@@ -73,7 +89,7 @@ void debug_no_msg(string debug_msg_text){
return;
}
try{
- file << debug_msg_text << endl;
+ file << get_time(settings.debug_log_time_format) << debug_msg_text << endl;
file.close();
}
catch(...){
@@ -82,16 +98,16 @@ void debug_no_msg(string debug_msg_text){
}
}
}catch(...){
- error_log("Error in tui.cpp: debug()");
+ error_log("Error in log.cpp: debug()");
}
}
void debug(string debug_msg_text){
debug_no_msg(debug_msg_text);
try{
-// msg(DEBUG_LINE_NUM,0, "DEBUG:"+debug_msg_text);
+// msg(DEBUG_LINE_NUM,0, "DEBUG:"+get_time(settings.debug_time_format)+debug_msg_text);
}catch(...){
- error_log("Error in tui.cpp: debug()");
+ error_log("Error in log.cpp: debug()");
}
}
@@ -99,7 +115,7 @@ void error_log_no_msg(string error_msg_text){
try{
if (settings.error_log_file!="none"){
ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app);
- file << error_msg_text << endl;
+ file << get_time(settings.error_log_time_format) << error_msg_text << endl;
file.close();
}
}catch(...){
@@ -111,8 +127,8 @@ void error_log_no_msg(string error_msg_text){
void error_log(string error_msg_text){
error_log_no_msg(error_msg_text);
try{
- msg_error_log(error_msg_text);
+ msg_error_log(get_time(settings.error_log_time_format)+error_msg_text);
}catch(...){
- error_log_no_msg("Error in tui.cpp: error_log()");
+ error_log_no_msg("Error in log.cpp: error_log()");
}
} \ No newline at end of file