   DECLARE APPENDERS CURSOR FOR
     SELECT APPENDER_ID, CONFIGURATION
     FROM CONF_APPENDERS;
+  DECLARE CONTINUE HANDLER FOR SQLSTATE '55019'
+    INSERT INTO LOGS (LEVEL_ID, LOGGER_ID, ENVIRONMENT, MESSAGE) VALUES 
+    (1, 0, CURRENT USER, 'Appender not available');
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET AT_END = TRUE;
+
   -- Retrieves the current level in the configuration for the given logger.
   SELECT C.LEVEL_ID INTO CURRENT_LEVEL_ID 
     FROM CONF_LOGGERS_EFFECTIVE C
-    WHERE C.LOGGER_ID = LOGGER_ID;
-    
+    WHERE C.LOGGER_ID = LOGGER_ID
+    FETCH FIRST 1 ROW ONLY;
+
   -- Checks if the current level is at least equal to the provided level.
   -- TODO Verificar esto, ya que aqu se puede usar la tabla references, si root
   -- no est activo.

  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_LOG_SQL: BEGIN
  INSERT INTO LOGS (DATE, LEVEL_ID, LOGGER_ID, ENVIRONMENT, MESSAGE) VALUES
    (CURRENT TIMESTAMP, LEVEL_ID, LOGGER_ID, CURRENT USER, MESSAGE); 
 END P_LOG_SQL@
ALTER MODULE LOGGER PUBLISH 
  PROCEDURE LOG_DB2DIAG (

  END IF;
END P_LOG@

/**
 * Logs a message at debug (5) level.
 *
 * IN LOGGER_ID
 *   This is the associated logger of the provided message.
 * IN MESSAGE
 *   Message to log.
 */
ALTER MODULE LOGGER ADD 
  PROCEDURE DEBUG (
  IN LOGGER_ID ANCHOR CONF_LOGGERS.LOGGER_ID,
  IN MESSAGE ANCHOR LOGS.MESSAGE)
  SPECIFIC P_DEBUG
  LANGUAGE SQL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_DEBUG: BEGIN
  CALL LOG (LOGGER_ID, 5, MESSAGE);
 END P_DEBUG@

/**
 * Logs a message at info (4) level.
 *
 * IN LOGGER_ID
 *   This is the associated logger of the provided message.
 * IN MESSAGE
 *   Message to log.
 */
ALTER MODULE LOGGER ADD 
  PROCEDURE INFO (
  IN LOGGER_ID ANCHOR CONF_LOGGERS.LOGGER_ID,
  IN MESSAGE ANCHOR LOGS.MESSAGE)
  SPECIFIC P_INFO
  LANGUAGE SQL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_INFO: BEGIN
  CALL LOG (LOGGER_ID, 4, MESSAGE);
 END P_INFO@

/**
 * Logs a message at warn (3) level.
 *
 * IN LOGGER_ID
 *   This is the associated logger of the provided message.
 * IN MESSAGE
 *   Message to log.
 */
ALTER MODULE LOGGER ADD 
  PROCEDURE WARN (
  IN LOGGER_ID ANCHOR CONF_LOGGERS.LOGGER_ID,
  IN MESSAGE ANCHOR LOGS.MESSAGE)
  SPECIFIC P_WARN
  LANGUAGE SQL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_WARN: BEGIN
  CALL LOG (LOGGER_ID, 3, MESSAGE);
 END P_WARN@

/**
 * Logs a message at error (2) level.
 *
 * IN LOGGER_ID
 *   This is the associated logger of the provided message.
 * IN MESSAGE
 *   Message to log.
 */
ALTER MODULE LOGGER ADD 
  PROCEDURE ERROR (
  IN LOGGER_ID ANCHOR CONF_LOGGERS.LOGGER_ID,
  IN MESSAGE ANCHOR LOGS.MESSAGE)
  SPECIFIC P_ERROR
  LANGUAGE SQL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_ERROR: BEGIN
  CALL LOG (LOGGER_ID, 2, MESSAGE);
 END P_ERROR@

/**
 * Logs a message at fatal (1) level.
 *
 * IN LOGGER_ID
 *   This is the associated logger of the provided message.
 * IN MESSAGE
 *   Message to log.
 */
ALTER MODULE LOGGER ADD 
  PROCEDURE FATAL (
  IN LOGGER_ID ANCHOR CONF_LOGGERS.LOGGER_ID,
  IN MESSAGE ANCHOR LOGS.MESSAGE)
  SPECIFIC P_FATAL
  LANGUAGE SQL
  NOT DETERMINISTIC
  NO EXTERNAL ACTION
  MODIFIES SQL DATA
 P_FATAL: BEGIN
  CALL LOG (LOGGER_ID, 1, MESSAGE);
 END P_FATAL@

