0

I've developed a dropwizard application using v0.9.2. Is it possible to use log4j's SocketAppender in the configuration YML? Directly specifying a type 'socket' doesn't work:

Failed to parse configuration at: logging.appenders.[1]; Could not resolve type id 'socket' into a subtype of [simple type, class io.dropwizard.logging.AppenderFactory]: known type ids = [AppenderFactory, console, file, syslog]

Any guidance would be much appreciated if someone has already done something of this sort :)

ragebiswas
  • 3,818
  • 9
  • 38
  • 39

1 Answers1

1

Yes it is. I have answered this similarly before here: Dropwizard doesn't log custom loggers to file

Essentially what your problem is, is that dropwizard does not know about the factory for logging you want to use. So you need to do tell DW about it.

  1. create a new factory that implements AppenderFactory.
  2. Implement that factory to return an SocketAppender or whatever appender you want to use.
  3. Your class needs to be annotated with @JsonProperty (see HostnameFileAppender in my linked answer)
  4. You need to add a Resource in META-INF/services called: io.dropwizard.logging.AppenderFactory
  5. That text file you need to add your full classname (bla.bla.bla.MyAppenderFactory)

Now DW knows about this class. You can now use the name you gave your class in the annotation in your yml file for configuration. DW will automatically resolve that to the correct Factory class and create the appender you want.

I hope that helps, let me know if you need more help.

Artur

Community
  • 1
  • 1
pandaadb
  • 6,306
  • 2
  • 22
  • 41