Proper way to include log4j in an Eclipse 4 (RCP/SWT/OSGi) application

后端 未结 3 1677
走了就别回头了
走了就别回头了 2021-01-28 16:53

This is a follow-up (somehow of my Third-party dependencies to an OSGi application) where it was suggested that some libraries e.g. log4j are already available as bundl

相关标签:
3条回答
  • 2021-01-28 17:03

    The fragment is one option to extend the log4j bundles classpath to include the required configuration file. It is probably the simplest way of configuring application wide properties.

    This is not meant to be altered after deployment though as it will be embedded within a jar file. You will have to come up with a different approach if you expect to make it configurable after deployment.

    NOTE: I am afraid you misunderstood the answer about the jars that are already available as bundles. This does not mean that they are part of your OSGi platform of choice (Indigo), only that they are ready to be deployed to an OSGi platform as is. Your creation of a plugin project was unnecessary, you simply needed to add the jar to your target platform to resolve your missing imports.

    0 讨论(0)
  • 2021-01-28 17:15

    I suggest take a look at Pax-Logging this will give you all kinds of logging frameworks for usage in a OSGi environment. And you're able to use an external configuration file (no extender needed) to configure your logging.

    0 讨论(0)
  • 2021-01-28 17:22

    If you really need to expose the file, you could put it anywhere you want, and then make sure your program calls one of these methods at startup:

    • org.apache.log4j.xml.DOMConfigurator.configure(String filename)
    • org.apache.log4j.PropertyConfigurator.configure(String configFilename)

    Or use the "configureAndWatch"-variants if you would like to make changes to the config without restarting your application.

    Edit: I write "If you really need to", because I have experienced that I never need to turn on debug-logging after deployment, because it is always turned on! This is OK for applications where I have normal (but not extreme) requirements on response-time and throughput. Logging to an UDP-appender is fast (and does not fill up the disk). Or using rolling file appender is quite safe, and fast enough for my use. Always having the debug-log available is a life-saver when nailing down those hard-to-reproduce bugs.

    0 讨论(0)
提交回复
热议问题