Skip to content

Commit

Permalink
PDFBOX-5695: fixed DebugLogAppender not being initialised and runtime…
Browse files Browse the repository at this point in the history
… exceptions in LogDialog, by Axel Howind

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1913576 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Nov 4, 2023
1 parent fdf26ce commit 9eebb95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.*;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;

import java.io.Serializable;

@Plugin(name = "DebugLogAppender", category = "Core", elementType = "appender", printObject = true)
public class DebugLogAppender extends AbstractAppender
{
protected DebugLogAppender(String name, Filter filter, Layout<? extends Serializable> layout,
Expand All @@ -34,6 +39,14 @@ protected DebugLogAppender(String name, Filter filter, Layout<? extends Serializ
super(name, filter, layout, ignoreExceptions);
}

@PluginFactory
public static DebugLogAppender createAppender(@PluginAttribute("name") String name,
@PluginElement("Filter") Filter filter,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginAttribute("ignoreExceptions") boolean ignoreExceptions) {
return new DebugLogAppender(name, filter, layout, ignoreExceptions);
}

@Override
public void append(LogEvent event)
{
Expand All @@ -53,7 +66,7 @@ public static void setupCustomLogger()
"%d [%t] %-5level: %msg%n%throwable"));
builder.add(appenderBuilder);

appenderBuilder = builder.newAppender("Custom", "org.package.CustomAppender");
appenderBuilder = builder.newAppender("Custom", "DebugLogAppender");
appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern",
"%d [%t] %-5level: %msg%n%throwable"));
builder.add(appenderBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,37 @@ public void log(String name, String level, Object o, Throwable throwable)
SimpleAttributeSet levelStyle = new SimpleAttributeSet();
switch (level)
{
case "fatal":
case "FATAL":
levelText = "Fatal";
StyleConstants.setForeground(levelStyle, Color.WHITE);
StyleConstants.setBackground(levelStyle, Color.BLACK);
fatalCount++;
break;
case "error":
case "ERROR":
levelText = "Error";
StyleConstants.setForeground(levelStyle, new Color(0xFF291F));
StyleConstants.setBackground(levelStyle, new Color(0xFFF0F0));
errorCount++;
break;
case "warn":
case "WARN":
levelText = "Warning";
StyleConstants.setForeground(levelStyle, new Color(0x614201));
StyleConstants.setBackground(levelStyle, new Color(0xFFFCE5));
warnCount++;
break;
case "info":
case "INFO":
levelText = "Info";
StyleConstants.setForeground(levelStyle, new Color(0x203261));
StyleConstants.setBackground(levelStyle, new Color(0xE2E8FF));
otherCount++;
break;
case "debug":
case "DEBUG":
levelText = "Debug";
StyleConstants.setForeground(levelStyle, new Color(0x32612E));
StyleConstants.setBackground(levelStyle, new Color(0xF4FFEC));
otherCount++;
break;
case "trace":
case "TRACE":
levelText = "Trace";
StyleConstants.setForeground(levelStyle, new Color(0x64438D));
StyleConstants.setBackground(levelStyle, new Color(0xFEF3FF));
Expand Down

0 comments on commit 9eebb95

Please sign in to comment.