SemaphoreLogEventGenerator.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.semaphore;

  21. import java.sql.Connection;
  22. import java.text.SimpleDateFormat;

  23. import org.openspcoop2.utils.date.DateUtils;
  24. import org.slf4j.Logger;

  25. /**
  26.  * SemaphoreLogEventGenerator
  27.  *
  28.  * @author Andrea Poli (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class SemaphoreLogEventGenerator implements ISemaphoreEventGenerator {

  33.     private Logger log;
  34.    
  35.     public SemaphoreLogEventGenerator(Logger log) {
  36.         this.log = log;
  37.     }
  38.    
  39.     @Override
  40.     public void emitEvent(Connection con, SemaphoreEvent event) {
  41.         SimpleDateFormat dateformat = DateUtils.getSimpleDateFormatMs();
  42.         String msg =
  43.                 "["+event.getSeverity()+"] ["+event.getOperationType()+"] Date["+dateformat.format(event.getDate())+"] IdNode["+event.getIdNode()+"] [Lock:"+event.isLock()+"]: "+event.getDetails();
  44.         switch (event.getSeverity()) {
  45.         case DEBUG:
  46.             this.log.debug(msg);
  47.             break;
  48.         case INFO:
  49.             this.log.info(msg);
  50.             break;
  51.         case WARN:
  52.             this.log.warn(msg);
  53.             break;
  54.         case ERROR:
  55.             this.log.error(msg);
  56.             break;
  57.         }
  58.     }
  59. }