2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
2010-11-20 08:21:36 +00:00
|
|
|
* Copyright (C) 2010 Tatsuhiro Tsujikawa
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2006-02-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_LOGGER_H
|
|
|
|
#define D_LOGGER_H
|
2006-02-28 02:25:45 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2009-07-18 08:30:37 +00:00
|
|
|
#include <string>
|
|
|
|
|
2011-08-09 14:33:55 +00:00
|
|
|
#include "SharedHandle.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
class Exception;
|
2011-08-09 14:33:55 +00:00
|
|
|
class OutputFile;
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
class Logger {
|
|
|
|
public:
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
enum LEVEL {
|
2010-04-16 09:25:59 +00:00
|
|
|
A2_DEBUG = 1 << 0,
|
|
|
|
A2_INFO = 1 << 1,
|
|
|
|
A2_NOTICE = 1 << 2,
|
|
|
|
A2_WARN = 1 << 3,
|
|
|
|
A2_ERROR = 1 << 4,
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
};
|
2009-07-18 08:30:37 +00:00
|
|
|
private:
|
2013-01-05 09:48:09 +00:00
|
|
|
// Minimum log level for file log output.
|
2010-06-21 13:51:56 +00:00
|
|
|
LEVEL logLevel_;
|
2011-08-09 14:33:55 +00:00
|
|
|
SharedHandle<OutputFile> fpp_;
|
2013-01-05 09:48:09 +00:00
|
|
|
// Minimum log level for console log output.
|
|
|
|
LEVEL consoleLogLevel_;
|
|
|
|
// true if console log output is enabled.
|
|
|
|
bool consoleOutput_;
|
2012-12-08 12:48:18 +00:00
|
|
|
bool useColor_;
|
2010-11-20 12:33:12 +00:00
|
|
|
// Don't allow copying
|
|
|
|
Logger(const Logger&);
|
|
|
|
Logger& operator=(const Logger&);
|
2011-08-07 08:06:07 +00:00
|
|
|
|
|
|
|
void writeLog
|
|
|
|
(Logger::LEVEL level,
|
|
|
|
const char* sourceFile,
|
|
|
|
int lineNum,
|
|
|
|
const char* msg,
|
2013-01-05 09:48:09 +00:00
|
|
|
const char* trace);
|
|
|
|
|
|
|
|
// Returns true if message with log level |level| will be outputted
|
|
|
|
// to file.
|
|
|
|
bool fileLogEnabled(LEVEL level);
|
|
|
|
// Returns true if message with log level |level| will be outputted
|
|
|
|
// to console.
|
|
|
|
bool consoleLogEnabled(LEVEL level);
|
2009-07-18 08:30:37 +00:00
|
|
|
public:
|
|
|
|
Logger();
|
|
|
|
|
2010-11-20 08:21:36 +00:00
|
|
|
~Logger();
|
|
|
|
|
|
|
|
void log
|
|
|
|
(LEVEL level,
|
|
|
|
const char* sourceFile,
|
|
|
|
int lineNum,
|
|
|
|
const char* msg);
|
|
|
|
|
|
|
|
void log
|
|
|
|
(LEVEL level,
|
|
|
|
const char* sourceFile,
|
|
|
|
int lineNum,
|
|
|
|
const std::string& msg);
|
|
|
|
|
|
|
|
void log
|
|
|
|
(LEVEL level,
|
|
|
|
const char* sourceFile,
|
|
|
|
int lineNum,
|
|
|
|
const char* msg,
|
|
|
|
const Exception& ex);
|
2009-07-18 08:30:37 +00:00
|
|
|
|
2010-11-20 08:21:36 +00:00
|
|
|
void log
|
|
|
|
(LEVEL level,
|
|
|
|
const char* sourceFile,
|
|
|
|
int lineNum,
|
|
|
|
const std::string& msg,
|
|
|
|
const Exception& ex);
|
2009-07-18 08:30:37 +00:00
|
|
|
|
|
|
|
void openFile(const std::string& filename);
|
|
|
|
|
|
|
|
void closeFile();
|
|
|
|
|
|
|
|
void setLogLevel(LEVEL level)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
logLevel_ = level;
|
2009-07-18 08:30:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 09:48:09 +00:00
|
|
|
void setConsoleLogLevel(LEVEL level)
|
|
|
|
{
|
|
|
|
consoleLogLevel_ = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setConsoleOutput(bool enabled);
|
2010-02-09 12:20:20 +00:00
|
|
|
|
|
|
|
// Returns true if this logger actually writes debug log message to
|
|
|
|
// either file or stdout.
|
2010-11-20 08:21:36 +00:00
|
|
|
bool levelEnabled(LEVEL level);
|
2006-02-17 13:35:04 +00:00
|
|
|
};
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_LOGGER_H
|