Log4jLoggerWithApplicationContext.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.utils.logger.log4j;

  21. import java.util.List;

  22. import org.openspcoop2.utils.UtilsException;
  23. import org.openspcoop2.utils.logger.beans.context.application.ApplicationContext;
  24. import org.openspcoop2.utils.logger.beans.context.application.ApplicationTransaction;
  25. import org.openspcoop2.utils.logger.beans.context.core.AbstractContext;
  26. import org.openspcoop2.utils.logger.beans.context.core.BaseClient;
  27. import org.openspcoop2.utils.logger.beans.context.core.BaseServer;
  28. import org.openspcoop2.utils.logger.config.DiagnosticConfig;
  29. import org.openspcoop2.utils.logger.config.Log4jConfig;
  30. import org.openspcoop2.utils.logger.config.MultiLoggerConfig;

  31. /**
  32.  * Log4jLoggerWithApplicationContext
  33.  *
  34.  * @author Andrea Poli (apoli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class Log4jLoggerWithApplicationContext extends AbstractLog4JLoggerWithContext  {

  39.     public Log4jLoggerWithApplicationContext(MultiLoggerConfig config) throws UtilsException {
  40.         super(config);
  41.     }

  42.     public Log4jLoggerWithApplicationContext(DiagnosticConfig diagnosticConfig, Log4jConfig logConfig) throws UtilsException {
  43.         super(diagnosticConfig, logConfig);
  44.     }

  45.     @Override
  46.     protected AbstractContext newContext() {
  47.         return new ApplicationContext();
  48.     }

  49.     @Override
  50.     protected BaseClient getClient() {
  51.         if(this.context==null) {
  52.             return null;
  53.         }
  54.         if(this.context instanceof ApplicationContext) {
  55.             ApplicationContext appContext = (ApplicationContext) this.context;
  56.             if(appContext.getTransaction()!=null) {
  57.                 return ((ApplicationTransaction)appContext.getTransaction()).getClient();
  58.             }
  59.         }
  60.         return null;
  61.     }

  62.     @Override
  63.     protected List<BaseServer> getServers() {
  64.         if(this.context==null) {
  65.             return null;
  66.         }
  67.         if(this.context instanceof ApplicationContext) {
  68.             ApplicationContext appContext = (ApplicationContext) this.context;
  69.             if(appContext.getTransaction()!=null) {
  70.                 return ((ApplicationTransaction)appContext.getTransaction()).getServers();
  71.             }
  72.         }
  73.         return null;
  74.     }
  75.    
  76.    
  77. }