<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Display log4j Messages in Runtime Log</title><link>https://answers.axonivy.com/questions/3466/display-log4j-messages-in-runtime-log</link><description>&lt;p&gt;Is it possible, to configure Logging so that log4j messages from other modules, (like Hibernate) are shown directly in the Designer Runtime Log?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3466/display-log4j-messages-in-runtime-log" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 02 Oct 2018 09:38:28 -0400</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/3466/display-log4j-messages-in-runtime-log/3467</link><description>&lt;p&gt;Hi Peter&lt;/p&gt;
&lt;p&gt;You could use the following Utility class to forward log message from one Logger to another one. E.e. from the Hibernate Logger to the Runtime Log (ivy.log)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Priority;
import org.apache.log4j.spi.LoggingEvent;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.log.Logger;

public class LogUtil
{
    private static class ForwardAppender extends AppenderSkeleton 
    {
        public static final String NAME = ForwardAppender.class.getSimpleName();
        private Logger to;

        @SuppressWarnings("deprecation")
        public ForwardAppender(Logger to) {
            this.to = to;
            setName(NAME);
        }

        @Override
        public void close() {
        }

        @Override
        public boolean requiresLayout() {
            return false;
        }

        @Override
        protected void append(LoggingEvent event) {
            if (event.getThrowableInformation() != null)
            {
                to.log(event.getLevel(), event.getMessage(), event.getThrowableInformation().getThrowable());
            }
            else
            {
                to.log(event.getLevel(), event.getMessage());
            }
        }
    }

    public static void forwardLoggerToLogger(Logger from, Logger to)
    {
        if (from.getAppender(ForwardAppender.NAME)==null)
        {
            from.addAppender(new ForwardAppender(to));
        }
    }

    public static void main(String[] args) 
    {
        // Example 
        Logger hibernate = Logger.getLogger("org.hibernate");
        Logger runtimeLog = Ivy.log();
        forwardLoggerToLogger(hibernate, runtimeLog);
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Tue, 02 Oct 2018 09:38:28 -0400</pubDate><guid>https://answers.axonivy.com/questions/3466/display-log4j-messages-in-runtime-log/3467</guid></item></channel></rss>