Closed SaucyWrong closed 9 years ago
This method is probably not yet supported since I have never tested it out. The wrapping of a socket appender in an asynchronous appender is supported though.
Can you share your log4j2.xml?
Sure thing--I'm using the yml config format and it looks something like this (I deleted certain things that weren't relevant, such as the root logger, which is just a normal RollingRandomAccessFile appender:
%YAML 1.1
---
Configuration:
appenders:
appender:
- type: Socket
name: SOCKET
host: localhost
port: 4560
immediateFail: true
immediateFlush: true
loggers:
root:
level: warn
AppenderRef:
- ref: ROOT_LOG
logger:
- name: com.foo.bar.MyClass
level: ALL
additivity: false
AppenderRef:
- ref: SOCKET
You'll notice that these appenders and loggers look normal--there is nothing in the config file to indicate that they are asynchronous.
Instead, I supply the following JVM property at runtime:
-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
This tells log4j2 that it should use the Disruptor to asynchronously handle all logging activity. It would seem that this requires the disruptor jar to be present on the classpath for both the program doing the logging and the program that is acting as the log4j2 server (your plugin, in this case).
Incidentally, it appears that adding the necessary jar and then requiring it in the Ruby code does allow the plugin to successfully handle asynchronous loggers. I'm sure you'll want to test this yourself, but this appears to work for me.
Here is the code change I made to the plugin in my environment:
begin
vendor_dir = ::File.expand_path("../../../vendor/", ::File.dirname(__FILE__))
require File.join(vendor_dir, "log4j-api-2.1.jar")
require File.join(vendor_dir, "log4j-core-2.1.jar")
require File.join(vendor_dir, "disruptor-3.3.0.jar")
And I obtained the disruptor jar from http://search.maven.org/#artifactdetails%7Ccom.lmax%7Cdisruptor%7C3.3.0%7Cjar
I don't believe any other changes to the plugin are required--I think this jar is just needed by log4j2 so if a message comes in the disruptor format it can unwrap it properly.
I have released 5.0 with the fix you mentioned. Does it work for you? If confirmed I will close this issue. Thanks for all the help!
This fix works for me. Thanks for the great plugin!
You are welcome! Thanks for reporting this issue! If you encounter any problems or have any suggestions please report them :smile:
Using release 4.0 of this excellent plugin, it appears that the disruptor jar used by log4j when using globally-asyn loggers as documented here: http://logging.apache.org/log4j/2.x/manual/async.html#AllAsync
the plugin complains that it can't find a class when I attempt to ship it a log using an asynchronous socket appender:
The disruptor jar seems to be required when you work with the asynchronous loggers using the -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.
The concept of asynchronous loggers is new in Log4j2 and is different from wrapping a socket appender with an asynchronous appender.
I tried manually placing the jar in the vendor subfolder of the plugin, but that did not do anything. Is this method of shipping logs to your plugin supported?