سؤال

So I'm having some troubles with creating a custom log4j (1.2) appender. https://github.com/stuart-warren/logit

Basic test case: https://gist.github.com/stuart-warren/6750331

It logs over the network fine, but at the end of execution the application doesn't actually finish, I have to click terminate in Eclipse...

I'm extending the usual AppenderSkeleton that most network based appenders appear to use, but the close() method never appears to get called and hence I never destroy my socket.

It's probably something really obvious I haven't spotted, but I'm pretty new to java and after 2 days of tinkering it's getting to me.

Thanks.

Edit:

Typical, I finally work out that you have to call LogManager.shutdown(); and that calls the appenders close() method successfully.

هل كانت مفيدة؟

المحلول

Typical, I finally work out that you have to call LogManager.shutdown(); and that calls the appenders close() method successfully.

I also created a shutdown hook to close the socket if the app exit(0)s https://github.com/stuart-warren/logit/blob/master/src/main/java/com/stuartwarren/logit/log4j1/ShutdownHook.java

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top