SeverityLog4J.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 org.apache.logging.log4j.Level;
  22. import org.openspcoop2.utils.logger.constants.Severity;

  23. /**
  24.  * SeverityLog4J
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */
  30. public class SeverityLog4J {


  31.     private static String getSeverityLog4JName(Severity levelStr) {
  32.         return "OP_"+levelStr.name();
  33.     }

  34.     /*
  35.      * Log4J 2.x
  36.      *
  37.      *  Standard intLevel
  38.      *    OFF         0
  39.      *    FATAL     100
  40.      *    ERROR     200
  41.      *    WARN      300
  42.      *    INFO      400
  43.      *    DEBUG     500
  44.      *    TRACE     600
  45.      *    ALL   Integer.MAX_VALUE
  46.      */
  47.    
  48.     /** Definisce un Livello di Severita' FATAL per un messaggio Diagnostico: valore Log4J = 99 */
  49.     public static final Level LOG_V2_LEVEL_FATAL =
  50.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.FATAL),99);

  51.     /** Definisce un Livello di Severita' ERROR per un messaggio Diagnostico: valore Log4J = 199 */
  52.     public static final Level LOG_V2_LEVEL_ERROR =
  53.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.ERROR),199);

  54.     /** Definisce un Livello di Severita' WARN per un messaggio Diagnostico: valore Log4J = 299 */
  55.     public static final Level LOG_V2_LEVEL_WARN =
  56.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.WARN),299);

  57.     /** Definisce un Livello di Severita' INFO per un messaggio Diagnostico: valore Log4J = 399 */
  58.     public static final Level LOG_V2_LEVEL_INFO =
  59.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.INFO),399);

  60.     /** Definisce un Livello di Severita' DEBUG-LOW per un messaggio Diagnostico: valore Log4J = 498 */
  61.     public static final Level LOG_V2_LEVEL_DEBUG_LOW =
  62.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.DEBUG_LOW),498);

  63.     /** Definisce un Livello di Severita' DEBUG-MEDIUM per un messaggio Diagnostico: valore Log4J = 499 */
  64.     public static final Level LOG_V2_LEVEL_DEBUG_MEDIUM =
  65.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.DEBUG_MEDIUM),499);

  66.     /** Definisce un Livello di Severita' DEBUG-HIGH per un messaggio Diagnostico: valore Log4J = 599 */
  67.     public static final Level LOG_V2_LEVEL_DEBUG_HIGH =
  68.             org.apache.logging.log4j.Level.forName(getSeverityLog4JName(Severity.DEBUG_HIGH),599);

  69.     public static Level getSeverityLog4J(Severity severity){
  70.                    
  71.         switch (severity) {
  72.         case FATAL:
  73.             return LOG_V2_LEVEL_FATAL;
  74.         case ERROR:
  75.             return LOG_V2_LEVEL_ERROR;
  76.         case WARN:
  77.             return LOG_V2_LEVEL_WARN;
  78.         case INFO:
  79.             return LOG_V2_LEVEL_INFO;
  80.         case DEBUG_LOW:
  81.             return LOG_V2_LEVEL_DEBUG_LOW;
  82.         case DEBUG_MEDIUM:
  83.             return LOG_V2_LEVEL_DEBUG_MEDIUM;
  84.         case DEBUG_HIGH:
  85.             return LOG_V2_LEVEL_DEBUG_HIGH;
  86.         }

  87.         return null;
  88.     }
  89. //  
  90. //  public static void log4j2(Logger log,Severity severity, String msg){
  91. //      switch (severity) {
  92. //      case FATAL:
  93. //          log.fatal(msg);
  94. //          break;
  95. //      case ERROR:
  96. //          log.error(msg);
  97. //          break;
  98. //      case WARN:
  99. //          log.warn(msg);
  100. //          break;
  101. //      case INFO:
  102. //          log.info(msg);
  103. //          break;
  104. //      case DEBUG_LOW:
  105. //          log.debug(msg);
  106. //          break;
  107. //      case DEBUG_MEDIUM:
  108. //          log.debug(msg);
  109. //          break;
  110. //      case DEBUG_HIGH:
  111. //          log.trace(msg);
  112. //          break;
  113. //      }
  114. //  }
  115.    
  116. }