2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Made log and log-level option modifiable using
	aria2.changeGlobalOption. This means you can dynamically start or
	stop logging and change log file and log level.
	* doc/aria2c.1.txt
	* src/LogFactory.cc
	* src/LogFactory.h
	* src/LogFormatter.h
	* src/Logger.cc
	* src/Logger.h
	* src/Makefile.am
	* src/Makefile.in
	* src/SimpleLogFormatter.cc
	* src/SimpleLogFormatter.h
	* src/SimpleLogger.cc: Removed
	* src/SimpleLogger.h: Removed
	* src/XmlRpcMethod.cc
	* src/XmlRpcMethodImpl.cc
	* src/main.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-06-23 14:15:35 +00:00
parent 4736e77acf
commit 66660d10c2
16 changed files with 239 additions and 60 deletions

View File

@ -1,3 +1,24 @@
2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made log and log-level option modifiable using
aria2.changeGlobalOption. This means you can dynamically start or
stop logging and change log file and log level.
* doc/aria2c.1.txt
* src/LogFactory.cc
* src/LogFactory.h
* src/LogFormatter.h
* src/Logger.cc
* src/Logger.h
* src/Makefile.am
* src/Makefile.in
* src/SimpleLogFormatter.cc
* src/SimpleLogFormatter.h
* src/SimpleLogger.cc: Removed
* src/SimpleLogger.h: Removed
* src/XmlRpcMethod.cc
* src/XmlRpcMethodImpl.cc
* src/main.cc
2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-06-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Request ut_metadata in end-game mode(in other words, more Request ut_metadata in end-game mode(in other words, more

View File

@ -2,12 +2,12 @@
.\" Title: aria2c .\" Title: aria2c
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/> .\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
.\" Date: 06/02/2010 .\" Date: 06/23/2010
.\" Manual: Aria2 Manual .\" Manual: Aria2 Manual
.\" Source: Aria2 1.9.4 .\" Source: Aria2 1.9.4
.\" Language: English .\" Language: English
.\" .\"
.TH "ARIA2C" "1" "06/02/2010" "Aria2 1\&.9\&.4" "Aria2 Manual" .TH "ARIA2C" "1" "06/23/2010" "Aria2 1\&.9\&.4" "Aria2 Manual"
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
.\" * Define some portability stuff .\" * Define some portability stuff
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
@ -60,7 +60,7 @@ subsection for details\&.
.RS 4 .RS 4
The file name of the log file\&. If The file name of the log file\&. If
\fI\-\fR \fI\-\fR
is specified, log is written to stdout\&. is specified, log is written to stdout\&. If empty string("") is specified, log is not written to file\&.
.RE .RE
.PP .PP
\fB\-j\fR, \fB\-\-max\-concurrent\-downloads\fR=N \fB\-j\fR, \fB\-\-max\-concurrent\-downloads\fR=N
@ -2980,7 +2980,7 @@ This method returns global options\&. The response is of type struct\&. Its key
.sp .sp
\fBaria2\&.changeGlobalOption\fR \fIoptions\fR \fBaria2\&.changeGlobalOption\fR \fIoptions\fR
.sp .sp
This method changes global options dynamically\&. \fIoptions\fR is of type struct and the available options are \fBmax\-concurrent\-downloads\fR, \fBmax\-overall\-download\-limit\fR and \fBmax\-overall\-upload\-limit\fR\&. This method returns "OK" for success\&. This method changes global options dynamically\&. \fIoptions\fR is of type struct and the available options are \fBmax\-concurrent\-downloads\fR, \fBmax\-overall\-download\-limit\fR, \fBmax\-overall\-upload\-limit\fR, \fBlog\-level\fR and \fBlog\fR\&. Using \fBlog\fR option, you can dynamically start logging or change log file\&. To stop logging, give empty string("") as a parameter value\&. Note that log file is always opened in append mode\&. This method returns "OK" for success\&.
.sp .sp
\fBaria2\&.purgeDownloadResult\fR \fBaria2\&.purgeDownloadResult\fR
.sp .sp

View File

@ -626,7 +626,7 @@ downloading a file like BitTorrent.</p></div>
<dd> <dd>
<p> <p>
The file name of the log file. If <em>-</em> is specified, log is written to The file name of the log file. If <em>-</em> is specified, log is written to
stdout. stdout. If empty string("") is specified, log is not written to file.
</p> </p>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
@ -3657,8 +3657,11 @@ added download, the response contains keys returned by
<div class="paragraph"><p><strong>aria2.changeGlobalOption</strong> <em>options</em></p></div> <div class="paragraph"><p><strong>aria2.changeGlobalOption</strong> <em>options</em></p></div>
<div class="paragraph"><p>This method changes global options dynamically. <em>options</em> is of type <div class="paragraph"><p>This method changes global options dynamically. <em>options</em> is of type
struct and the available options are <strong>max-concurrent-downloads</strong>, struct and the available options are <strong>max-concurrent-downloads</strong>,
<strong>max-overall-download-limit</strong> and <strong>max-overall-upload-limit</strong>. This <strong>max-overall-download-limit</strong>, <strong>max-overall-upload-limit</strong>, <strong>log-level</strong>
method returns "OK" for success.</p></div> and <strong>log</strong>. Using <strong>log</strong> option, you can dynamically start logging or
change log file. To stop logging, give empty string("") as a parameter
value. Note that log file is always opened in append mode. This method
returns "OK" for success.</p></div>
<div class="paragraph"><p><strong>aria2.purgeDownloadResult</strong></p></div> <div class="paragraph"><p><strong>aria2.purgeDownloadResult</strong></p></div>
<div class="paragraph"><p>This method purges completed/error/removed downloads to free memory. <div class="paragraph"><p>This method purges completed/error/removed downloads to free memory.
This method returns "OK".</p></div> This method returns "OK".</p></div>
@ -4199,7 +4202,7 @@ files in the program, then also delete it here.</p></div>
<div id="footnotes"><hr /></div> <div id="footnotes"><hr /></div>
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Last updated 2010-06-02 21:12:07 JST Last updated 2010-06-23 23:10:50 JST
</div> </div>
</div> </div>
</body> </body>

View File

@ -43,7 +43,7 @@ Basic Options
*-l*, *--log*=LOG:: *-l*, *--log*=LOG::
The file name of the log file. If '-' is specified, log is written to The file name of the log file. If '-' is specified, log is written to
stdout. stdout. If empty string("") is specified, log is not written to file.
*-j*, *--max-concurrent-downloads*=N:: *-j*, *--max-concurrent-downloads*=N::
Set maximum number of parallel downloads for every static (HTTP/FTP) URI, Set maximum number of parallel downloads for every static (HTTP/FTP) URI,
@ -1766,8 +1766,11 @@ added download, the response contains keys returned by
This method changes global options dynamically. 'options' is of type This method changes global options dynamically. 'options' is of type
struct and the available options are *max-concurrent-downloads*, struct and the available options are *max-concurrent-downloads*,
*max-overall-download-limit* and *max-overall-upload-limit*. This *max-overall-download-limit*, *max-overall-upload-limit*, *log-level*
method returns "OK" for success. and *log*. Using *log* option, you can dynamically start logging or
change log file. To stop logging, give empty string("") as a parameter
value. Note that log file is always opened in append mode. This method
returns "OK" for success.
*aria2.purgeDownloadResult* *aria2.purgeDownloadResult*

View File

@ -33,9 +33,10 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "LogFactory.h" #include "LogFactory.h"
#include "SimpleLogger.h" #include "SimpleLogFormatter.h"
#include "a2io.h" #include "a2io.h"
#include "prefs.h" #include "prefs.h"
#include "RecoverableException.h"
namespace aria2 { namespace aria2 {
@ -44,15 +45,39 @@ Logger* LogFactory::logger_ = 0;
bool LogFactory::consoleOutput_ = true; bool LogFactory::consoleOutput_ = true;
Logger::LEVEL LogFactory::logLevel_ = Logger::A2_DEBUG; Logger::LEVEL LogFactory::logLevel_ = Logger::A2_DEBUG;
void LogFactory::openLogger(Logger* logger)
{
if(filename_ != DEV_NULL) {
// don't open file DEV_NULL for performance sake.
// This avoids costly unecessary message formatting and write.
logger->openFile(filename_);
}
logger->setLogLevel(logLevel_);
}
void LogFactory::reconfigure()
{
if(logger_) {
logger_->closeFile();
try {
openLogger(logger_);
} catch(RecoverableException& e) {
logger_->closeFile();
throw;
}
}
}
Logger* LogFactory::getInstance() { Logger* LogFactory::getInstance() {
if(!logger_) { if(!logger_) {
SimpleLogger* slogger = new SimpleLogger(); Logger* slogger = new Logger();
if(filename_ != DEV_NULL) { slogger->setLogFormatter(new SimpleLogFormatter());
// don't open file DEV_NULL for performance sake. try {
// This avoids costly unecessary message formatting and write. openLogger(slogger);
slogger->openFile(filename_); } catch(RecoverableException& e) {
delete slogger;
throw;
} }
slogger->setLogLevel(logLevel_);
if(consoleOutput_) { if(consoleOutput_) {
slogger->setStdoutLogLevel(Logger::A2_NOTICE, true); slogger->setStdoutLogLevel(Logger::A2_NOTICE, true);
slogger->setStdoutLogLevel(Logger::A2_WARN, true); slogger->setStdoutLogLevel(Logger::A2_WARN, true);
@ -63,6 +88,17 @@ Logger* LogFactory::getInstance() {
return logger_; return logger_;
} }
void LogFactory::setLogFile(const std::string& name)
{
if(name == "-") {
filename_ = DEV_STDOUT;
} else if(name == "") {
filename_ = DEV_NULL;
} else {
filename_ = name;
}
}
void LogFactory::setLogLevel(Logger::LEVEL level) void LogFactory::setLogLevel(Logger::LEVEL level)
{ {
logLevel_ = level; logLevel_ = level;

View File

@ -49,6 +49,8 @@ private:
static Logger* logger_; static Logger* logger_;
static bool consoleOutput_; static bool consoleOutput_;
static Logger::LEVEL logLevel_; static Logger::LEVEL logLevel_;
static void openLogger(Logger* logger);
public: public:
/** /**
* Get logger instance. Returned logger is singleton. * Get logger instance. Returned logger is singleton.
@ -57,11 +59,10 @@ public:
static Logger* getInstance(); static Logger* getInstance();
/** /**
* Set a filename to write log. * Set a filename to write log. If name is "-", log is written to
* stdout. If name is "", log is not written to file.
*/ */
static void setLogFile(const std::string& name) { static void setLogFile(const std::string& name);
filename_ = name;
}
/** /**
* Set flag whether the log is printed in console. * Set flag whether the log is printed in console.
@ -71,7 +72,6 @@ public:
consoleOutput_ = f; consoleOutput_ = f;
} }
/** /**
* Set log level to output. * Set log level to output.
*/ */
@ -87,6 +87,8 @@ public:
* Releases used resources * Releases used resources
*/ */
static void release(); static void release();
static void reconfigure();
}; };
} // namespace aria2 } // namespace aria2

65
src/LogFormatter.h Normal file
View File

@ -0,0 +1,65 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef D_LOG_FORMATTER_H
#define D_LOG_FORMATTER_H
#include "common.h"
#include <cstdarg>
#include <iosfwd>
#include <string>
#include "Logger.h"
namespace aria2 {
class Exception;
class LogFormatter {
public:
virtual ~LogFormatter() {}
virtual void writeLog
(std::ostream& o, Logger::LEVEL logLevel, const std::string& logLevelLabel,
const char* msg, va_list ap) = 0;
virtual void writeStackTrace
(std::ostream& o, Logger::LEVEL logLevel, const std::string& logLevelLabel,
const Exception& ex) = 0;
};
} // namespace aria2
#endif // D_LOG_FORMATTER_H

View File

@ -40,6 +40,7 @@
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "message.h" #include "message.h"
#include "LogFormatter.h"
namespace aria2 { namespace aria2 {
@ -53,11 +54,13 @@ const std::string Logger::ERROR_LABEL("ERROR");
const std::string Logger::INFO_LABEL("INFO"); const std::string Logger::INFO_LABEL("INFO");
Logger::Logger():logLevel_(Logger::A2_DEBUG), stdoutField_(0) {} Logger::Logger():
logFormatter_(0), logLevel_(Logger::A2_DEBUG), stdoutField_(0) {}
Logger::~Logger() Logger::~Logger()
{ {
closeFile(); closeFile();
delete logFormatter_;
} }
void Logger::openFile(const std::string& filename) void Logger::openFile(const std::string& filename)
@ -162,6 +165,12 @@ void Logger::error(const char* msg, const Exception& ex, ...)
WRITE_LOG_EX(A2_ERROR, ERROR_LABEL, msg, ex); WRITE_LOG_EX(A2_ERROR, ERROR_LABEL, msg, ex);
} }
void Logger::setLogFormatter(LogFormatter* logFormatter)
{
delete logFormatter_;
logFormatter_ = logFormatter;
}
void Logger::setStdoutLogLevel(Logger::LEVEL level, bool enabled) void Logger::setStdoutLogLevel(Logger::LEVEL level, bool enabled)
{ {
if(enabled) { if(enabled) {
@ -171,4 +180,22 @@ void Logger::setStdoutLogLevel(Logger::LEVEL level, bool enabled)
} }
} }
void Logger::writeLog
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
const char* msg, va_list ap)
{
if(logFormatter_) {
logFormatter_->writeLog(o, logLevel, logLevelLabel, msg, ap);
}
}
void Logger::writeStackTrace
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
const Exception& ex)
{
if(logFormatter_) {
logFormatter_->writeStackTrace(o, logLevel, logLevelLabel, ex);
}
}
} // namespace aria2 } // namespace aria2

View File

@ -45,6 +45,7 @@
namespace aria2 { namespace aria2 {
class Exception; class Exception;
class LogFormatter;
class Logger { class Logger {
public: public:
@ -66,6 +67,8 @@ public:
static const std::string INFO_LABEL; static const std::string INFO_LABEL;
private: private:
LogFormatter* logFormatter_;
LEVEL logLevel_; LEVEL logLevel_;
std::ofstream file_; std::ofstream file_;
@ -76,14 +79,14 @@ private:
{ {
return (level >= logLevel_ && file_.is_open()) || stdoutField_&level; return (level >= logLevel_ && file_.is_open()) || stdoutField_&level;
} }
protected:
virtual void writeLog
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
const char* msg, va_list ap) = 0;
virtual void writeStackTrace void writeLog
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel, (std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
const Exception& ex) = 0; const char* msg, va_list ap);
void writeStackTrace
(std::ostream& o, LEVEL logLevel, const std::string& logLevelLabel,
const Exception& ex);
public: public:
Logger(); Logger();
@ -113,6 +116,8 @@ public:
void closeFile(); void closeFile();
void setLogFormatter(LogFormatter* logFormatter);
void setLogLevel(LEVEL level) void setLogLevel(LEVEL level)
{ {
logLevel_ = level; logLevel_ = level;

View File

@ -40,7 +40,8 @@ SRCS = Socket.h\
DlRetryEx.cc DlRetryEx.h\ DlRetryEx.cc DlRetryEx.h\
DownloadFailureException.cc DownloadFailureException.h\ DownloadFailureException.cc DownloadFailureException.h\
Logger.cc Logger.h\ Logger.cc Logger.h\
SimpleLogger.cc SimpleLogger.h\ LogFormatter.h\
SimpleLogFormatter.cc SimpleLogFormatter.h\
DiskWriter.h\ DiskWriter.h\
DiskWriterFactory.h\ DiskWriterFactory.h\
AbstractDiskWriter.cc AbstractDiskWriter.h\ AbstractDiskWriter.cc AbstractDiskWriter.h\

View File

@ -342,9 +342,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
FatalException.h RecoverableException.cc \ FatalException.h RecoverableException.cc \
RecoverableException.h DlAbortEx.cc DlAbortEx.h DlRetryEx.cc \ RecoverableException.h DlAbortEx.cc DlAbortEx.h DlRetryEx.cc \
DlRetryEx.h DownloadFailureException.cc \ DlRetryEx.h DownloadFailureException.cc \
DownloadFailureException.h Logger.cc Logger.h SimpleLogger.cc \ DownloadFailureException.h Logger.cc Logger.h LogFormatter.h \
SimpleLogger.h DiskWriter.h DiskWriterFactory.h \ SimpleLogFormatter.cc SimpleLogFormatter.h DiskWriter.h \
AbstractDiskWriter.cc AbstractDiskWriter.h \ DiskWriterFactory.h AbstractDiskWriter.cc AbstractDiskWriter.h \
DefaultDiskWriter.cc DefaultDiskWriter.h \ DefaultDiskWriter.cc DefaultDiskWriter.h \
DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \ DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \
File.h Option.cc Option.h Base64.cc Base64.h base32.cc \ File.h Option.cc Option.h Base64.cc Base64.h base32.cc \
@ -815,7 +815,7 @@ am__objects_32 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
Request.$(OBJEXT) Exception.$(OBJEXT) FatalException.$(OBJEXT) \ Request.$(OBJEXT) Exception.$(OBJEXT) FatalException.$(OBJEXT) \
RecoverableException.$(OBJEXT) DlAbortEx.$(OBJEXT) \ RecoverableException.$(OBJEXT) DlAbortEx.$(OBJEXT) \
DlRetryEx.$(OBJEXT) DownloadFailureException.$(OBJEXT) \ DlRetryEx.$(OBJEXT) DownloadFailureException.$(OBJEXT) \
Logger.$(OBJEXT) SimpleLogger.$(OBJEXT) \ Logger.$(OBJEXT) SimpleLogFormatter.$(OBJEXT) \
AbstractDiskWriter.$(OBJEXT) DefaultDiskWriter.$(OBJEXT) \ AbstractDiskWriter.$(OBJEXT) DefaultDiskWriter.$(OBJEXT) \
DefaultDiskWriterFactory.$(OBJEXT) File.$(OBJEXT) \ DefaultDiskWriterFactory.$(OBJEXT) File.$(OBJEXT) \
Option.$(OBJEXT) Base64.$(OBJEXT) base32.$(OBJEXT) \ Option.$(OBJEXT) Base64.$(OBJEXT) base32.$(OBJEXT) \
@ -1122,9 +1122,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
FatalException.h RecoverableException.cc \ FatalException.h RecoverableException.cc \
RecoverableException.h DlAbortEx.cc DlAbortEx.h DlRetryEx.cc \ RecoverableException.h DlAbortEx.cc DlAbortEx.h DlRetryEx.cc \
DlRetryEx.h DownloadFailureException.cc \ DlRetryEx.h DownloadFailureException.cc \
DownloadFailureException.h Logger.cc Logger.h SimpleLogger.cc \ DownloadFailureException.h Logger.cc Logger.h LogFormatter.h \
SimpleLogger.h DiskWriter.h DiskWriterFactory.h \ SimpleLogFormatter.cc SimpleLogFormatter.h DiskWriter.h \
AbstractDiskWriter.cc AbstractDiskWriter.h \ DiskWriterFactory.h AbstractDiskWriter.cc AbstractDiskWriter.h \
DefaultDiskWriter.cc DefaultDiskWriter.h \ DefaultDiskWriter.cc DefaultDiskWriter.h \
DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \ DefaultDiskWriterFactory.cc DefaultDiskWriterFactory.h File.cc \
File.h Option.cc Option.h Base64.cc Base64.h base32.cc \ File.h Option.cc Option.h Base64.cc Base64.h base32.cc \
@ -1594,7 +1594,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SessionSerializer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SessionSerializer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Signature.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Signature.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleBtMessage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleBtMessage.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleLogger.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleLogFormatter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRandomizer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRandomizer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingleFileAllocationIterator.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SingleFileAllocationIterator.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SleepCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SleepCommand.Po@am__quote@

View File

@ -2,7 +2,7 @@
/* /*
* aria2 - The high speed download utility * aria2 - The high speed download utility
* *
* Copyright (C) 2006 Tatsuhiro Tsujikawa * Copyright (C) 2010 Tatsuhiro Tsujikawa
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,9 +32,10 @@
* files in the program, then also delete it here. * files in the program, then also delete it here.
*/ */
/* copyright --> */ /* copyright --> */
#include "SimpleLogger.h" #include "SimpleLogFormatter.h"
#include <cassert> #include <cassert>
#include <ostream>
#include "util.h" #include "util.h"
#include "a2time.h" #include "a2time.h"
@ -44,13 +45,17 @@
namespace aria2 { namespace aria2 {
SimpleLogFormatter::SimpleLogFormatter() {}
SimpleLogFormatter::~SimpleLogFormatter() {}
static void writeHeader static void writeHeader
(std::ostream& o, const std::string& date, const std::string& logLevelLabel) (std::ostream& o, const std::string& date, const std::string& logLevelLabel)
{ {
o << StringFormat("%s %s - ", date.c_str(), logLevelLabel.c_str()); o << StringFormat("%s %s - ", date.c_str(), logLevelLabel.c_str());
} }
void SimpleLogger::writeLog void SimpleLogFormatter::writeLog
(std::ostream& o, Logger::LEVEL level, const std::string& logLevelLabel, (std::ostream& o, Logger::LEVEL level, const std::string& logLevelLabel,
const char* msg, va_list ap) const char* msg, va_list ap)
{ {
@ -79,7 +84,7 @@ void SimpleLogger::writeLog
} }
} }
void SimpleLogger::writeStackTrace void SimpleLogFormatter::writeStackTrace
(std::ostream& o, Logger::LEVEL level, const std::string& logLevelLabel, (std::ostream& o, Logger::LEVEL level, const std::string& logLevelLabel,
const Exception& e) const Exception& e)
{ {

View File

@ -2,7 +2,7 @@
/* /*
* aria2 - The high speed download utility * aria2 - The high speed download utility
* *
* Copyright (C) 2006 Tatsuhiro Tsujikawa * Copyright (C) 2010 Tatsuhiro Tsujikawa
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,25 +32,28 @@
* files in the program, then also delete it here. * files in the program, then also delete it here.
*/ */
/* copyright --> */ /* copyright --> */
#ifndef _D_SIMPLE_LOGGER_H_ #ifndef D_SIMPLE_LOG_FORMATTER_H
#define _D_SIMPLE_LOGGER_H_ #define D_SIMPLE_LOG_FORMATTER_H
#include "Logger.h" #include "LogFormatter.h"
namespace aria2 { namespace aria2 {
class SimpleLogger:public Logger { class SimpleLogFormatter:public LogFormatter {
protected: public:
SimpleLogFormatter();
virtual ~SimpleLogFormatter();
virtual void writeLog virtual void writeLog
(std::ostream& out, Logger::LEVEL logLevel, const std::string& logLevelLabel, (std::ostream& o, Logger::LEVEL logLevel, const std::string& logLevelLabel,
const char* msg, va_list ap); const char* msg, va_list ap);
virtual void writeStackTrace virtual void writeStackTrace
(std::ostream& out, Logger::LEVEL logLevel, const std::string& logLevelLabel, (std::ostream& o, Logger::LEVEL logLevel, const std::string& logLevelLabel,
const Exception& e); const Exception& e);
}; };
} // namespace aria2 } // namespace aria2
#endif // _D_SIMPLE_LOGGER_H_ #endif // D_SIMPLE_LOG_FORMATTER_H

View File

@ -186,6 +186,8 @@ const std::set<std::string>& listChangeableGlobalOptions()
PREF_MAX_OVERALL_UPLOAD_LIMIT, PREF_MAX_OVERALL_UPLOAD_LIMIT,
PREF_MAX_OVERALL_DOWNLOAD_LIMIT, PREF_MAX_OVERALL_DOWNLOAD_LIMIT,
PREF_MAX_CONCURRENT_DOWNLOADS, PREF_MAX_CONCURRENT_DOWNLOADS,
PREF_LOG,
PREF_LOG_LEVEL
}; };
static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS)); static std::set<std::string> options(vbegin(OPTIONS), vend(OPTIONS));
return options; return options;

View File

@ -964,6 +964,18 @@ SharedHandle<ValueBase> ChangeGlobalOptionXmlRpcMethod::process
(option->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS)); (option->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
e->getRequestGroupMan()->requestQueueCheck(); e->getRequestGroupMan()->requestQueueCheck();
} }
if(option->defined(PREF_LOG_LEVEL)) {
LogFactory::setLogLevel(option->get(PREF_LOG_LEVEL));
}
if(option->defined(PREF_LOG)) {
LogFactory::setLogFile(option->get(PREF_LOG));
try {
LogFactory::reconfigure();
} catch(RecoverableException& e) {
// TODO no exception handling
}
}
return VLB_OK; return VLB_OK;
} }

View File

@ -175,13 +175,7 @@ downloadresultcode::RESULT main(int argc, char* argv[])
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX)); bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX));
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
if(op->get(PREF_LOG) == "-") { LogFactory::setLogFile(op->get(PREF_LOG));
LogFactory::setLogFile(DEV_STDOUT);
} else if(op->blank(PREF_LOG)) {
LogFactory::setLogFile(DEV_NULL);
} else {
LogFactory::setLogFile(op->get(PREF_LOG));
}
LogFactory::setLogLevel(op->get(PREF_LOG_LEVEL)); LogFactory::setLogLevel(op->get(PREF_LOG_LEVEL));
if(op->getAsBool(PREF_QUIET)) { if(op->getAsBool(PREF_QUIET)) {
LogFactory::setConsoleOutput(false); LogFactory::setConsoleOutput(false);