Add --stderr option to redirect all stdout log output to stderr

pull/641/head
Tatsuhiro Tsujikawa 2016-04-27 00:16:55 +09:00
parent aa863fa4d1
commit db239c2853
7 changed files with 27 additions and 0 deletions

View File

@ -679,6 +679,13 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_ADVANCED);
handlers.push_back(op);
}
{
OptionHandler* op(new BooleanOptionHandler(
PREF_STDERR, TEXT_STDERR, A2_V_FALSE, OptionHandler::OPT_ARG));
op->addTag(TAG_ADVANCED);
handlers.push_back(op);
}
{
OptionHandler* op(
new NumberOptionHandler(PREF_STOP, TEXT_STOP, "0", 0, INT32_MAX));

View File

@ -47,6 +47,7 @@ namespace global {
namespace {
Console consoleCout;
Console consoleCerr;
Console consoleCoutBackup;
};
void initConsole(bool suppress)
@ -65,6 +66,12 @@ void initConsole(bool suppress)
}
}
void redirectStdoutToStderr()
{
consoleCoutBackup = std::move(consoleCout);
consoleCout = consoleCerr;
}
const Console& cout() { return consoleCout; }
const Console& cerr() { return consoleCerr; }

View File

@ -51,6 +51,9 @@ namespace global {
// output sent to the console objects are discarded.
void initConsole(bool suppress);
// stdout is redirected to stderr.
void redirectStdoutToStderr();
const Console& cout();
const Console& cerr();

View File

@ -300,6 +300,9 @@ error_code::Value option_processing(Option& op, bool standalone,
showUsage("", oparser, global::cerr());
return e.getErrorCode();
}
if (standalone && op.getAsBool(PREF_STDERR)) {
global::redirectStdoutToStderr();
}
if (standalone && !op.getAsBool(PREF_ENABLE_RPC) &&
#ifdef ENABLE_BITTORRENT
op.blank(PREF_TORRENT_FILE) &&

View File

@ -370,6 +370,8 @@ PrefPtr PREF_MIN_TLS_VERSION = makePref("min-tls-version");
PrefPtr PREF_SOCKET_RECV_BUFFER_SIZE = makePref("socket-recv-buffer-size");
// value: 1*digit
PrefPtr PREF_MAX_MMAP_LIMIT = makePref("max-mmap-limit");
// value: true | false
PrefPtr PREF_STDERR = makePref("stderr");
/**
* FTP related preferences

View File

@ -324,6 +324,8 @@ extern PrefPtr PREF_MIN_TLS_VERSION;
extern PrefPtr PREF_SOCKET_RECV_BUFFER_SIZE;
// value: 1*digit
extern PrefPtr PREF_MAX_MMAP_LIMIT;
// value: true | false
extern PrefPtr PREF_STDERR;
/**
* FTP related preferences

View File

@ -1085,5 +1085,8 @@
" size of those files. If file size is strictly\n" \
" greater than the size specified in this option,\n" \
" mmap will be disabled.")
#define TEXT_STDERR \
_(" --stderr[=true|false] Redirect all console output that would be\n" \
" otherwise printed in stdout to stderr.")
// clang-format on