Skip to content

Commit

Permalink
Comment-out temporarily unsupported column types, fix iso8601/simple …
Browse files Browse the repository at this point in the history
…date conversion through the menu on the timestamp table header
  • Loading branch information
scottdeboy committed Dec 18, 2023
1 parent 6203572 commit 6475b4a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 57 deletions.
30 changes: 7 additions & 23 deletions src/main/java/org/apache/log4j/chainsaw/ChainsawColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,22 @@ public class ChainsawColumns {
private static final List<String> columnNames = new ArrayList<>();

static {
columnNames.add(ChainsawConstants.LOGGER_COL_NAME);
columnNames.add(ChainsawConstants.LOG4J_MARKER_COL_NAME); //add uppercase col name
columnNames.add(ChainsawConstants.TIMESTAMP_COL_NAME);
columnNames.add(ChainsawConstants.LOG4J_MARKER_COL_NAME);
columnNames.add(ChainsawConstants.LEVEL_COL_NAME);
columnNames.add(ChainsawConstants.THREAD_COL_NAME);
columnNames.add(ChainsawConstants.LOGGER_COL_NAME);
columnNames.add(ChainsawConstants.MESSAGE_COL_NAME);
columnNames.add(ChainsawConstants.NDC_COL_NAME);
columnNames.add(ChainsawConstants.THROWABLE_COL_NAME);
columnNames.add(ChainsawConstants.CLASS_COL_NAME);
columnNames.add(ChainsawConstants.METHOD_COL_NAME);
columnNames.add(ChainsawConstants.FILE_COL_NAME);
columnNames.add(ChainsawConstants.LINE_COL_NAME);
columnNames.add(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name

//NOTE: ID must ALWAYS be last field because the model adds this value itself as an identifier to the end of the consructed vector
columnNames.add(ChainsawConstants.ID_COL_NAME);
}

public static final int INDEX_LOGGER_COL_NAME = 1;
public static final int INDEX_TIMESTAMP_COL_NAME = 1;
public static final int INDEX_LOG4J_MARKER_COL_NAME = 2;
public static final int INDEX_TIMESTAMP_COL_NAME = 3;
public static final int INDEX_LEVEL_COL_NAME = 4;
public static final int INDEX_THREAD_COL_NAME = 5;
public static final int INDEX_MESSAGE_COL_NAME = 6;
public static final int INDEX_NDC_COL_NAME = 7;
public static final int INDEX_THROWABLE_COL_NAME = 8;
public static final int INDEX_CLASS_COL_NAME = 9;
public static final int INDEX_METHOD_COL_NAME = 10;
public static final int INDEX_FILE_COL_NAME = 11;
public static final int INDEX_LINE_COL_NAME = 12;
public static final int INDEX_MILLIS_DELTA_COL_NAME = 13;
public static final int INDEX_ID_COL_NAME = 14;
public static final int INDEX_LEVEL_COL_NAME = 3;
public static final int INDEX_LOGGER_COL_NAME = 4;
public static final int INDEX_MESSAGE_COL_NAME = 5;
public static final int INDEX_ID_COL_NAME = 6;

public static final Cursor CURSOR_FOCUS_ON;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,11 @@ public Object getValueAt(int rowIndex, int columnIndex) {
case ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME:
return event.getProperty(ChainsawConstants.LOG4J_MARKER_COL_NAME);

/*
case ChainsawColumns.INDEX_MILLIS_DELTA_COL_NAME:
return event.getProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
*/
case ChainsawColumns.INDEX_LOGGER_COL_NAME:
return event.m_logger;

Expand All @@ -570,6 +572,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
case ChainsawColumns.INDEX_MESSAGE_COL_NAME:
return event.m_message;

/*
case ChainsawColumns.INDEX_NDC_COL_NAME:
return event.m_ndc;
Expand All @@ -590,6 +593,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
case ChainsawColumns.INDEX_METHOD_COL_NAME:
return info == null ? "" : info.methodName;
*/

default:

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/apache/log4j/chainsaw/ColumnComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public int compare(Object o1, Object o2) {

break;

case ChainsawColumns.INDEX_NDC_COL_NAME:
/* case ChainsawColumns.INDEX_NDC_COL_NAME:
if (e1.m_ndc != null && e2.m_ndc != null) {
sort =
e1.m_ndc.compareToIgnoreCase(
Expand Down Expand Up @@ -116,22 +116,25 @@ public int compare(Object o1, Object o2) {
e2.m_locationInfo.methodName);
}
break;
break;*/

case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME:
sort = e1.m_timestamp.compareTo(e2.m_timestamp);
break;

/*
case ChainsawColumns.INDEX_THREAD_COL_NAME:
sort = e1.m_threadName.compareToIgnoreCase(e2.m_threadName);
break;
*/

case ChainsawColumns.INDEX_ID_COL_NAME:
int id1 = Integer.parseInt(e1.getProperty(Constants.LOG4J_ID_KEY));
int id2 = Integer.parseInt(e2.getProperty(Constants.LOG4J_ID_KEY));
sort = Integer.compare(id2, id1);
break;

/*
case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
// if (e1.getThrowableStrRep() != null && e2.getThrowableStrRep() != null) {
// String[] s1 = e1.getThrowableStrRep();
Expand All @@ -154,6 +157,7 @@ public int compare(Object o1, Object o2) {
sort = e1.m_locationInfo.lineNumber - e2.m_locationInfo.lineNumber;
}
break;
*/

//other columns may be Property values - see if there is an Property value matching column name
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import java.awt.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.*;

import org.apache.commons.configuration2.AbstractConfiguration;
import org.apache.log4j.chainsaw.prefs.SettingsManager;

Expand Down Expand Up @@ -181,7 +181,7 @@ public Component getTableCellRendererComponent(

JComponent component;
switch (colIndex) {
case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
/* case ChainsawColumns.INDEX_THROWABLE_COL_NAME:
if (value instanceof String[] && ((String[]) value).length > 0) {
Style tabStyle = singleLineTextPane.getLogicalStyle();
StyleConstants.setTabSet(tabStyle, tabs);
Expand All @@ -200,7 +200,7 @@ public Component getTableCellRendererComponent(
}
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
component = generalPanel;
break;
break;*/
case ChainsawColumns.INDEX_LOGGER_COL_NAME:
String logger = value.toString();
int startPos = -1;
Expand All @@ -222,7 +222,7 @@ public Component getTableCellRendererComponent(
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
component = generalPanel;
break;
case ChainsawColumns.INDEX_CLASS_COL_NAME:
/* case ChainsawColumns.INDEX_CLASS_COL_NAME:
singleLineTextPane.setText(value.toString());
setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.CLASS_FIELD), (StyledDocument) singleLineTextPane.getDocument());
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
Expand Down Expand Up @@ -251,7 +251,7 @@ public Component getTableCellRendererComponent(
setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.THREAD_FIELD), (StyledDocument) singleLineTextPane.getDocument());
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
component = generalPanel;
break;
break;*/
case ChainsawColumns.INDEX_TIMESTAMP_COL_NAME:
//timestamp matches contain the millis..not the display text..just highlight if we have a match for the timestamp field
Set timestampMatches = (Set) matches.get(LoggingEventFieldResolver.TIMESTAMP_FIELD);
Expand All @@ -264,12 +264,12 @@ public Component getTableCellRendererComponent(
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
component = generalPanel;
break;
case ChainsawColumns.INDEX_METHOD_COL_NAME:
/* case ChainsawColumns.INDEX_METHOD_COL_NAME:
singleLineTextPane.setText(value.toString());
setHighlightAttributesInternal(matches.get(LoggingEventFieldResolver.METHOD_FIELD), (StyledDocument) singleLineTextPane.getDocument());
layoutRenderingPanel(generalPanel, singleLineTextPane, delta, isSelected, width, col, table);
component = generalPanel;
break;
break;*/
case ChainsawColumns.INDEX_LOG4J_MARKER_COL_NAME:
case ChainsawColumns.INDEX_MESSAGE_COL_NAME:
String thisString = value.toString().trim();
Expand Down Expand Up @@ -546,20 +546,20 @@ public void setLoggerPrecision(int loggerPrecision) {
* @return formatted object
*/
private Object formatField(Object field, LoggingEventWrapper loggingEventWrapper) {
if (!(field instanceof ZonedDateTime)) {
if (!(field instanceof Instant)) {
return (field == null ? "" : field);
}

//handle date field
if (useRelativeTimesToFixedTime) {
ZonedDateTime dt = (ZonedDateTime)field;
ZonedDateTime dt = ((Instant) field).atZone(ZoneOffset.UTC);
return "" + ChronoUnit.MILLIS.between(dt, relativeTimestampBase);
}
if (useRelativeTimesToPrevious) {
return loggingEventWrapper.getLoggingEvent().getProperty(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE);
}

return ((ZonedDateTime)field).format(DateTimeFormatter.ISO_DATE);
return dateFormatInUse.format(Date.from((Instant)field));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.log4j.chainsaw.components.logpanel;

import org.apache.commons.configuration2.event.Event;
import org.apache.commons.configuration2.event.EventListener;
import org.apache.log4j.chainsaw.*;
import org.apache.log4j.chainsaw.color.ColorPanel;
import org.apache.log4j.chainsaw.color.RuleColorizer;
Expand Down Expand Up @@ -286,13 +288,14 @@ public void windowClosing(WindowEvent e) {
new JRadioButtonMenuItem(
new AbstractAction("Use ISO8601Format") {
public void actionPerformed(ActionEvent e) {

logPanelPreferenceModel.setDateFormatPattern("ISO8601");
}
});
final JRadioButtonMenuItem simpleTimeButton =
new JRadioButtonMenuItem(
new AbstractAction("Use simple time") {
public void actionPerformed(ActionEvent e) {
logPanelPreferenceModel.setDateFormatPattern("HH:mm:ss");
}
});

Expand Down Expand Up @@ -394,30 +397,28 @@ public void actionPerformed(ActionEvent e) {
logPanelPreferenceModel.addEventListener(
evt -> {
if (evt.getPropertyName().equals(LogPanelPreferenceModel.DATE_FORMAT_TIME_ZONE)) {
LogPanelPreferenceModel model = (LogPanelPreferenceModel) evt.getSource();

isoButton.setSelected(model.isUseISO8601Format());
simpleTimeButton.setSelected(!model.isUseISO8601Format() && !model.isCustomDateFormat());
isoButton.setSelected(logPanelPreferenceModel.isUseISO8601Format());
simpleTimeButton.setSelected(!logPanelPreferenceModel.isUseISO8601Format() && !logPanelPreferenceModel.isCustomDateFormat());

if (model.getDateFormatTimeZone() != null) {
renderer.setTimeZone(model.getDateFormatTimeZone());
searchRenderer.setTimeZone(model.getDateFormatTimeZone());
if (logPanelPreferenceModel.getDateFormatTimeZone() != null) {
renderer.setTimeZone(logPanelPreferenceModel.getDateFormatTimeZone());
searchRenderer.setTimeZone(logPanelPreferenceModel.getDateFormatTimeZone());
}

if (model.isUseISO8601Format()) {
if (logPanelPreferenceModel.isUseISO8601Format()) {
renderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
searchRenderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
} else {
try {
renderer.setDateFormatter(new SimpleDateFormat(model.getDateFormatPattern()));
renderer.setDateFormatter(new SimpleDateFormat(logPanelPreferenceModel.getDateFormatPattern()));
} catch (IllegalArgumentException iae) {
model.setDefaultDatePatternFormat();
logPanelPreferenceModel.setDefaultDatePatternFormat();
renderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
}
try {
searchRenderer.setDateFormatter(new SimpleDateFormat(model.getDateFormatPattern()));
searchRenderer.setDateFormatter(new SimpleDateFormat(logPanelPreferenceModel.getDateFormatPattern()));
} catch (IllegalArgumentException iae) {
model.setDefaultDatePatternFormat();
logPanelPreferenceModel.setDefaultDatePatternFormat();
searchRenderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
}
}
Expand All @@ -430,8 +431,7 @@ public void actionPerformed(ActionEvent e) {
logPanelPreferenceModel.addEventListener(
evt -> {
if (evt.getPropertyName().equals(LogPanelPreferenceModel.CLEAR_TABLE_EXPRESSION)) {
LogPanelPreferenceModel model = (LogPanelPreferenceModel) evt.getSource();
String expression = model.getClearTableExpression();
String expression = evt.getPropertyValue().toString();
try {
clearTableExpressionRule = ExpressionRule.getRule(expression);
logger.info("clearTableExpressionRule set to: " + expression);
Expand All @@ -442,15 +442,47 @@ public void actionPerformed(ActionEvent e) {
}
});

logPanelPreferenceModel.addEventListener(evt -> {
if (!evt.isBeforeUpdate() && evt.getPropertyName().equals(LogPanelPreferenceModel.DATE_FORMAT_PATTERN) ||
evt.getPropertyName().equals(LogPanelPreferenceModel.DATE_FORMAT_TIME_ZONE)) {

isoButton.setSelected(logPanelPreferenceModel.isUseISO8601Format());
simpleTimeButton.setSelected(!logPanelPreferenceModel.isUseISO8601Format() && !logPanelPreferenceModel.isCustomDateFormat());

if (logPanelPreferenceModel.getDateFormatTimeZone() != null && !logPanelPreferenceModel.getDateFormatTimeZone().isEmpty()) {
renderer.setTimeZone(logPanelPreferenceModel.getDateFormatTimeZone());
searchRenderer.setTimeZone(logPanelPreferenceModel.getDateFormatTimeZone());
}

if (logPanelPreferenceModel.isUseISO8601Format()) {
renderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
searchRenderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
} else {
try {
renderer.setDateFormatter(new SimpleDateFormat(logPanelPreferenceModel.getDateFormatPattern()));
} catch (IllegalArgumentException iae) {
logPanelPreferenceModel.setDefaultDatePatternFormat();
renderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
}
try {
searchRenderer.setDateFormatter(new SimpleDateFormat(logPanelPreferenceModel.getDateFormatPattern()));
} catch (IllegalArgumentException iae) {
logPanelPreferenceModel.setDefaultDatePatternFormat();
searchRenderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
}
}

table.tableChanged(new TableModelEvent(tableModel));
searchTable.tableChanged(new TableModelEvent(searchModel));
}});

logPanelPreferenceModel.addEventListener(
evt -> {
if (evt.getPropertyName().equals(LogPanelPreferenceModel.LOGGER_PRECISION)) {
LogPanelPreferenceModel model = (LogPanelPreferenceModel) evt.getSource();

renderer.setLoggerPrecision(model.getLoggerPrecision());
renderer.setLoggerPrecision(logPanelPreferenceModel.getLoggerPrecision());
table.tableChanged(new TableModelEvent(tableModel));

searchRenderer.setLoggerPrecision(model.getLoggerPrecision());
searchRenderer.setLoggerPrecision(logPanelPreferenceModel.getLoggerPrecision());
searchTable.tableChanged(new TableModelEvent(searchModel));
}
});
Expand Down Expand Up @@ -3304,12 +3336,14 @@ public ThrowableDisplayMouseAdapter(JTable throwableTable, EventContainer throwa
}

public void mouseClicked(MouseEvent e) {
/*
TableColumn column = throwableTable.getColumnModel().getColumn(throwableTable.columnAtPoint(e.getPoint()));
if (!column.getHeaderValue().toString().toUpperCase().equals(ChainsawColumns.getColumnName(ChainsawColumns.INDEX_THROWABLE_COL_NAME))) {
return;
}
LoggingEventWrapper loggingEventWrapper = throwableEventContainer.getRow(throwableTable.getSelectedRow());
*/

//throwable string representation may be a length-one empty array
// String[] ti = loggingEventWrapper.getLoggingEvent().getThrowableStrRep();
Expand Down

0 comments on commit 6475b4a

Please sign in to comment.