8000 Bug fix for FileAppenders, when using the ',aux' extension. · log4cplus/log4cplus@97c690c · GitHub
[go: up one dir, main page]

Skip to content

Commit 97c690c

Browse files
committed
Bug fix for FileAppenders, when using the ',aux' extension.
This patch fixes the implementation of the ',aux' extension for FileAppenders. The implementation can now cope with ',aux' as well as ',<space(s)>aux'-types.
1 parent 3565945 commit 97c690c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/fileappender.cxx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,14 +1093,33 @@ static tstring
10931093
preprocessDateTimePattern(const tstring_view& pattern, DailyRollingFileSchedule& schedule)
10941094
{
10951095
// Example: "yyyy-MM-dd HH:mm:ss,aux"
1096+
// Example with space(s) between the ',' and 'aux': "yyyy-MM-dd HH:mm:ss, aux"
10961097
// Patterns from java.text.SimpleDateFormat not implemented here: Y, F, k, K, S, X
10971098

10981099
tostringstream result;
10991100

1100-
bool auxilary = (pattern.find(LOG4CPLUS_TEXT(",aux")) == pattern.length()-4);
1101+
size_t aux_len = 0;
1102+
auto pattern_length = pattern.length();
1103+
if (pattern_length >= 4 && pattern.find(LOG4CPLUS_TEXT("aux"), pattern_length-3) == pattern_length-3) {
1104+
auto const comma_pos = pattern.rfind(LOG4CPLUS_TEXT(","));
1105+
if (comma_pos != tstring_view::npos) {
1106+
auto const comma_to_aux_len = pattern_length - 4 - comma_pos;
1107+
if (comma_to_aux_len == 0) {
1108+
aux_len = 4;
1109+
}
1110+
else if (comma_to_aux_len > 0) {
1111+
auto const space_str = pattern.substr(comma_pos+1, comma_to_aux_len);
1112+
if (space_str == tstring(comma_to_aux_len, ' ')) {
1113+
aux_len = 4 + comma_to_aux_len;
1114+
}
1115+
}
1116+
pattern_length -= aux_len;
1117+
}
1118+
}
1119+
11011120
bool has_week = false, has_day = false, has_hour = false, has_minute = false;
11021121

1103-
for (size_t i = 0, pattern_length = pattern.length(); i < pattern_length; )
1122+
for (size_t i = 0; i < pattern_length; )
11041123
{
11051124
tchar c = pattern[i];
11061125
size_t end_pos = pattern.find_first_not_of(c, i);
@@ -1202,7 +1221,7 @@ preprocessDateTimePattern(const tstring_view& pattern, DailyRollingFileSchedule&
12021221
i += len;
12031222
}
12041223

1205-
if (!auxilary)
1224+
if (aux_len == 0)
12061225
{
12071226
if (has_minute)
12081227
schedule = MINUTELY;

0 commit comments

Comments
 (0)
0