summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-21 22:35:31 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-07-21 22:35:31 +0300
commitb1619d7aa7827f5051af64494acd9fac1ace9cfd (patch)
tree7acd283a1737ae0f19425dea1ccd7aefb46a1bdd
parentAdd to tui: ETA, AVG speed and active/total connections (diff)
downloadidfetch-b1619d7aa7827f5051af64494acd9fac1ace9cfd.tar.gz
idfetch-b1619d7aa7827f5051af64494acd9fac1ace9cfd.tar.bz2
idfetch-b1619d7aa7827f5051af64494acd9fac1ace9cfd.zip
Separate logging into log.h and log.cpp files. Add option value "none" to disable logs.
-rw-r--r--segget/Makefile2
-rw-r--r--segget/log.cpp118
-rw-r--r--segget/log.h40
-rw-r--r--segget/segget.conf13
-rw-r--r--segget/segget.cpp6
-rw-r--r--segget/tui.cpp82
-rw-r--r--segget/tui.h7
7 files changed, 171 insertions, 97 deletions
diff --git a/segget/Makefile b/segget/Makefile
index ed965bf..eafc4d4 100644
--- a/segget/Makefile
+++ b/segget/Makefile
@@ -18,7 +18,7 @@ all: clean $(BINS)
%.o: %.cxx
$(CXX) -c -o $@ $(CXXFLAGS) $^
-segget: segget.o connection.o checksum.o config.o distfile.o mirror.o network.o networkbroker.o phase.o pkg.o response.o segment.o settings.o stats.o str.o tui.o utils.o ui_server.o proxyfetcher.o
+segget: segget.o connection.o checksum.o config.o distfile.o log.o mirror.o network.o networkbroker.o phase.o pkg.o response.o segment.o settings.o stats.o str.o tui.o utils.o ui_server.o proxyfetcher.o
$(CXX) -o $@ -lncurses $(LIBS) $(CIBS) $^
#%: %.o
# $(CXX) -o $@ $(LIBS) $(CIBS) $^
diff --git a/segget/log.cpp b/segget/log.cpp
new file mode 100644
index 0000000..7916382
--- /dev/null
+++ b/segget/log.cpp
@@ -0,0 +1,118 @@
+/*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "log.h"
+
+void log_no_msg(string log_msg_text){
+ try{
+ if (settings.general_log_file!="none"){
+ ofstream file;
+ file.exceptions (ofstream::failbit | ofstream::badbit);
+ try{
+ file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app);
+ }catch(...){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+".");
+ return;
+ }
+ try{
+ file << log_msg_text << endl;
+ file.close();
+ }
+ catch(...){
+ error_log("Error while writing "+settings.logs_dir+"/"+settings.general_log_file+".");
+ return;
+ }
+ }
+ }catch(...){
+ error_log("Error in tui.cpp: log()");
+ }
+}
+
+void log(string log_msg_text){
+ log_no_msg(log_msg_text);
+ try{
+ msg(LOG_LINE_NUM,0, "LOG:"+log_msg_text);
+ }catch(...){
+ error_log("Error in tui.cpp: log()");
+ }
+}
+
+void debug_no_msg(string debug_msg_text){
+ try{
+ if (settings.debug_log_file!="none"){
+ ofstream file;
+ file.exceptions (ofstream::failbit | ofstream::badbit);
+ try{
+ file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app);
+ }
+ catch(...){
+ error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+".");
+ return;
+ }
+ try{
+ file << debug_msg_text << endl;
+ file.close();
+ }
+ catch(...){
+ error_log("Error while writing "+settings.logs_dir+"/"+settings.debug_log_file+".");
+ return;
+ }
+ }
+ }catch(...){
+ error_log("Error in tui.cpp: debug()");
+ }
+}
+
+void debug(string debug_msg_text){
+ debug_no_msg(debug_msg_text);
+ try{
+// msg(DEBUG_LINE_NUM,0, "DEBUG:"+debug_msg_text);
+ }catch(...){
+ error_log("Error in tui.cpp: debug()");
+ }
+}
+
+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.close();
+ }
+ }catch(...){
+ fprintf(stderr, "Error opening error log file.");
+ fprintf(stderr, "Error log file: %s/%s",settings.logs_dir.c_str(),settings.error_log_file.c_str());
+ }
+}
+
+void error_log(string error_msg_text){
+ error_log_no_msg(error_msg_text);
+ try{
+ msg(ERROR_LINE_NUM,0, "ERROR:"+error_msg_text);
+ }catch(...){
+ error_log_no_msg("Error in tui.cpp: error_log()");
+ }
+} \ No newline at end of file
diff --git a/segget/log.h b/segget/log.h
new file mode 100644
index 0000000..45a158d
--- /dev/null
+++ b/segget/log.h
@@ -0,0 +1,40 @@
+/*
+* Copyright (C) 2010 Robin H.Johnson, Ovechko Kostyantyn <fastinetserver@gmail.com>.
+*
+* Project: IDFetch.
+* Developer: Ovechko Kostyantyn Olexandrovich (Kharkiv State Technical University of Construction and Architecture, Ukraine).
+* Mentor: Robin H. Johnson (Gentoo Linux: Developer, Trustee & Infrastructure Lead).
+* Mentoring organization: Gentoo Linux.
+* Sponsored by GSOC 2010.
+*
+* This file is part of Segget.
+*
+* Segget is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* Segget is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with Segget; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef __LOG_H__
+#define __LOG_H__
+#include "settings.h"
+#include "utils.h"
+
+using namespace std;
+
+void log_no_msg(string log_msg_text);
+void log(string log_msg_text);
+void debug_no_msg(string debug_msg_text);
+void debug(string debug_msg_text);
+void error_log_no_msg(string error_msg_text);
+void error_log(string error_msg_text);
+#endif \ No newline at end of file
diff --git a/segget/segget.conf b/segget/segget.conf
index 21e28cd..8e41fec 100644
--- a/segget/segget.conf
+++ b/segget/segget.conf
@@ -76,7 +76,7 @@ max_tries=10
# Maximum value: 20
# Default:
# max_connections=10
-max_connections=3
+max_connections=10
# CURRENT_SPEED_TIME_INTERVAL_MSECS
# segget transfers may have bursty nature of their traffic. Therefore, while
@@ -99,7 +99,7 @@ current_speed_time_interval_msecs=1000
# Maximum value: 10
# Default:
# max_connections_num_per_mirror=1
-max_connections_num_per_mirror=10
+max_connections_num_per_mirror=1
# SYNOPSIS: collect_benchmark_stats_on=0 | 1
# - If set to 1, stats on mirrors performance will be collected.
@@ -214,11 +214,11 @@ provide_proxy_fetcher_port=3130
# network7_priority=0
# network8_priority=0
# network9_priority=0
-network0_priority=10
-network1_priority=9
+network0_priority=0
+network1_priority=0
network2_priority=0
network3_priority=0
-network4_priority=0
+network4_priority=7
network5_priority=0
network6_priority=0
network7_priority=0
@@ -268,18 +268,21 @@ logs_dir=./logs
# GENERAL_LOG_FILE
# Define a file name to store general log.
+# Set to none to disable loggin.
# Default:
# general_log_file=segget.log
general_log_file=segget.log
# ERROR_LOG_FILE
# Define a file name to store error log.
+# Set to none to disable loggin.
# Default:
# error_log_file=segget.log
error_log_file=error.log
# DEBUG_LOG_FILE
# Define a file name to store debug log.
+# Set to none to disable loggin.
# Default:
# debug_log_file=segget.log
debug_log_file=debug.log \ No newline at end of file
diff --git a/segget/segget.cpp b/segget/segget.cpp
index 8829d6d..a1978ae 100644
--- a/segget/segget.cpp
+++ b/segget/segget.cpp
@@ -262,9 +262,9 @@ int download_pkgs(){
connection_array[current_segment->connection_num].stop(connection_result);
- if (not choose_segment(current_segment->connection_num)) {
- U++; // just to prevent it from remaining at 0 if there are more URLs to get
- };
+// if (not choose_segment(current_segment->connection_num)) {
+// U++; // just to prevent it from remaining at 0 if there are more URLs to get
+// };
stats.show_totals();
curl_easy_cleanup(e);
}else {
diff --git a/segget/tui.cpp b/segget/tui.cpp
index fa194b6..5f4545b 100644
--- a/segget/tui.cpp
+++ b/segget/tui.cpp
@@ -145,86 +145,4 @@ void msg_total(string msg_text){
}catch(...){
error_log_no_msg("Error in tui.cpp: msg_total()");
}
-}
-void log(string log_msg_text){
- try{
- msg(LOG_LINE_NUM,0, "LOG:"+log_msg_text);
- ofstream file;
- file.exceptions (ofstream::failbit | ofstream::badbit);
- try{
- file.open((settings.logs_dir+"/"+settings.general_log_file).c_str(), ios::app);
- }catch(...){
- error_log("Error opening "+settings.logs_dir+"/"+settings.general_log_file+".");
- return;
- }
- try{
- file << log_msg_text << endl;
- file.close();
- }
- catch(...){
- error_log("Error while writing "+settings.logs_dir+"/"+settings.general_log_file+".");
- return;
- }
- }catch(...){
- error_log("Error in tui.cpp: log()");
- }
-}
-void debug(string debug_msg_text){
- try{
-// msg(DEBUG_LINE_NUM,0, "DEBUG:"+debug_msg_text);
- debug_no_msg(debug_msg_text);
- }catch(...){
- error_log("Error in tui.cpp: debug()");
- }
-}
-
-void debug_no_msg(string debug_msg_text){
- try{
- ofstream file;
- file.exceptions (ofstream::failbit | ofstream::badbit);
- try{
- file.open((settings.logs_dir+"/"+settings.debug_log_file).c_str(), ios::app);
- }
- catch(...){
- error_log("Error opening "+settings.logs_dir+"/"+settings.debug_log_file+".");
- return;
- }
- try{
- file << debug_msg_text << endl;
- file.close();
- }
- catch(...){
- error_log("Error while writing "+settings.logs_dir+"/"+settings.debug_log_file+".");
- return;
- }
- }catch(...){
- error_log("Error in tui.cpp: debug()");
- }
-}
-
-void error_log_no_msg(string error_msg_text){
- try{
- ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app);
- file << error_msg_text << endl;
- file.close();
- }catch(...){
- fprintf(stderr, "Error opening error log file.");
- fprintf(stderr, "Error log file: %s/%s",settings.logs_dir.c_str(),settings.error_log_file.c_str());
- }
-}
-
-void error_log(string error_msg_text){
- try{
- ofstream file ((settings.logs_dir+"/"+settings.error_log_file).c_str(), ios::app);
- file << error_msg_text << endl;
- file.close();
- }catch(...){
- fprintf(stderr, "Error opening error log file.");
- fprintf(stderr, "Error log file: %s/%s",settings.logs_dir.c_str(),settings.error_log_file.c_str());
- }
- try{
- msg(ERROR_LINE_NUM,0, "ERROR:"+error_msg_text);
- }catch(...){
- error_log_no_msg("Error in tui.cpp: error_log()");
- }
} \ No newline at end of file
diff --git a/segget/tui.h b/segget/tui.h
index 8f24b47..612ea5a 100644
--- a/segget/tui.h
+++ b/segget/tui.h
@@ -30,6 +30,7 @@
#include "settings.h"
#include "ui_server.h"
#include "utils.h"
+#include "log.h"
using namespace std;
@@ -42,10 +43,4 @@ void msg_status2(uint connection_num, string msg_text);
void msg_clean_connection(uint connection_num);
void msg_error(string error_text);
void msg_total(string msg_text);
-
-void log(string log_msg_text);
-void debug_no_msg(string debug_msg_text);
-void debug(string debug_msg_text);
-void error_log(string error_msg_text);
-void error_log_no_msg(string error_msg_text);
#endif \ No newline at end of file