Adding a Logback appender

3,435 views
Skip to first unread message

Tom Hubina

unread,
May 8, 2014, 10:08:06 PM5/8/14
to dropwiz...@googlegroups.com
Since Dropwizard doesn't use the logback.xml, I'm trying to figure out how to add an appender to my project. Specifically I want to add:


I'm not seeing anyway to add appenders with the logging section of the yml. How do I add this?

Thanks!

Tom

Jochen Schalanda

unread,
May 9, 2014, 4:23:12 AM5/9/14
to dropwiz...@googlegroups.com
Hi Tom,

On 09.05.2014 04:08, Tom Hubina wrote:
> I'm not seeing anyway to add appenders with the logging section of the
> yml. How do I add this?

You'll need to implement an AppenderFactory [1] (or
AbstractAppenderFactory [2] for that matter) which is enriched by some
Jackson annotations. You don't need to register your custom
AppenderFactory as it will be found by classpath scanning.

See ConsoleAppenderFactory [3] for a simple example.


[1]:
https://joschi.github.io/dropwizard/0.7.0/dropwizard-logging/apidocs/io/dropwizard/logging/AppenderFactory.html
[2]:
https://joschi.github.io/dropwizard/0.7.0/dropwizard-logging/apidocs/io/dropwizard/logging/AbstractAppenderFactory.html
[3]:
https://github.com/dropwizard/dropwizard/blob/v0.7.0/dropwizard-logging/src/main/java/io/dropwizard/logging/ConsoleAppenderFactory.java


Cheers,
Jochen

Tim Carey-Smith

unread,
May 9, 2014, 1:48:07 AM5/9/14
to dropwiz...@googlegroups.com
You’ll need to make a new FooAppenderFactory and configure it inside your config-file.

I have an example which I have been using:
https://github.com/dropwizard/dropwizard/issues/496#issuecomment-37977508

Cheers,
Tim

Tom Hubina

unread,
May 9, 2014, 2:14:18 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
Can anyone explain to me why Dropwizard took such a simple and functional thing like adding appenders to Logback and made it a complete mess? I mean, there must be some value add here .. but for the life of me it makes no sense.

Tom

Tatu Saloranta

unread,
May 9, 2014, 2:20:00 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
I am guessing that the specific use case was not needed by implementors at the time. If it was, there'd be simpler way to do it.

Which also means that if you can figure out better way, implement it & contribute, you could help simplify this so it wouldn't be a mess? :)

-+ Tatu +-


--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Hubina

unread,
May 9, 2014, 2:31:30 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
I don't need to find a better way. Logback worked just fine until Dropwizard broke it.

I'm going to work on it and I'm sure I'll figure it out, but at first glance what used to be as simple as adding a few lines to the logback.xml now requires:
1. Creating a factory method to provide an appender
2. Figuring out how to tell Dropwizard about the factory.
3. Figuring out how to construct the third party appender in the first place since the docs all assume everyone is going to use logback.xml

My question is, why did Dropwizard break it? I mean, there must be some really cool value that was added in order to balance out the added work I get to go through right now? A bit of google shows this issue first came up back in 0.3 - so there must be some reason to continue going down this path.

Tom

Tatu Saloranta

unread,
May 9, 2014, 2:33:39 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
You seem awfully certain that this was some kind of nefarious intentional act of sabotage... if it broke in 0.3 and _NOBODY CARED ENOUGH TO FIX IT_ then... gee.

-+ Tatu +-

Christopher Elkins

unread,
May 9, 2014, 2:51:44 PM5/9/14
to dropwiz...@googlegroups.com
On May 9, 2014, at 11:31 AM, Tom Hubina <t...@spicemouse.com> wrote:

I don't need to find a better way. Logback worked just fine until Dropwizard broke it.

I'm going to work on it and I'm sure I'll figure it out, but at first glance what used to be as simple as adding a few lines to the logback.xml now requires:
1. Creating a factory method to provide an appender
2. Figuring out how to tell Dropwizard about the factory.
3. Figuring out how to construct the third party appender in the first place since the docs all assume everyone is going to use logback.xml

My question is, why did Dropwizard break it? I mean, there must be some really cool value that was added in order to balance out the added work I get to go through right now? A bit of google shows this issue first came up back in 0.3 - so there must be some reason to continue going down this path.

It’s pretty simple really:

1. Dropwizard prefers (immutable) programmatic configuration.
2. Dropwizard prefers a single configuration file to directives spread across multiple files.
3. Dropwizard makes it possible to circumvent those preferences, albeit sometimes in a less than optimal way.

-- 
Christopher Elkins

Tom Hubina

unread,
May 9, 2014, 2:51:48 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
I don't know about nefarious but it isn't broken accidentally and requiring a fix that no one cares enough to do. It's intentionally disabled. The "fix" would be to remove something that was intentionally done, which seems counter productive and presumptuous. I'm just asking why it was done and what I'm missing. If you don't know, then please let someone else answer.

Tom

Tatu Saloranta

unread,
May 9, 2014, 2:57:18 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
On Fri, May 9, 2014 at 11:51 AM, Tom Hubina <t...@spicemouse.com> wrote:
I don't know about nefarious but it isn't broken accidentally and requiring a fix that no one cares enough to do. It's intentionally disabled. The "fix" would be to remove something that was intentionally done, which seems counter productive and presumptuous. I'm just asking why it was done and what I'm missing. If you don't know, then please let someone else answer.


How was it explicitly disabled? Configuration settings have changed over time, and 0.3 is a long time ago. By "not caring" I am specifically referring to your saying that "it was working in 0.3" [but not since then]. If someone did care, this would have been discussed, perhaps changed earlier.
Not moving some part of configurability over is not explicit disabling; perhaps it was done intentionally, perhaps not. But you chose to assume one way.

Be that as it may. I just don't like the sense of entitlement I am hearing, accusatory tone. Asking this:


"Can anyone explain to me why Dropwizard took such a simple and functional thing like adding appenders to Logback and made it a complete mess?"

sounds like just the thing to get unhelpful responses.

And yes, I will let others handle your questions from now on.

-+ Tatu +-

Tom Hubina

unread,
May 9, 2014, 4:14:32 PM5/9/14
to dropwiz...@googlegroups.com
Thanks for explanation. Sounds like this is one of those less than optimal ways, but maybe it's getting a bit better?

I saw one post where someone had a list of appenders in the yml and specifically mentions this being possible in 0.7, but I don't see that in the 0.7.0 that I have. Is it on a branch somewhere or something?

and

I'm guessing you wouldn't be able to add a new appender this way, but it's how you would configure an appender you added in code? What is the direction this is going?

Tom

Matt Brown

unread,
May 9, 2014, 4:57:01 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
It might help to understand the original purpose of Dropwizard - to combine together a number of different libraries and to provide a *simplified* way to create new services for engineers at Yammer. It was literally intended to be the glue code to build services there in a standardized way.

From that perspective, it makes sense why a number of configuration options that were never used in that environment were not exposed, and why certain standardized practices were hard-coded.

Whether or not that same goal makes sense for an open-source library is subjective, but the best way to get things added back is always to submit a patch.

Tom Hubina

unread,
May 9, 2014, 5:24:40 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
Yup. Given the design goals that Christopher mentioned I think a short, "This is how you add an appender" tutorial would be better than a patch.

Tom

Tom Hubina

unread,
May 9, 2014, 5:27:02 PM5/9/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
I've written the AbstractAppenderFactory but build() isn't being called. Are you sure it will be found with classpath scanning? The docs say:

add a META-INF/services/io.dropwizard.logging.AppenderFactory file with your implementation's full class name to the class path

What does that mean?

Tom

On Friday, May 9, 2014 1:23:12 AM UTC-7, Jochen Schalanda wrote:

Justin Rudd

unread,
May 9, 2014, 6:36:00 PM5/9/14
to dropwiz...@googlegroups.com
I don't have an answer to your specific problem, but I just submitted this PR to allow for logging configuration via "out of the box" Logback facilities...


I tried it out on a couple of apps that I have as well as the dropwizard-example module. It works as expected with both logback.xml and logback.groovy. Love it if some people would eyeball it. And I can throw it on the dropwizard-dev@ as well if that is preferred.


--

Tom Hubina

unread,
May 9, 2014, 6:53:39 PM5/9/14
to dropwiz...@googlegroups.com
Ok. Figured out a big source of my confusion on this stuff. I recently changed my pom to use 0.7.0 instead 0.6.2 and for whatever reason both version were still co-existing and causing me a huge ton of confusion. I've ripped out 0.6.2 manually and am in the process of migrating my code over to 0.7.0. Hopefully when I'm done adding the logback appender will be a lot less confusing ;)

Tom

Jochen Schalanda

unread,
May 10, 2014, 5:14:28 AM5/10/14
to dropwiz...@googlegroups.com
On 09.05.2014 23:27, Tom Hubina wrote:
> I've written the AbstractAppenderFactory but build() isn't being called.
> Are you sure it will be found with classpath scanning? The docs say:

It's not (only) classpath scanning as I mentioned in my previous mail,
sorry. Dropwizard 0.7.x is using the standard SPI mechanism [1] of Java.

This means that you have to create a file named
META-INF/services/io.dropwizard.logging.AppenderFactory in your
resources directory which contains the fully qualified name of your
concrete implementation of (Abstract)AppenderFactory.

For the example I mentioned in my last mail (ConsoleAppenderFactory)
this can be found in the sources of dropwizard-logging [2].


[1]: http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
[2]:
https://github.com/dropwizard/dropwizard/blob/v0.7.0/dropwizard-logging/src/main/resources/META-INF/services/io.dropwizard.logging.AppenderFactory


Cheers,
Jochen

Tom Hubina

unread,
May 10, 2014, 1:36:33 PM5/10/14
to dropwiz...@googlegroups.com, joc...@schalanda.name
Thanks! I didn't really understand what the docs meant by that, but I found another project for adding an appender and that cleared it up for me.


It's a good sample to start from since the only thing it does is add an appender and there's very few files to dig through.

Of course most of my confusion was caused by having both 0.6.2 and 0.7.0 in the same project. Maven + IntelliJ + changing the package names from 0.6.2 to 0.7.0 did a number on my project that I didn't catch for longer than I'd care to admit ;)

Tom

Cory Bradshaw

unread,
Sep 4, 2015, 10:44:28 AM9/4/15
to dropwizard-user, joc...@schalanda.name
I've been able to add a custom appender for Logging Events, but how would I do this for AccessEvents? In short, I am wanting to get dropwizard access logs to a custom logging service.

Any help would be appreciated.
Reply all
Reply to author
Forward
0 new messages