Uploaded image for project: 'Runtime'
  1. Runtime
  2. RUNTIME-3153

[Script] Add a logger utils

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Major Major
    • 4.3.0
    • 4.2.0
    • Plugin core
    • None
    • 4.3 RC2

      var AmetysHomeHelper = Java.type('AmetysHomeHelper');    
      var PatternLayout = Java.type('org.apache.log4j.PatternLayout');    
      var FileAppender = Java.type('org.apache.log4j.FileAppender');    
      var Level = Java.type('org.apache.log4j.Level');    
      var LogManager = Java.type('org.apache.log4j.LogManager');    
      
      function createNewLogFile(category, level)    
      {       
          var logger = LogManager.getLogger(category);    
          logger.setAdditivity(false);    
          logger.setLevel(Level.toLevel(level));
          if (logger.getAppender(category) == null)  
          {    
              var filename = AmetysHomeHelper.getAmetysHome() + "/logs/" + category + ".log";    
              var layout = new PatternLayout("%d %-5p [%c] (%t;%X{requestURI}) %m%n");    
              var fileAppender = new FileAppender(layout, filename);    
              fileAppender.activateOptions(); 
              fileAppender.setName(category)    
              logger.addAppender(fileAppender);    
          }  
               
          return logger;    
      }

      Use it like this:

      var logger = createNewLogFile("script", "info");    
      logger.info("Blablabla...");

            Unassigned Unassigned
            bmaurel Bérénice Maurel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: