ChangeD: Error log window shows last 100 log entries (instead of first 100)

This commit is contained in:
Jindra Petřík
2025-07-02 20:52:47 +02:00
parent 752b242c58
commit 6375f69b3e
2 changed files with 109 additions and 102 deletions

View File

@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Icon of "Deobfuscation options" menu from pile of pills to medkit
- Error log window shows last 100 log entries (instead of first 100)
## [24.0.1] - 2025-06-27
### Fixed

View File

@@ -277,122 +277,128 @@ public class ErrorLogFrame extends AppFrame {
}
}
private void log(final Level level, final String msg, final String detail) {
if (logItemCount.getAndIncrement() < MAX_LOG_ITEM_COUNT) {
View.execInEventDispatchLater(() -> {
notifyMainFrame(level);
private void log(final Level level, final String msg, final String detail) {
View.execInEventDispatchLater(() -> {
if (logItemCount.getAndIncrement() > MAX_LOG_ITEM_COUNT) {
logHistory.remove(0);
if (logViewInner != null) {
logViewInner.remove(0);
}
}
notifyMainFrame(level);
JPanel pan = new JPanel();
JPanel pan = new JPanel();
if (View.isOceanic()) {
pan.setBackground(Color.white);
}
pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
JComponent detailComponent;
if (detail == null) {
detailComponent = null;
} else {
final JTextArea detailTextArea = new JTextArea(detail);
detailTextArea.setEditable(false);
detailTextArea.setOpaque(false);
detailTextArea.setFont(new JLabel().getFont());
if (View.isOceanic()) {
pan.setBackground(Color.white);
detailTextArea.setBackground(Color.white);
}
pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
detailComponent = detailTextArea;
}
JPanel header = new JPanel();
header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
if (View.isOceanic()) {
header.setBackground(Color.white);
}
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
final String dateStr = format.format(new Date());
final String logEntry = dateStr + " " + level.toString() + " " + msg + "\r\n" + detail;
JComponent detailComponent;
if (detail == null) {
detailComponent = null;
} else {
final JTextArea detailTextArea = new JTextArea(detail);
detailTextArea.setEditable(false);
detailTextArea.setOpaque(false);
detailTextArea.setFont(new JLabel().getFont());
if (View.isOceanic()) {
detailTextArea.setBackground(Color.white);
}
detailComponent = detailTextArea;
JToggleButton copyButton = new JToggleButton(View.getIcon("copy16"));
copyButton.setFocusPainted(false);
copyButton.setBorderPainted(false);
copyButton.setFocusable(false);
copyButton.setContentAreaFilled(false);
copyButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
copyButton.setMargin(new Insets(2, 2, 2, 2));
copyButton.setToolTipText(translate("copy"));
copyButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringSelection = new StringSelection(logEntry);
clipboard.setContents(stringSelection, null);
}
JPanel header = new JPanel();
header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
if (View.isOceanic()) {
header.setBackground(Color.white);
}
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
final String dateStr = format.format(new Date());
final String logEntry = dateStr + " " + level.toString() + " " + msg + "\r\n" + detail;
});
logHistory.add(logEntry);
JToggleButton copyButton = new JToggleButton(View.getIcon("copy16"));
copyButton.setFocusPainted(false);
copyButton.setBorderPainted(false);
copyButton.setFocusable(false);
copyButton.setContentAreaFilled(false);
copyButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
copyButton.setMargin(new Insets(2, 2, 2, 2));
copyButton.setToolTipText(translate("copy"));
copyButton.addActionListener(new ActionListener() {
final JToggleButton expandButton = new JToggleButton(collapseIcon);
expandButton.setFocusPainted(false);
expandButton.setBorderPainted(false);
expandButton.setFocusable(false);
expandButton.setContentAreaFilled(false);
expandButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
expandButton.setMargin(new Insets(2, 2, 2, 2));
expandButton.setToolTipText(translate("details"));
final JPanel detailPanel;
if (detailComponent != null) {
detailPanel = new JPanel(new BorderLayout());
detailPanel.add(detailComponent, BorderLayout.CENTER);
detailPanel.setAlignmentX(0f);
} else {
detailPanel = null;
}
if (detailComponent != null) {
expandButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringSelection = new StringSelection(logEntry);
clipboard.setContents(stringSelection, null);
expandButton.setIcon(expandButton.isSelected() ? expandIcon : collapseIcon);
detailPanel.setVisible(expandButton.isSelected());
revalidate();
repaint();
}
});
logHistory.add(logEntry);
}
final JToggleButton expandButton = new JToggleButton(collapseIcon);
expandButton.setFocusPainted(false);
expandButton.setBorderPainted(false);
expandButton.setFocusable(false);
expandButton.setContentAreaFilled(false);
expandButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
expandButton.setMargin(new Insets(2, 2, 2, 2));
expandButton.setToolTipText(translate("details"));
if (detailComponent != null) {
header.add(expandButton);
}
JLabel dateLabel = new JLabel(dateStr);
dateLabel.setPreferredSize(new Dimension(200, (int) dateLabel.getPreferredSize().getHeight()));
dateLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(dateLabel);
final JPanel detailPanel;
if (detailComponent != null) {
detailPanel = new JPanel(new BorderLayout());
detailPanel.add(detailComponent, BorderLayout.CENTER);
detailPanel.setAlignmentX(0f);
} else {
detailPanel = null;
}
JLabel levelLabel = new JLabel(level.getName());
levelLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(levelLabel);
JTextArea msgLabel = new JTextArea(msg);
msgLabel.setEditable(false);
msgLabel.setOpaque(false);
msgLabel.setFont(levelLabel.getFont());
if (detailComponent != null) {
expandButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
expandButton.setIcon(expandButton.isSelected() ? expandIcon : collapseIcon);
detailPanel.setVisible(expandButton.isSelected());
revalidate();
repaint();
}
});
}
msgLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(msgLabel);
header.setAlignmentX(0f);
if (detailComponent != null) {
header.add(expandButton);
}
JLabel dateLabel = new JLabel(dateStr);
dateLabel.setPreferredSize(new Dimension(200, (int) dateLabel.getPreferredSize().getHeight()));
dateLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(dateLabel);
JLabel levelLabel = new JLabel(level.getName());
levelLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(levelLabel);
JTextArea msgLabel = new JTextArea(msg);
msgLabel.setEditable(false);
msgLabel.setOpaque(false);
msgLabel.setFont(levelLabel.getFont());
msgLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
header.add(msgLabel);
header.setAlignmentX(0f);
header.add(copyButton);
pan.add(header);
if (detailComponent != null) {
pan.add(detailPanel);
detailPanel.setVisible(false);
}
pan.setAlignmentX(0f);
if (logViewInner != null) { //may be disposed or what? #1904
logViewInner.add(pan);
}
saveToFileButton.setEnabled(true);
revalidate();
repaint();
});
}
header.add(copyButton);
pan.add(header);
if (detailComponent != null) {
pan.add(detailPanel);
detailPanel.setVisible(false);
}
pan.setAlignmentX(0f);
if (logViewInner != null) { //may be disposed or what? #1904
logViewInner.add(pan);
}
saveToFileButton.setEnabled(true);
revalidate();
repaint();
});
}
public void log(Level level, String msg) {