10 #ifdef LOG4CPP_HAVE_UNISTD_H 13 #ifdef LOG4CPP_HAVE_IO_H 35 #ifndef LOG4CPP_DISABLE_REMOTE_SYSLOG 37 #endif // LOG4CPP_DISABLE_REMOTE_SYSLOG 38 #ifdef LOG4CPP_HAVE_LIBIDSA 40 #endif // LOG4CPP_HAVE_LIBIDSA 41 #ifdef LOG4CPP_HAVE_SYSLOG 70 std::ifstream initFile(initFileName.c_str());
73 throw ConfigureFailure(std::string(
"File ") + initFileName +
" does not exist");
86 std::vector<std::string> catList;
90 for(std::vector<std::string>::const_iterator iter = catList.begin();
91 iter != catList.end(); ++iter) {
97 std::string currentAppender;
99 std::string prefix(
"appender");
100 Properties::const_iterator from =
_properties.lower_bound(prefix +
'.');
101 Properties::const_iterator to =
_properties.lower_bound(prefix +
'/');
102 for(Properties::const_iterator i = from; i != to; ++i) {
103 const std::string& key = (*i).first;
104 const std::string& value = (*i).second;
105 std::list<std::string> propNameParts;
106 std::back_insert_iterator<std::list<std::string> > pnpIt(propNameParts);
108 std::list<std::string>::const_iterator i2 = propNameParts.begin();
109 std::list<std::string>::const_iterator iEnd = propNameParts.end();
111 throw ConfigureFailure(std::string(
"missing appender name"));
114 const std::string appenderName = *i2++;
120 if (appenderName == currentAppender) {
125 currentAppender = appenderName;
129 throw ConfigureFailure(std::string(
"partial appender definition : ") + key);
137 std::string tempCatName =
138 (categoryName ==
"rootCategory") ? categoryName :
"category." + categoryName;
140 Properties::iterator iter =
_properties.find(tempCatName);
143 throw ConfigureFailure(std::string(
"Unable to find category: ") + tempCatName);
146 Category& category = (categoryName ==
"rootCategory") ?
150 std::list<std::string> tokens;
151 std::back_insert_iterator<std::list<std::string> > tokIt(tokens);
153 std::list<std::string>::const_iterator i = tokens.begin();
154 std::list<std::string>::const_iterator iEnd = tokens.end();
160 if (priorityName !=
"") {
163 }
catch(std::invalid_argument& e) {
165 " for category '" + categoryName +
"'");
175 for(; i != iEnd; ++i) {
177 AppenderMap::const_iterator appIt =
182 appenderName +
"' not found for category '" + categoryName +
"'");
193 std::string appenderPrefix = std::string(
"appender.") + appenderName;
196 Properties::iterator key =
_properties.find(appenderPrefix);
198 throw ConfigureFailure(std::string(
"Appender '") + appenderName +
"' not defined");
200 std::string::size_type length = (*key).second.find_last_of(
".");
201 std::string appenderType = (length == std::string::npos) ?
202 (*key).second : (*key).second.substr(length+1);
205 if (appenderType ==
"ConsoleAppender") {
208 else if (appenderType ==
"FileAppender") {
211 appender =
new FileAppender(appenderName, fileName, append);
213 else if (appenderType ==
"RollingFileAppender") {
215 size_t maxFileSize =
_properties.
getInt(appenderPrefix +
".maxFileSize", 10*1024*1024);
221 else if (appenderType ==
"GenerationalFileAppender") {
226 else if (appenderType ==
"DailyRollingFileAppender") {
228 unsigned int maxDaysKeep =
_properties.
getInt(appenderPrefix +
".maxDaysKeep", 0);
232 #ifndef LOG4CPP_DISABLE_REMOTE_SYSLOG 233 else if (appenderType ==
"SyslogAppender") {
239 syslogHost, facility, portNumber);
241 #endif // LOG4CPP_DISABLE_REMOTE_SYSLOG 242 #ifdef LOG4CPP_HAVE_SYSLOG 243 else if (appenderType ==
"LocalSyslogAppender") {
246 appender =
new SyslogAppender(appenderName, syslogName, facility);
248 #endif // LOG4CPP_HAVE_SYSLOG 249 else if (appenderType ==
"AbortAppender") {
252 #ifdef LOG4CPP_HAVE_LIBIDSA 253 else if (appenderType ==
"IdsaAppender") {
259 #endif // LOG4CPP_HAVE_LIBIDSA 263 else if (appenderType ==
"Win32DebugAppender") {
264 appender =
new Win32DebugAppender(appenderName);
267 else if (appenderType ==
"NTEventLogAppender") {
269 appender =
new NTEventLogAppender(appenderName, source);
274 "' has unknown type '" + appenderType +
"'");
284 if (thresholdName !=
"") {
287 }
catch(std::invalid_argument& e) {
290 " for threshold of appender '" + appenderName +
"'");
298 std::string tempString;
299 Properties::iterator key =
300 _properties.find(std::string(
"appender.") + appenderName +
".layout");
303 throw ConfigureFailure(std::string(
"Missing layout property for appender '") +
306 std::string::size_type length = (*key).second.find_last_of(
".");
307 std::string layoutType = (length == std::string::npos) ?
308 (*key).second : (*key).second.substr(length+1);
312 if (layoutType ==
"BasicLayout") {
315 else if (layoutType ==
"SimpleLayout") {
318 else if (layoutType ==
"PatternLayout") {
322 key =
_properties.find(std::string(
"appender.") + appenderName +
".layout.ConversionPattern");
330 layout = patternLayout;
334 "' for appender '") + appenderName +
"'");
350 categories.push_back(std::string(
"rootCategory"));
353 std::string prefix(
"category");
354 Properties::const_iterator from =
_properties.lower_bound(prefix +
'.');
355 Properties::const_iterator to =
_properties.lower_bound(prefix + (
char)(
'.' + 1));
356 for (Properties::const_iterator iter = from; iter != to; iter++) {
357 categories.push_back((*iter).first.substr(prefix.size() + 1));
void setLayout(Appender *appender, const std::string &name)
void getCategories(std::vector< std::string > &categories) const
virtual ~PropertyConfiguratorImpl()
virtual void setThreshold(Priority::Value priority)=0
PropertyConfiguratorImpl()
Appender * instantiateAppender(const std::string &name)
virtual void setAdditivity(bool additivity)
static Category & getInstance(const std::string &name)
virtual void setConversionPattern(const std::string &conversionPattern)
virtual void doConfigure(const std::string &initFileName)
AppenderMap _allAppenders
virtual bool requiresLayout() const =0
virtual void removeAllAppenders()
static Category & getRoot()
static std::string trim(const std::string &s)
virtual void setPriority(Priority::Value priority)
virtual int getInt(const std::string &property, int defaultValue)
virtual void load(std::istream &in)
static unsigned int split(std::vector< std::string > &v, const std::string &s, char delimiter, unsigned int maxSegments=INT_MAX)
virtual std::string getString(const std::string &property, const char *defaultValue)
virtual void addAppender(Appender *appender)
void instantiateAllAppenders()
virtual void setLayout(Layout *layout)=0
static Value getPriorityValue(const std::string &priorityName)
void configureCategory(const std::string &categoryname)
virtual bool getBool(const std::string &property, bool defaultValue)