Log4JLoggerWithProxyContext.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.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.utils.UtilsException;
  24. import org.openspcoop2.utils.logger.beans.context.core.AbstractContext;
  25. import org.openspcoop2.utils.logger.beans.context.core.BaseClient;
  26. import org.openspcoop2.utils.logger.beans.context.core.BaseServer;
  27. import org.openspcoop2.utils.logger.beans.context.proxy.ProxyContext;
  28. import org.openspcoop2.utils.logger.beans.context.proxy.ProxyTransaction;
  29. import org.openspcoop2.utils.logger.config.DiagnosticConfig;
  30. import org.openspcoop2.utils.logger.config.Log4jConfig;
  31. import org.openspcoop2.utils.logger.config.MultiLoggerConfig;

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

  40.     public Log4JLoggerWithProxyContext(MultiLoggerConfig config) throws UtilsException {
  41.         super(config);
  42.     }

  43.     public Log4JLoggerWithProxyContext(DiagnosticConfig diagnosticConfig, Log4jConfig logConfig) throws UtilsException {
  44.         super(diagnosticConfig, logConfig);
  45.     }
  46.    
  47.     @Override
  48.     protected AbstractContext newContext() {
  49.         return new ProxyContext();
  50.     }

  51.     @Override
  52.     protected BaseClient getClient() {
  53.         if(this.context==null) {
  54.             return null;
  55.         }
  56.         if(this.context instanceof ProxyContext) {
  57.             ProxyContext proxyContext = (ProxyContext) this.context;
  58.             if(proxyContext.getTransaction()!=null) {
  59.                 return ((ProxyTransaction)proxyContext.getTransaction()).getClient();
  60.             }
  61.         }
  62.         return null;
  63.     }

  64.     @Override
  65.     protected List<BaseServer> getServers() {
  66.         if(this.context==null) {
  67.             return null;
  68.         }
  69.         if(this.context instanceof ProxyContext) {
  70.             ProxyContext proxyContext = (ProxyContext) this.context;
  71.             if(proxyContext.getTransaction()!=null &&
  72.                     ((ProxyTransaction)proxyContext.getTransaction()).getServer()!=null) {
  73.                 List<BaseServer> list = new ArrayList<>();
  74.                 list.add(((ProxyTransaction)proxyContext.getTransaction()).getServer());
  75.                 return list;
  76.             }
  77.         }
  78.         return null;
  79.     }
  80.    
  81. }