10 #ifdef LOG4CPP_HAVE_UNISTD_H 13 #ifdef LOG4CPP_HAVE_IO_H 36 #ifdef LOG4CPP_HAVE_SYSLOG 39 #ifndef LOG4CPP_DISABLE_REMOTE_SYSLOG 49 std::ifstream initFile(initFileName.c_str());
52 throw ConfigureFailure(std::string(
"Config File ") + initFileName +
" does not exist or is unreadable");
59 std::string nextCommand;
60 std::string categoryName;
62 while (initFile >> nextCommand) {
64 if (nextCommand[0] ==
'#') {
66 std::getline(initFile, dummy);
70 if (!(initFile >> categoryName))
74 (categoryName.compare(
"root") == 0) ?
78 if (nextCommand.compare(
"appender") == 0) {
80 std::string appenderName;
82 if (initFile >> layout >> appenderName) {
84 if (appenderName.compare(
"file") == 0) {
85 std::string logFileName;
86 if (!(initFile >> logFileName)) {
87 throw ConfigureFailure(
"Missing filename for log file logging configuration file for category: " + categoryName);
91 else if (appenderName.compare(
"rolling") == 0) {
92 std::string logFileName;
94 unsigned int maxBackupIndex=1;
95 if (!(initFile >> logFileName)) {
96 throw ConfigureFailure(
"Missing filename for log file logging configuration file for category: " + categoryName);
98 if (!(initFile >> maxFileSize)) {
99 throw ConfigureFailure(
"Missing maximum size for log file logging configuration file for category: " + categoryName);
101 if (!(initFile >> maxBackupIndex)) {
102 throw ConfigureFailure(
"Missing maximum backup index for log file logging configuration file for category: " + categoryName);
106 else if (appenderName.compare(
"dailyrolling") == 0) {
107 std::string logFileName;
108 unsigned int maxKeepDays=1;
109 if (!(initFile >> logFileName)) {
110 throw ConfigureFailure(
"Missing filename for log file logging configuration file for category: " + categoryName);
112 if (!(initFile >> maxKeepDays)) {
113 throw ConfigureFailure(
"Missing maximum keep days for log file logging configuration file for category: " + categoryName);
117 else if (appenderName.compare(
"console") == 0) {
121 else if (appenderName.compare(
"stdout") == 0) {
125 else if (appenderName.compare(
"stderr") == 0) {
129 #ifdef LOG4CPP_HAVE_SYSLOG 130 else if (appenderName.compare(
"syslog") == 0) {
131 std::string syslogName;
133 if (!(initFile >> syslogName)) {
134 throw ConfigureFailure(
"Missing syslogname for SysLogAppender for category: " + categoryName);
136 if (!(initFile >> facility)) {
147 else if (appenderName.compare(
"nteventlog") == 0) {
149 if (!(initFile >> source)) {
150 throw ConfigureFailure(
"Missing source for NTEventLogAppender for category: " + categoryName);
153 new log4cpp::NTEventLogAppender(categoryName, source);
156 #if !defined(LOG4CPP_DISABLE_REMOTE_SYSLOG) 157 else if (appenderName.compare(
"remotesyslog") == 0) {
158 std::string syslogName;
162 if (!(initFile >> syslogName)) {
163 throw ConfigureFailure(
"Missing syslogname for SysLogAppender for category: " + categoryName);
165 if (!(initFile >> relayer)) {
166 throw ConfigureFailure(
"Missing syslog host for SysLogAppender for category: " + categoryName);
168 if (!(initFile >> facility)) {
171 if (!(initFile >> portNumber)) {
177 #endif // LOG4CPP_DISABLE_REMOTE_SYSLOG 181 ") in logging configuration file for category: " +
184 if (layout.compare(
"basic") == 0)
186 else if (layout.compare(
"simple") == 0)
188 else if (layout.compare(
"pattern") == 0) {
193 initFile.getline(pattern, 1000);
199 ") in logging configuration file for category: " +
205 else if (nextCommand.compare(
"priority") == 0) {
206 std::string priority;
207 if (!(initFile >> priority)) {
208 throw ConfigureFailure(
"Missing priority in logging configuration file for category: " + categoryName);
213 }
catch(std::invalid_argument) {
214 throw ConfigureFailure(
"Invalid priority ("+priority+
") in logging configuration file for category: "+categoryName);
217 else if (nextCommand.compare(
"category") == 0) {
225 throw ConfigureFailure(
"Invalid format in logging configuration file. Command: " + nextCommand);
static void configure(const std::string &initFileName)
static Category & getInstance(const std::string &name)
virtual void setConversionPattern(const std::string &conversionPattern)
static Category & getRoot()
virtual void setPriority(Priority::Value priority)
virtual void addAppender(Appender *appender)
virtual void setLayout(Layout *layout)=0
static Value getPriorityValue(const std::string &priorityName)
random user-level messages