Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ongoing work on layout-pattern-to-regex converters
- Loading branch information
Showing
9 changed files
with
686 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
logback-decoder LICENSE | ||
----------------------- | ||
|
||
logback-decoder: the log file decoder | ||
Copyright (C) 2012, QOS.ch. All rights reserved. | ||
|
||
This program and the accompanying materials are dual-licensed under | ||
either the terms of the Eclipse Public License v1.0 as published by | ||
the Eclipse Foundation | ||
|
||
or (per the licensee's choosing) | ||
|
||
under the terms of the GNU Lesser General Public License version 2.1 | ||
as published by the Free Software Foundation. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
Wed Apr 18 16:55:59 WEDT 2012 | ||
Thank you for downloading logback-decoder, the logback log-file decoder. | ||
|
||
The documentation can be found in the Wiki here: | ||
https://github.com/qos-ch/logback-decoder/wiki | ||
|
||
Building logback-decoder | ||
======================== | ||
|
||
This project requires Maven 2.2.1 or later to build (3.x works as well). | ||
Run the following command to build: | ||
|
||
$ mvn install | ||
|
||
In case of problems | ||
=================== | ||
|
||
In case of problems, please do not hesitate to post an e-mail message | ||
on the logback-user@qos.ch mailing list. However, please do not | ||
directly e-mail logback developers. The answer to your question might | ||
be useful to other users. Moreover, there are many knowledgeable users | ||
on the logback-user mailing lists who can quickly answer your | ||
questions. | ||
|
19 changes: 14 additions & 5 deletions
19
src/main/java/ch/qos/logback/decoder/AccessDecode.java
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/ch/qos/logback/decoder/DateRegexConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (C) 2012, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.decoder; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.CoreConstants; | ||
import ch.qos.logback.core.util.DatePatternToRegexUtil; | ||
|
||
/** | ||
* Converts a date pattern into a regular expression | ||
*/ | ||
public class DateRegexConverter extends ClassicConverter { | ||
private String datePattern = null; | ||
|
||
public void start() { | ||
datePattern = getFirstOption(); | ||
if (datePattern == null) { | ||
datePattern = CoreConstants.ISO8601_PATTERN; | ||
} | ||
|
||
if (datePattern.equals(CoreConstants.ISO8601_STR)) { | ||
datePattern = CoreConstants.ISO8601_PATTERN; | ||
} | ||
} | ||
|
||
public String convert(ILoggingEvent le) { | ||
return new DatePatternToRegexUtil(datePattern).toRegex(); | ||
} | ||
} |
47 changes: 41 additions & 6 deletions
47
src/main/java/ch/qos/logback/decoder/FieldCapturer.java
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,55 @@ | ||
/** | ||
* Copyright (C) 2012, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.decoder; | ||
|
||
|
||
/** | ||
* A capturing group (as in regular expressions) for a particular logback | ||
* layout pattern. | ||
* | ||
* @param <E> | ||
* An {@link Event} type (XXX: Should this actually be "E extends Event"?) | ||
*/ | ||
public abstract class FieldCapturer<E> { | ||
|
||
protected boolean capturing; | ||
protected String regexExpression; | ||
|
||
public String getRegexExpression() { | ||
return regexExpression; | ||
protected String regexPattern; | ||
|
||
/** | ||
* Gets the regular expression pattern used to parse a field from an event | ||
* | ||
* @return the pattern as a string | ||
*/ | ||
public String getRegexPattern() { | ||
return regexPattern; | ||
} | ||
|
||
/** | ||
* Determines if this capturer is in the process of capturing fields | ||
* | ||
* @return <c>true</c> if capture is in progress; <c>false</c> otherwise | ||
*/ | ||
public boolean isCapturing() { | ||
return capturing; | ||
} | ||
|
||
/** | ||
* Parses a field from an event | ||
* | ||
* @param event | ||
* the event to be evaluated | ||
* @param fieldAsStr | ||
* (XXX: I'm not entirely sure. I'm guessing this is the field's layout pattern. e.g., "%msg") | ||
*/ | ||
abstract void captureField(E event, String fieldAsStr); | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/ch/qos/logback/decoder/FileOfCallerRegexConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (C) 2012, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.decoder; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
|
||
/** | ||
* Converts a file-of-caller pattern into a regular expression | ||
*/ | ||
public class FileOfCallerRegexConverter extends ClassicConverter { | ||
|
||
public String convert(ILoggingEvent le) { | ||
// The caller must be a Java class, and Java files match the | ||
// class names with the .java extension as required by the | ||
// Java compiler. Therefore, the pattern is the valid | ||
// characters for a Java identifier plus the ".java" suffix. | ||
return "[$_a-zA-z0-9]+\\.java"; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/ch/qos/logback/decoder/LineOfCallerRegexConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (C) 2012, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.decoder; | ||
|
||
import ch.qos.logback.classic.pattern.ClassicConverter; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
|
||
/** | ||
* Converts a line-of-caller pattern into a regular expression | ||
*/ | ||
public class LineOfCallerRegexConverter extends ClassicConverter { | ||
|
||
public String convert(ILoggingEvent le) { | ||
return "\\d+|\\?"; | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/main/java/ch/qos/logback/decoder/PatternLayoutRegexifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* Copyright (C) 2012, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.decoder; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.CoreConstants; | ||
import ch.qos.logback.core.pattern.PatternLayoutBase; | ||
|
||
/** | ||
* Utility to convert a layout pattern into a regular expression | ||
* | ||
* @author Anthony Trinh | ||
*/ | ||
public class PatternLayoutRegexifier extends PatternLayoutBase<ILoggingEvent> { | ||
|
||
public static final Map<String, String> defaultConverterMap = new HashMap<String, String>(); | ||
private Locale _locale; | ||
|
||
static { | ||
// defaultConverterMap.putAll(Parser.DEFAULT_COMPOSITE_CONVERTER_MAP); | ||
|
||
defaultConverterMap.put("d", DateRegexConverter.class.getName()); | ||
defaultConverterMap.put("date", DateRegexConverter.class.getName()); | ||
|
||
// defaultConverterMap.put("r", RelativeTimeRegexConverter.class.getName()); | ||
// defaultConverterMap.put("relative", RelativeTimeRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("level", LevelRegexConverter.class.getName()); | ||
// defaultConverterMap.put("le", LevelRegexConverter.class.getName()); | ||
// defaultConverterMap.put("p", LevelRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("t", ThreadRegexConverter.class.getName()); | ||
// defaultConverterMap.put("thread", ThreadRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("lo", LoggerRegexConverter.class.getName()); | ||
// defaultConverterMap.put("logger", LoggerRegexConverter.class.getName()); | ||
// defaultConverterMap.put("c", LoggerRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("m", MessageRegexConverter.class.getName()); | ||
// defaultConverterMap.put("msg", MessageRegexConverter.class.getName()); | ||
// defaultConverterMap.put("message", MessageRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("C", ClassOfCallerRegexConverter.class.getName()); | ||
// defaultConverterMap.put("class", ClassOfCallerRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("M", MethodOfCallerRegexConverter.class.getName()); | ||
// defaultConverterMap.put("method", MethodOfCallerRegexConverter.class.getName()); | ||
|
||
defaultConverterMap.put("L", LineOfCallerRegexConverter.class.getName()); | ||
defaultConverterMap.put("line", LineOfCallerRegexConverter.class.getName()); | ||
|
||
defaultConverterMap.put("F", FileOfCallerRegexConverter.class.getName()); | ||
defaultConverterMap.put("file", FileOfCallerRegexConverter.class.getName()); | ||
|
||
// defaultConverterMap.put("X", MDCRegexConverter.class.getName()); | ||
// defaultConverterMap.put("mdc", MDCRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("ex", ThrowableProxyRegexConverter.class.getName()); | ||
// defaultConverterMap.put("exception", ThrowableProxyRegexConverter.class | ||
// .getName()); | ||
// defaultConverterMap.put("rEx", RootCauseFirstThrowableProxyRegexConverter.class.getName()); | ||
// defaultConverterMap.put("rootException", RootCauseFirstThrowableProxyRegexConverter.class | ||
// .getName()); | ||
// defaultConverterMap.put("throwable", ThrowableProxyRegexConverter.class | ||
// .getName()); | ||
// | ||
// defaultConverterMap.put("xEx", ExtendedThrowableProxyRegexConverter.class.getName()); | ||
// defaultConverterMap.put("xException", ExtendedThrowableProxyRegexConverter.class | ||
// .getName()); | ||
// defaultConverterMap.put("xThrowable", ExtendedThrowableProxyRegexConverter.class | ||
// .getName()); | ||
// | ||
// defaultConverterMap.put("nopex", NopThrowableInformationRegexConverter.class | ||
// .getName()); | ||
// defaultConverterMap.put("nopexception", | ||
// NopThrowableInformationRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("cn", ContextNameAction.class.getName()); | ||
// defaultConverterMap.put("contextName", ContextNameRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("caller", CallerDataRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("marker", MarkerRegexConverter.class.getName()); | ||
// | ||
// defaultConverterMap.put("property", PropertyRegexConverter.class.getName()); | ||
// | ||
// | ||
// defaultConverterMap.put("n", LineSeparatorRegexConverter.class.getName()); | ||
} | ||
|
||
/** | ||
* Sets the locale | ||
* | ||
* @param locale | ||
*/ | ||
public void setLocale(Locale locale) { | ||
_locale = locale; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getDefaultConverterMap() { | ||
return defaultConverterMap; | ||
} | ||
|
||
@Override | ||
public String doLayout(ILoggingEvent event) { | ||
if (!isStarted()) { | ||
return CoreConstants.EMPTY_STRING; | ||
} | ||
return writeLoopOnConverters(event); | ||
} | ||
|
||
} |
Oops, something went wrong.