3 Replies Latest reply on Sep 15, 2014 9:45 AM by gmaitral

    How to get logs from UM?

    New Member

      Hi,

       

      We are trying to get UM logs to send them to our log system.

       

      We have found the LBM.setLogger(...) method, which seems very convenient to redirect logs wherever we want (log4net for instance)

      However, this does not seem to work. We never get

       

      Also, this is the ONLY method of LBM to be NOT static, which seems very, very weird. Everywhere else, we just call static methods from LBM, but for this particular purpose, we have to create a LBM instance, but we don't do anything else than just define a log callback.

       

      Here is a quick code snippet that does not work:

       

      ----------------------------

       

              /// <summary>

              /// Initializes a new instance of the Factory class.

              /// </summary>

              .ctor()

              {

                  LBM.setConfiguration(configurationFile);

       

                  // Why do we have to create a LBM instance? We only need it for setLogger? What to do with it after that?

                  var lbm = new LBM();

                  lbm.setLogger(this.LbmLogging);

              }

       

              /// <summary>

              /// Callback to LBM logs..

              /// </summary>

              /// <param name="loglevel">The log level of the message.</param>

              /// <param name="message">The message.</param>

              private void LbmLogging(int loglevel, string message)

              {

                  switch (loglevel)

                  {

                      case LBM.LOG_EMERG:

                      case LBM.LOG_ALERT:

                      case LBM.LOG_CRIT:

                      case LBM.LOG_ERR:

                          this.logger.ErrorFormat("[IUM>] {0}", message);

                          break;

                      case LBM.LOG_WARNING:

                          this.logger.WarnFormat("[IUM>] {0}", message);

                          break;

                      case LBM.LOG_NOTICE:

                      case LBM.LOG_INFO:

                          this.logger.InfoFormat("[IUM>] {0}", message);

                          break;

                      case LBM.LOG_DEBUG:

                          this.logger.DebugFormat("[IUM>] {0}", message);

                          break;

                  }

              }

       

      ----------------------------

        • 1. Re: How to get logs from UM?
          New Member

          More information : This is in UMS .NET API 6.5

          • 2. Re: How to get logs from UM?
            New Member

            Hi,

             

            I'm not exactly sure of the reason why the setLogger method is not a static method - one possible explanation is that it allows customers to create a subclass of LBM and override the default log callback that way, but this looks like a historic design decision.

             

            As for your code, I'm a little confused on exactly how you have written your example. If you take a look at this example of setting up the logging in Java (apologies I don't have a copy written in C#), you can see how the logger is overridden, but we're still creating an instance of a 3rd party logger to tie in to the callbacks:

             

            ===

            import com.latencybusters.lbm.*;

            import com.sprint.logging.Logger;

            import com.sprint.logging.SLogFactory;

             

             

            import java.io.BufferedReader;

            import java.io.IOException;

            import java.io.InputStreamReader;

             

             

            public class Pub {

                static final Logger logger = SLogFactory.getLogger(Pub.class);

             

             

                public static void main(String[] args) throws LBMException, IOException {

                    logger.info("#main Pub");

                    LBM lbm = new LBM();

                    lbm.setLogger(new LBMLogging() {

                        @Override

                        public void LBMLog(int i, String s) {

                            switch(i) {

                                case LBM.LOG_EMERG:

                                    logger.error("#LBMLog LOG_EMERG " + s);

                                    break;

                                case LBM.LOG_ALERT:

                                    logger.error("#LBMLog LOG_ALERT " + s);

                                    break;

                                case LBM.LOG_CRIT:

                                    logger.error("#LBMLog LOG_CRIT " + s);

                                    break;

                                case LBM.LOG_ERR:

                                    logger.error("#LBMLog LOG_ERR " + s);

                                    break;

                                case LBM.LOG_WARNING:

                                    logger.warn("#LBMLog LOG_WARNING " + s);

                                    break;

                                case LBM.LOG_NOTICE:

                                    logger.warn("#LBMLog LOG_NOTICE " + s);

                                    break;

                                case LBM.LOG_INFO:

                                    logger.info("#LBMLog LOG_INFO " + s);

                                    break;

                                case LBM.LOG_DEBUG:

                                    logger.info("#LBMLog LOG_DEBUG " + s);

                                    break;

                                default:

                                    logger.info("#LBMLog unrecognised level="+i + " " +s);

                                    break;

                            }

                        }

                    });

             

             

                    LBMContextAttributes lbmContextAttributes = new LBMContextAttributes();

                    LBMContext lbmContext = new LBMContext(lbmContextAttributes);

                    LBMSourceAttributes lbmSourceAttributes = new LBMSourceAttributes();

                    lbmSourceAttributes.setValue("ume_store","127.0.0.1:14567:1000");

                    lbmSourceAttributes.setValue("ume_late_join","1");

                    for(LBMConfigOption opt : lbmSourceAttributes.dumpAttributeList() ) {

                        logger.info("#main LBMSourceAttributes " + opt.getOptionName() + "=" + opt.getValue());

                    }

             

            Hope this helps.

             

            Thanks
            David

            • 3. Re: How to get logs from UM?
              New Member

              Hello,

               

              Sorry for the delay, I have not seen your reply until today.

               

              So I've made it work. The code was correct from the start, but the setLogger on the LBM was done too late, after the context creation. Now it's done before and everything is fine.

               

              What you can't see here in the code is indeed the creation of the logger. We use in house interface, allowing us to not have dependencies over third party log systems (but in the end, we use log4net). I thought the creation of the logger was not relevant, so I did not include it in the code extract

               

              Thanks for your reply