LoggerManager.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.monitor.engine.config;

  21. import org.openspcoop2.monitor.engine.constants.CostantiConfigurazione;

  22. import java.io.File;
  23. import java.io.FileInputStream;
  24. import java.io.InputStream;
  25. import java.util.Properties;

  26. import org.slf4j.Logger;
  27. import org.openspcoop2.utils.LoggerWrapperFactory;

  28. /**
  29.  * LoggerManager
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class LoggerManager {

  36.     private static Logger logger = LoggerWrapperFactory.getLogger(LoggerManager.class);
  37.    
  38.     private static boolean initialized = false;
  39.     public static void initLogger(){
  40.         if(LoggerManager.initialized==false){
  41.             InputStream is = null;
  42.             Properties config = null;
  43.             try {
  44.                 File f = new File(CostantiConfigurazione.LOG4J_FILENAME);
  45.                 if(f.exists()){
  46.                     is = new FileInputStream(f);
  47.                 }
  48.                 else {
  49.                     f = new File("deploy"+File.separatorChar+"properties",CostantiConfigurazione.LOG4J_FILENAME);
  50.                     if(f.exists()){
  51.                         is = new FileInputStream(f);
  52.                     }
  53.                     else{
  54.                         //
  55.                         is = LoggerManager.class.getResourceAsStream("/"+CostantiConfigurazione.LOG4J_FILENAME);
  56.                         if(is==null){
  57.                             throw new Exception("Configurazione del framework ["+CostantiConfigurazione.LOG4J_FILENAME+"] non trovata");
  58.                         }
  59.                     }
  60.                 }
  61.                
  62.                 config = new Properties();
  63.                 config.load(is);
  64.                 LoggerWrapperFactory.setLogConfiguration(config);
  65.                
  66.                 LoggerManager.logger.info("Sistema di logging correttamente inizializzato");
  67.                 LoggerManager.initialized = true;
  68.                
  69.             } catch (Exception e) {
  70.                 LoggerManager.logger.error("Errore durante l'inizializzazione del Sistema di Logging: "+e.getMessage(),e);
  71.             }finally{
  72.                 try{
  73.                     if(is!=null)
  74.                         is.close();
  75.                 }catch(Exception eClose){
  76.                     // close
  77.                 }
  78.             }
  79.         }
  80.     }
  81.    
  82.     static{
  83.         LoggerManager.initLogger();
  84.     }
  85.    
  86. }