Curtis Ruck | 30 Aug 02:53 2014

dynamic appender registration

I'm looking at integrating Log4j2 into a complex desktop application,
because of it's async logging implementation.  The problem I'm running into
is that I'd like to dynamically register/unregister an appender on the root
logger (or any user specified logger).  The problem though is that I can't
find any API (in core or otherwise) that would actually allow this.

--
Curtis
Michael Schall | 29 Aug 21:07 2014
Picon

Extending Appenders

I'm upgrading an application to use Log4j2.  With our existing
implementation we have created a new appender which extends the
SMTPAppender.  I see the SMTPAppender is a final class now which prevents
me from extending it.  I was wondering what the reason for this is?  Do we
really need to re-implement the the entire SMTPAppender (properties,
buffering, ...) to extend the appender?

Thanks for your time.

Mike
lb | 28 Aug 12:13 2014
Picon

Custom appender : PluginElement

I'm writing a custom appender and I have a problem setting up PluginElement:

The xml definition is the following one:

 <BinaryVanillaChronicle name="CONF-BINARY-VANILLA-CHRONICLE">

<path>${sys:java.io.tmpdir}/chronology-log4j2/conf-binary-vanilla-chronicle</path>
    <formatMessage>false</formatMessage>
    <includeCallerData>false</includeCallerData>
    <includeMappedDiagnosticContext>false</includeMappedDiagnosticContext>
    <chronicleConfig>
        <dataCacheCapacity>128</dataCacheCapacity>
    </chronicleConfig>
</BinaryVanillaChronicle>

And the PluginFactory method is:
 <at> PluginFactory
public static BinaryVanillaChronicleAppender createAppender(
     <at> PluginAttribute("name") final String name,
     <at> PluginAttribute("path") final String path,
     <at> PluginAttribute("formatMessage") final String formatMessage,
     <at> PluginAttribute("includeCallerData") final String includeCallerData,
     <at> PluginAttribute("includeMappedDiagnosticContext") final String
includeMappedDiagnosticContext,
     <at> PluginElement("chronicleConfig") final VanillaLogAppenderConfig
chronicleConfig,
     <at> PluginElement("filters") final Filter filter)

When I run it, I have the following messages:
2014-08-28 12:12:29,247 ERROR appenders contains an invalid element or
(Continue reading)

Clément Guillaume | 25 Aug 21:22 2014

Appenders

Hi,

I would love to have a direct access to the target of a ConsoleAppender (as
I can directly get the fileName of a FileAppender). Do you plan to
implement this feature ? (and also for others properties like
ConsoleAppender.isFollow or FileAppender.immediateFlush, ...)

I also would love to be able to dynamically update thess properties. I
don't think it is currently possible.
Or at least I would like to be able to replace an Appender in the
Configuration (by a new one) without removing the Appender from all the
previously associated LoggerConfig.

Regards,

Clément
Aristedes Maniatis | 24 Aug 10:31 2014
Picon

new catching syntax

Congratulations on the version 2 release. It looks great. A question though about the recommended way to
use the new 'catching syntax. We used to do this:

    catch (Exception e ) {
      logger.warn("Failed to import report: " + path, e);

But now the new lifecycle syntax has some advantages. We can do this:

    catch (Exception e ) {
      logger.catching(e);

But it would be useful for me to log the path which ultimately caused the exception. Except that I cannot do this:

    catch (Exception e ) {
      logger.catching("Failed to import report: {}", path, e);

What is the recommended approach here? Avoid the lifecycle style syntax? Call the logger twice, once with
my message and variable and once with the exception?

Thanks
Ari

--

-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
Henrik Østerlund Gram | 22 Aug 21:09 2014
Picon

plugin-registration failing

Hi,

I had been using the betas for a couple of years and everything was fine.
 But unfortunately I cannot seem to make 2.0.x work.

I have couple of plugins (converters) that are annotated properly, but the
automatic detection of these never did work and I had to use the follow
maven step to create the necessary Log4j2Plugins.dat for it to work.

<plugin> <groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version>
<executions> <execution> <phase>process-classes</phase> <goals>
<goal>java</goal> </goals> </execution> </executions> <configuration>
<mainClass>org.apache.logging.log4j.core.config.plugins.PluginManager</mainClass>
<arguments>
<argument>${project.build.directory}/../src/main/resources</argument>
<argument>my.package</argument> </arguments> </configuration> </plugin>
But since rc2 the PluginManager was disabled, and it's now seemingly
impossible to get the plugins registered. The source for PluginManager
suggests looking at the configuration page supposedly using the packages
attr to tell the framework where to scan for plugins, but again, that just
doesn't work.  I used that as well in the betas where it also did not work.

Perhaps in trivial project setups it works fine, I don't know, but I have
an ear with multiple .wars and a common single log4j2 (present in the ear's
lib where the jar for my converters is also present) and I don't know why
it cannot pick it up.

Any workarounds?  I can't understand why it should be this difficult to
register a converter.
(Continue reading)

Mariano Gonzalez | 22 Aug 19:56 2014
Picon

What's the AsyncLoggerConfig thread?

Hello,

Could you explain what's the purpose of this thread? It seems to keep on
running when my application is undeployed.

I looked at the code and it seems to be a thread responsible for
dispatching events to Disruptor, but if that's the case then the name may
not be very descriptive IMHO. Can you confirm what's the purpose of this
thread and that it should stop after the logging context receives the
stop() message?

Thanks!
Manfred Dohmen | 22 Aug 16:45 2014
Picon

log4j2 and ch.qos.logback.core.PropertyDefinerBase

Hello,

crossposting from here:
http://stackoverflow.com/q/25426738/492462

Logback's PropertyDefinerBase allows to use dynamic properties within 
logback.xml. I use this to configure a target directory for a 
FileAppender with values from my application config. In my case there's 
an enum instance that contains the value I want to use:

public String getPropertyValue() {return MyConfigEnum.LOGDIR.value();}

Relevant parts of logback.xml:

<fileNamePattern>${logdir}/test.log</fileNamePattern>

... and:

<define name="logdir" class="com.example.MyLogdirDefiner" />

This idiom is now needed for log4j 2. How can I apply the value of 
MyConfigEnum.LOGDIR in a log4j2.xml?

I don't want to set a property upon application start.

Regards!
Yogesh Rao | 22 Aug 15:27 2014
Picon

Log4j2 with SL4J Adapter

Hi,

I am trying out the API side of log4j2 with the SLF4J adaptor. With the
sample code written i couldn't see the logging being done properly. Perhaps
i am doing something wrong here.

Firstly versions of the software are :-

1. JDK 1.8.x
2. Log4j2 (2.0.1)
3. SLF4J 1.7.7
4. SLF4J's Simple Logger (1.7.7)

Code written is as under

HelloWorld.java
--------------

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class HelloWorld {

private static final Logger logger = LogManager.getLogger("HelloWorld");
    public static void main(String[] args) {
        logger.error("Hello, World!");
        logger.error("Logging in user {} with birthday {}", "Ted",
"1/10/1900");
    }

(Continue reading)

Mikael Ståldal | 20 Aug 11:17 2014

Log4j 2, ThreadContext and asynchronous servlets

Is it possible to have the ThreadContext in Log4j 2 to be request scoped
with asynchronous servlets in a Servlet 3 environment?

With asynchronous servlets, there is no direct connection between request
and thread.

--

-- 
Mikael Ståldal
Chief Software Architect
*Appear*
Phone: +46 8 545 91 572
Email: mikael.staldal <at> appearnetworks.com
Brett Delle Grazie | 19 Aug 13:25 2014
Picon

Log4j2 SyslogAppender / SyslogLayout and message format

Hi,

I'm trying to use the SyslogAppender and possibly the SyslogLayout but I
wanted to customise the message format so that some MDC parameters could be
added to the content of the message (e.g. by applying a pattern layout to
the 'message' portion).

Is there any way of achieving this? There used to be with Log4j 1.2.

I appreciate that this can be done with format 5424 but we're using BSD
format right now.

Thanks,

--

-- 
Kind regards,

Brett

Gmane