Skip to content

Commit

Permalink
Fix casting exception for SocketHubAppender (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
otros-systems authored Jul 23, 2018
1 parent 4cfffc9 commit e86c3ab
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*******************************************************************************
* Copyright 2011 Krzysztof Otrebski
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
/*
Copyright 2011 Krzysztof Otrebski
<p>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<p>
http://www.apache.org/licenses/LICENSE-2.0
<p>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package pl.otros.logview.parser.log4j;

import com.google.common.collect.ImmutableMap;
Expand All @@ -24,10 +24,7 @@
import pl.otros.logview.api.InitializationException;
import pl.otros.logview.api.model.LogData;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -66,7 +63,10 @@ public static LogData translateLog4j(LoggingEvent event) {
if (properties != null) {
Map<String, String> props = new HashMap<>(properties.size());
for (Object key : properties.keySet()) {
String value = (String) properties.get(key);
String value = Optional
.ofNullable(properties.get(key))
.map(Object::toString)
.orElse("");
if (StringUtils.isNotBlank(value)) {
props.put(key.toString(), value);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public static void parsePattern(Properties p) throws InitializationException {
throw new InitializationException("Log " + CONVERSION_PATTERN + " is not set.");
}

Matcher dateFormatMatcher = Pattern.compile("%-?\\d*(?:\\.\\d+)?d(?:\\{([^}]+)\\})?").matcher(conversionPattern);
Matcher dateFormatMatcher = Pattern.compile("%-?\\d*(?:\\.\\d+)?d(?:\\{([^}]+)})?").matcher(conversionPattern);
String dateFormat = "yyyy-MM-dd HH:mm:ss,SSS"; //ISO8601
if (dateFormatMatcher.find() && dateFormatMatcher.groupCount() >= 1) {
if (dateFormatMatcher.group(1).equals("ABSOLUTE")) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public static void parsePattern(Properties p) throws InitializationException {
conversionCharacters.put('x', "NDC");

for (Map.Entry<Character, String> conversion : conversionCharacters.entrySet()) {
parserPattern = parserPattern.replaceAll("%-?\\d*(?:\\.\\d+)?" + conversion.getKey() + "(?:\\{([^}]+)\\})?", conversion.getValue());
parserPattern = parserPattern.replaceAll("%-?\\d*(?:\\.\\d+)?" + conversion.getKey() + "(?:\\{([^}]+)})?", conversion.getValue());
}
p.setProperty("pattern", parserPattern);
}
Expand Down

0 comments on commit e86c3ab

Please sign in to comment.