summaryrefslogtreecommitdiff
path: root/src/mongo/db/server_options.cpp
diff options
context:
space:
mode:
authormatt dannenberg <matt.dannenberg@10gen.com>2013-10-10 19:01:04 -0400
committermatt dannenberg <matt.dannenberg@10gen.com>2013-10-11 14:05:41 -0400
commit0ffa31cb9e1fdd281710aa872cac27c5ef8e3145 (patch)
tree038ea02ef9d46ac7c7892ac37dd074ccbbcf5e6f /src/mongo/db/server_options.cpp
parent1016dea64ab9a2c26e1da9c71991f9234d3806ec (diff)
downloadmongo-0ffa31cb9e1fdd281710aa872cac27c5ef8e3145.tar.gz
SERVER-7454 add syslogFacility flag to specify syslog facility
Diffstat (limited to 'src/mongo/db/server_options.cpp')
-rw-r--r--src/mongo/db/server_options.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/mongo/db/server_options.cpp b/src/mongo/db/server_options.cpp
index d984b5ec104..2b8ecc86fa0 100644
--- a/src/mongo/db/server_options.cpp
+++ b/src/mongo/db/server_options.cpp
@@ -30,6 +30,9 @@
#ifdef _WIN32
#include <direct.h>
+#else
+#define SYSLOG_NAMES
+#include <syslog.h>
#endif
#include "mongo/base/status.h"
@@ -138,6 +141,14 @@ namespace mongo {
if (!ret.isOK()) {
return ret;
}
+#ifndef _WIN32
+ ret = options->addOption(OD("syslogFacility", "syslogFacility", moe::String,
+ "syslog facility used for monogdb syslog message",
+ true));
+ if (!ret.isOK()) {
+ return ret;
+ }
+#endif // _WIN32
ret = options->addOption(OD("logappend", "logappend", moe::Switch,
"append to logpath instead of over-writing", true));
if (!ret.isOK()) {
@@ -494,6 +505,28 @@ namespace mongo {
}
serverGlobalParams.logWithSyslog = params.count("syslog");
+
+ if (params.count("syslogFacility")) {
+ std::string facility = params["syslogFacility"].as<string>();
+ bool set = false;
+ // match facility string to facility value
+ for (unsigned long i = 0; i < sizeof(facilitynames)/sizeof(facilitynames[0]); i++) {
+ if (!facility.compare(facilitynames[i].c_name)) {
+ serverGlobalParams.syslogFacility = facilitynames[i].c_val;
+ set = true;
+ }
+ }
+ if (!set) {
+ StringBuilder sb;
+ sb << "ERROR: syslogFacility must be set to a string representing one of the "
+ << "possible syslog facilities";
+ return Status(ErrorCodes::BadValue, sb.str());
+ }
+ }
+ else {
+ serverGlobalParams.syslogFacility = LOG_USER;
+ }
+
serverGlobalParams.logAppend = params.count("logappend");
if (!serverGlobalParams.logpath.empty() && serverGlobalParams.logWithSyslog) {
return Status(ErrorCodes::BadValue, "Cant use both a logpath and syslog ");