Sha256: ac46295d8718193bcfc9fa41a5ceb1282eb5f2bd53c1912467555ee2345ebc61
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
package org.embulk.parser.apache.log; import java.util.regex.Pattern; import java.util.regex.Matcher; import org.apache.commons.lang3.StringUtils; import org.embulk.spi.time.TimestampParser; public class TimestampLogElementFactory implements LogElementFactory<TimestampLogElement>, Patterns { private TimestampParser.Task task; private String name; public TimestampLogElementFactory(TimestampParser.Task task, String name) { this.task = task; this.name = name; } @Override public TimestampLogElement create(String parameter) { if(StringUtils.isEmpty(parameter)){ return new TimestampLogElement(task, name, "\\[([^\\]]+)\\]"); }else{ String regex = toTimestampRegex(parameter); return new TimestampLogElement(task, name, regex, parameter); } } private String toTimestampRegex(String parameter) { String regex = "(" + parameter + ")"; regex = regex.replaceAll("\\[|\\]","\\\\$0"); regex = regex.replaceAll("%[abhpABPZ]","[A-z]+"); regex = regex.replaceAll("%c","[A-z]{3} [A-z]{3} \\\\d{2} \\\\d{2}:\\\\d{2}:\\\\d{2} \\\\d{4}"); regex = regex.replaceAll("%[dgmyCHIMSUVW]","\\\\d{2}"); regex = regex.replaceAll("%[Dx]","\\\\d{2}/\\\\d{2}/\\\\d{2}"); regex = regex.replaceAll("%[ekl]","[1-9 ]\\\\d"); regex = regex.replaceAll("%F","\\\\d{4}-\\\\d{2}-\\\\d{2}"); regex = regex.replaceAll("%[GY]","\\\\d{4}"); regex = regex.replaceAll("%j","\\\\d{3}"); regex = regex.replaceAll("%r","\\\\d{2}:\\\\d{2}:\\\\d{2} [A-z]+"); regex = regex.replaceAll("%R","\\\\d{2}:\\\\d{2}"); regex = regex.replaceAll("%s","\\\\d+"); regex = regex.replaceAll("%[TX]","\\\\d{2}:\\\\d{2}:\\\\d{2}"); regex = regex.replaceAll("%[uw]","\\\\d"); regex = regex.replaceAll("%z","\\\\+\\\\d{4}"); return regex; } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
embulk-parser-apache-custom-log-0.3.0 | src/main/java/org/embulk/parser/apache/log/TimestampLogElementFactory.java |