Announcement Announcement Module
Collapse
No announcement yet.
ch.qos.logback.classic.net.SMTPAppender Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ch.qos.logback.classic.net.SMTPAppender

    Has anyone been able to ge ch.qos.logback.classic.net.SMTPAppender working? According to http://static.springsource.org/s2-dm...serviceability...

    ... [you] have the complete range of Logback's appenders available for your use.
    Here is my entire config/serviceability.xml

    Code:
    <configuration>
            <appender name="EMAILER" class="ch.qos.logback.classic.net.SMTPAppender">
                <SMTPHost>smtp.example.org</SMTPHost>
                    <To>me@exam[email protected]</To>
                    <From>[email protected]</From>
                    <layout class="ch.qos.logback.classic.PatternLayout">
                            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %msg %ex%n</Pattern>
                    </layout> 
         </appender>
            <appender name="LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
                    <file>serviceability/logs/log.log</file>
                    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                            <FileNamePattern>serviceability/logs/log_%i.log</FileNamePattern>
                            <MinIndex>1</MinIndex>
                            <MaxIndex>4</MaxIndex>
                    </rollingPolicy>
                    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                            <MaxFileSize>10MB</MaxFileSize>
                    </triggeringPolicy>
                    <layout class="ch.qos.logback.classic.PatternLayout">
                            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %msg %ex%n</Pattern>
                    </layout>
            </appender>
    
            <appender name="EVENT_LOG_STDOUT" class="com.springsource.osgi.medic.log.logback.ReroutingAwareConsoleAppender">
                    <layout class="ch.qos.logback.classic.PatternLayout">
                            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %msg %ex%n</Pattern>
                    </layout>
            </appender>
    
            <root level="WARN">
                    <appender-ref ref="LOG_FILE" />
            </root>
    
           <logger level="DEBUG" additivity="false" name="org.example">
                    <appender-ref ref="EVENT_LOG_STDOUT" />
                    <appender-ref ref="EMAILER" />
            </logger>
    
    </configuration>
    but on startup I get the following error:

    Code:
    com.springsource.osgi.medic.log.impl.logback.LoggerContextConfigurationFailedException: Configuration failed with the following problems: [Could not create an Appender of type [ch.qos.logback.classic.net.SMTPAppender]., ActionException in Action for tag [appender], Could not find an appender named [EMAILER]. Did you define it below in the config file?, See http://logback.qos.ch/codes.html#appender_order for more details.]
    	at com.springsource.osgi.medic.log.impl.logback.JoranLoggerContextConfigurer.reportFailureIfNecessary(JoranLoggerContextConfigurer.java:55)
    	at com.springsource.osgi.medic.log.impl.logback.JoranLoggerContextConfigurer.applyConfiguration(JoranLoggerContextConfigurer.java:47)
    	at com.springsource.osgi.medic.log.impl.logback.StandardContextSelectorDelegate.configureDefaultContext(StandardContextSelectorDelegate.java:138)
    	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.configureDefaultContextIfNecessary(DelegatingContextSelector.java:46)
    	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.setDefaultLoggerContext(DelegatingContextSelector.java:39)
    	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.<init>(DelegatingContextSelector.java:34)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.slf4j.impl.StaticLoggerBinder.dynamicalContextSelector(StaticLoggerBinder.java:139)
    	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:105)
    	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:60)
    	at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
    	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
    	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
    	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
    	at com.springsource.osgi.medic.log.impl.LoggingPrintStreamWrapper.<init>(LoggingPrintStreamWrapper.java:73)
    	at com.springsource.osgi.medic.impl.MedicActivator.wrapPrintStream(MedicActivator.java:190)
    	at com.springsource.osgi.medic.impl.MedicActivator.logStart(MedicActivator.java:178)
    	at com.springsource.osgi.medic.impl.MedicActivator.start(MedicActivator.java:112)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
    	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
    	at com.springsource.osgi.launcher.FrameworkBuilder.installAndStartBundles(FrameworkBuilder.java:178)
    	at com.springsource.osgi.launcher.FrameworkBuilder.start(FrameworkBuilder.java:160)
    	at com.springsource.osgi.launcher.Launcher.main(Launcher.java:58)
    com.springsource.osgi.medic.log.impl.logback.LoggerContextConfigurationFailedException: Configuration failed with the following problems: [Could not create an Appender of type [ch.qos.logback.classic.net.SMTPAppender]., ActionException in Action for tag [appender], Could not find an appender named [EMAILER]. Did you define it below in the config file?, See http://logback.qos.ch/codes.html#appender_order for more details.]
    	at com.springsource.osgi.medic.log.impl.logback.JoranLoggerContextConfigurer.reportFailureIfNecessary(JoranLoggerContextConfigurer.java:55)
    	at com.springsource.osgi.medic.log.impl.logback.JoranLoggerContextConfigurer.applyConfiguration(JoranLoggerContextConfigurer.java:47)
    	at com.springsource.osgi.medic.log.impl.logback.StandardContextSelectorDelegate.createConfiguredContext(StandardContextSelectorDelegate.java:118)
    	at com.springsource.osgi.medic.log.impl.logback.StandardContextSelectorDelegate.getLoggerContext(StandardContextSelectorDelegate.java:99)
    	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.getLoggerContext(DelegatingContextSelector.java:74)
    	at org.slf4j.impl.StaticLoggerBinder.getLoggerFactory(StaticLoggerBinder.java:151)
    	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:280)
    	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
    	at com.springsource.osgi.medic.log.impl.LoggingPrintStreamWrapper.<init>(LoggingPrintStreamWrapper.java:73)
    	at com.springsource.osgi.medic.impl.MedicActivator.wrapPrintStream(MedicActivator.java:190)
    	at com.springsource.osgi.medic.impl.MedicActivator.logStart(MedicActivator.java:178)
    	at com.springsource.osgi.medic.impl.MedicActivator.start(MedicActivator.java:112)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
    	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
    	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
    	at com.springsource.osgi.launcher.FrameworkBuilder.installAndStartBundles(FrameworkBuilder.java:178)
    	at com.springsource.osgi.launcher.FrameworkBuilder.start(FrameworkBuilder.java:160)
    	at com.springsource.osgi.launcher.Launcher.main(Launcher.java:58)
    Using 2.0.0.RELEASE with Java 1.6 on Linux. We would really love to be able to have errors emailed to us via logback. Any help would be appreciated.

  • #2
    It looks like there is a problem with the appender element, so try putting a breakpoint in LogBack's AppenderAction class at its begin method as a starting point for debugging.

    Good luck and please post back here if you find anything interesting.

    Comment


    • #3
      hi glyn

      configuring logback with debug=true (in configuration tag of servicability.xml) the state of logback is reported as follows.

      the problem is a cnfe (javax.mail.Multipart). in my setup a bundle exporting the package and containing the class is available in repository/ext-directory.

      Code:
      09:34:30,390 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [ch.qos.logback.classic.net.SMTPAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.net.SMTPAppender
      	at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.classic.net.SMTPAppender
      	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:53)
      	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:31)
      	at 	at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:54)
      	at 	at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
      	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:143)
      	at 	at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:125)
      	at 	at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:40)
      	at 	at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:328)
      	at 	at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
      	at 	at com.springsource.osgi.medic.log.impl.logback.JoranLoggerContextConfigurer.applyConfiguration(JoranLoggerContextConfigurer.java:39)
      	at 	at com.springsource.osgi.medic.log.impl.logback.StandardContextSelectorDelegate.configureDefaultContext(StandardContextSelectorDelegate.java:138)
      	at 	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.configureDefaultContextIfNecessary(DelegatingContextSelector.java:46)
      	at 	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.setDefaultLoggerContext(DelegatingContextSelector.java:39)
      	at 	at com.springsource.osgi.medic.log.impl.logback.DelegatingContextSelector.<init>(DelegatingContextSelector.java:34)
      	at 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      	at 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      	at 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      	at 	at org.slf4j.impl.StaticLoggerBinder.dynamicalContextSelector(StaticLoggerBinder.java:139)
      	at 	at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:105)
      	at 	at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:60)
      	at 	at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
      	at 	at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
      	at 	at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
      	at 	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
      	at 	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
      	at 	at com.springsource.osgi.medic.log.impl.LoggingPrintStreamWrapper.<init>(LoggingPrintStreamWrapper.java:73)
      	at 	at com.springsource.osgi.medic.impl.MedicActivator.wrapPrintStream(MedicActivator.java:190)
      	at 	at com.springsource.osgi.medic.impl.MedicActivator.logStart(MedicActivator.java:178)
      	at 	at com.springsource.osgi.medic.impl.MedicActivator.start(MedicActivator.java:112)
      	at 	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
      	at 	at java.security.AccessController.doPrivileged(Native Method)
      	at 	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
      	at 	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
      	at 	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:352)
      	at 	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:280)
      	at 	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:272)
      	at 	at com.springsource.osgi.launcher.FrameworkBuilder.installAndStartBundles(FrameworkBuilder.java:178)
      	at 	at com.springsource.osgi.launcher.FrameworkBuilder.start(FrameworkBuilder.java:160)
      	at 	at com.springsource.osgi.launcher.Launcher.main(Launcher.java:58)
      Caused by: java.lang.NoClassDefFoundError: javax/mail/Multipart
      	at 	at java.lang.Class.getDeclaredConstructors0(Native Method)
      	at 	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
      	at 	at java.lang.Class.getConstructor0(Class.java:2699)
      	at 	at java.lang.Class.newInstance0(Class.java:326)
      	at 	at java.lang.Class.newInstance(Class.java:308)
      	at 	at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:49)
      	at 	... 39 common frames omitted
      Caused by: java.lang.ClassNotFoundException: javax.mail.Multipart

      Comment


      • #4
        Logback is packaged inside the medic core bundle which does not import the package javax.mail. You need to add an import for javax.mail to the medic core bundle. Since this is specific to your application of medic, it would not be appropriate to modify the manifest of medic core directly. But you can add an import by defining a fragment of medic core which contains just that import. Please see if that works.

        Comment


        • #5
          In dm-kernel 2.0.2 the medic core bundle already imports the javax.mail package optionally, so no fragment has to be created.

          I got logback configuring the smtp appender correctly by

          - copying javax.mail bundle to lib/kernel and
          - registering it in lib/com.springsource.kernel.launch.properties

          New problems appear when the appender wants to send the first message.

          It's very strange... The root of failure is a NoSuchMethodException in javax.mail.Session class raised on the lower line:
          Code:
          Class[] c = {javax.mail.Session.class, javax.mail.URLName.class};
          Constructor cons = serviceClass.getConstructor(c);
          I'm pretty sure this is an osgi class loading issue, because, obviously, this constructor exists...

          Similar behaviour when I want to print logback state with
          Code:
          LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
          StatusPrinter.print(lc);
          a ClassCastException is thrown (cannot cast LoggerContext to LoggerContext )...

          Another strange thing is, that when having the debug=true flag set in the serviceability.xml root tag the logback status report is printed twice and with other timestamps. Could it be that there are two logger contexts instantiated that interfere with each other?

          Comment


          • #6
            I have come across reflection bugs in the Sun JRE before which assume the class loaders are arranged as a hierarchy, which isn't the case with OSGi, so you may have hit one of those. IIRC the reflection code keeps some caches which do not work correctly with OSGi. That was some years ago though and such bugs may have been fixed, but it's a possible line of investigation. You can probably get a bit further by debugging into the failing reflection code and seeing which class loaders it is using.

            As for the duplicate logging contexts you are quite right. This was a bug in the medic component which was fixed (the fix was backported from Virgo) in dm Server 2.0.3, which shipped yesterday.

            Please note that active development on dm Server has stopped and Eclipse Virgo is the replacement, in case you hadn't noticed. You may like to migrate to Virgo and discuss your problems on the Virgo forum where a larger community is present and others may have seen and solved your problem.

            Comment

            Working...
            X