Hello lili,
Using this log format and a Log4j/Logback Pattern Parser, you can't. An "absolute date" means that you can locate it on a timeline, so here you are missing day/month/year.
If you want to consider that this date always belongs to the current day, you can do so using a Java Parser, like for example:
Code: Select all
package sample.parser;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.lightysoft.logmx.business.ParsedEntry;
import com.lightysoft.logmx.mgr.LogFileParser;
/**
* Sample LogMX Parser able to parse a log file with multi-line support and Absolute/Relative Date support.<BR/>
* Here is an example of log file suitable for this parser:<BR/>
*
* 14:37:04,995 INFO [8080-exec-5] (Main.java:291) - Start main
* 14:37:05,151 INFO [8080-exec-5] (Main.java:293) - Finish main
*/
public class LiliParser extends LogFileParser {
/** Current parsed log entry */
private ParsedEntry entry = null;
/** Entry short-date format */
private static SimpleDateFormat shortDateFormat = new SimpleDateFormat("HH:mm:ss,S");
/** Entry long-date format */
private static SimpleDateFormat longDateFormat = new SimpleDateFormat("d/M/yy HH:mm:ss,S");
/** Pattern for entry begin */
private final static Pattern ENTRY_BEGIN_PATTERN = Pattern
.compile("^(\\d+:\\d+:\\d+,\\d+)\\s+(\\S+)\\s+\\[(.*?)\\]\\s+\\((.*?)\\)\\s+-\\s*(.*)$");
/** Buffer for Entry message (improves performance for multi-lines entries) */
private StringBuilder entryMsgBuffer = null;
/**
* Returns the name of this parser
* @see com.lightysoft.logmx.mgr.LogFileParser#getParserName()
*/
public String getParserName() {
return "Lili Parser";
}
/**
* Returns the supported file type for this parser
* @see com.lightysoft.logmx.mgr.LogFileParser#getSupportedFileType()
*/
public String getSupportedFileType() {
return "Lili log files";
}
/**
* Process the new line of text read from file
* @see com.lightysoft.logmx.mgr.LogFileParser#parseLine(java.lang.String)
*/
protected void parseLine(String line) throws Exception {
// If end of file, records last entry if necessary, and exits
if (line == null) {
recordPreviousEntryIfExists();
return;
}
Matcher matcher = ENTRY_BEGIN_PATTERN.matcher(line);
if (matcher.matches()) {
// Record previous found entry if exists, then create a new one
prepareNewEntry();
entry.setDate(matcher.group(1));
entry.setLevel(matcher.group(2));
entry.setThread(matcher.group(3));
entry.setEmitter(matcher.group(4));
entryMsgBuffer.append(matcher.group(5));
} else if (entry != null) {
entryMsgBuffer.append('\n').append(line); // appends this line to previous entry's text
}
}
/**
* Returns a relative Date for the given entry
* @see com.lightysoft.logmx.mgr.LogFileParser#getRelativeEntryDate(com.lightysoft.logmx.business.ParsedEntry)
*/
public Date getRelativeEntryDate(ParsedEntry pEntry) throws Exception {
synchronized (shortDateFormat) { // Java date formatter is not thread-safe
return shortDateFormat.parse(pEntry.getDate());
}
}
/**
* Returns the absolute Date for the given entry
* @see com.lightysoft.logmx.mgr.LogFileParser#getAbsoluteEntryDate(com.lightysoft.logmx.business.ParsedEntry)
*/
public Date getAbsoluteEntryDate(ParsedEntry pEntry) throws Exception {
Calendar now = Calendar.getInstance();
StringBuilder dateToParse = new StringBuilder(80);
dateToParse.append(now.get(Calendar.DAY_OF_MONTH)).append('/')
.append(now.get(Calendar.MONTH) + 1).append('/').append(now.get(Calendar.YEAR))
.append(' ').append(pEntry.getDate());
synchronized (longDateFormat) { // Java date formatter is not thread-safe
return longDateFormat.parse(dateToParse.toString());
}
}
/**
* Send to LogMX the current parsed log entry
* @throws Exception
*/
private void recordPreviousEntryIfExists() throws Exception {
if (entry != null) {
entry.setMessage(entryMsgBuffer.toString());
addEntry(entry);
}
}
/**
* Send to LogMX the current parsed log entry, then create a new one
* @throws Exception
*/
private void prepareNewEntry() throws Exception {
recordPreviousEntryIfExists();
entry = createNewEntry();
entryMsgBuffer = new StringBuilder(80);
}
}
To automatically import this Parser, go to menu "Tools" > "Options" > "General", click on button "Import options...", and choose
this file (then don't forget to disable your own previous Parser in "Parsers" Options tab). To get more information on how to create/modify Java class Parsers, you can
read this, or ask any question here
![Smile :)](./images/smilies/icon_e_smile.gif)