Пример #1
0
 /**
  * Set the {@link ErrorHandler} for this Appender.
  *
  * @since 0.9.0
  */
 public synchronized void setErrorHandler(ErrorHandler eh) {
   if (eh == null) {
     // We do not throw exception here since the cause is probably a
     // bad config file.
     LogLog.warn("You have tried to set a null error-handler.");
   } else {
     this.errorHandler = eh;
   }
 }
Пример #2
0
 /**
  * Gets the editing context to use for creating mail messages in.
  *
  * @return editing context with a no-op delegate set.
  */
 public EOEditingContext editingContext() {
   if (editingContext == null) {
     if (!hasCooperatingObjectStores()) {
       LogLog.warn(
           "Creating editing context for the ERCMailMessageAppender before any cooperating object stores have been added.");
     }
     editingContext = new EOEditingContext();
     editingContext.setDelegate(_delegate);
   }
   return editingContext;
 }
Пример #3
0
 /* 136:    */
 /* 137:    */ public synchronized void setErrorHandler(ErrorHandler eh) /* 138:    */ {
   /* 139:271 */ if (eh == null)
   /* 140:    */ {
     /* 141:272 */ LogLog.warn("You have tried to set a null error-handler.");
     /* 142:    */ }
   /* 143:    */ else
   /* 144:    */ {
     /* 145:274 */ this.errorHandler = eh;
     /* 146:275 */ if (this.qw != null) {
       /* 147:276 */ this.qw.setErrorHandler(eh);
       /* 148:    */ }
     /* 149:    */ }
   /* 150:    */ }
Пример #4
0
 /* 101:    */
 /* 102:    */ protected OutputStreamWriter createWriter(OutputStream os) /* 103:    */ {
   /* 104:236 */ OutputStreamWriter retval = null;
   /* 105:    */
   /* 106:238 */ String enc = getEncoding();
   /* 107:239 */ if (enc != null) {
     /* 108:    */ try
     /* 109:    */ {
       /* 110:241 */ retval = new OutputStreamWriter(os, enc);
       /* 111:    */ }
     /* 112:    */ catch (IOException e)
     /* 113:    */ {
       /* 114:243 */ if ((e instanceof InterruptedIOException)) {
         /* 115:244 */ Thread.currentThread().interrupt();
         /* 116:    */ }
       /* 117:246 */ LogLog.warn("Error initializing output writer.");
       /* 118:247 */ LogLog.warn("Unsupported encoding?");
       /* 119:    */ }
     /* 120:    */ }
   /* 121:250 */ if (retval == null) {
     /* 122:251 */ retval = new OutputStreamWriter(os);
     /* 123:    */ }
   /* 124:253 */ return retval;
   /* 125:    */ }
Пример #5
0
 /*
  * (non-Javadoc)
  *
  * @see org.apache.log4j.appender.AppenderCommand#execute(org.apache.log4j.Appender)
  */
 public final void execute(final Appender appender, final LoggingEvent event) {
   try {
     appender.doAppend(event);
   } catch (RuntimeException e) {
     if (this.shouldThrow()) {
       throw e;
     } else {
       this.errors = true;
       LogLog.warn(
           Thread.currentThread().getName()
               + " recovered from fault during LoggingEvent dispatch - events may have been lost",
           e);
     }
   }
 }
  /** This method must work for the root category as well. */
  void parseCategory(
      Properties props, Logger logger, String optionKey, String loggerName, String value) {

    LogLog.debug("Parsing for [" + loggerName + "] with value=[" + value + "].");
    // We must skip over ',' but not white space
    StringTokenizer st = new StringTokenizer(value, ",");

    // If value is not in the form ", appender.." or "", then we should set
    // the level of the loggeregory.

    if (!(value.startsWith(",") || value.equals(""))) {

      // just to be on the safe side...
      if (!st.hasMoreTokens()) return;

      String levelStr = st.nextToken();
      LogLog.debug("Level token is [" + levelStr + "].");

      // If the level value is inherited, set category level value to
      // null. We also check that the user has not specified inherited for the
      // root category.
      if (INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
        if (loggerName.equals(INTERNAL_ROOT_NAME)) {
          LogLog.warn("The root logger cannot be set to null.");
        } else {
          logger.setLevel(null);
        }
      } else {
        logger.setLevel(OptionConverter.toLevel(levelStr, (Level) Level.DEBUG));
      }
      LogLog.debug("Category " + loggerName + " set to " + logger.getLevel());
    }

    // Begin by removing all existing appenders.
    logger.removeAllAppenders();

    Appender appender;
    String appenderName;
    while (st.hasMoreTokens()) {
      appenderName = st.nextToken().trim();
      if (appenderName == null || appenderName.equals(",")) continue;
      LogLog.debug("Parsing appender named \"" + appenderName + "\".");
      appender = parseAppender(props, appenderName);
      if (appender != null) {
        logger.addAppender(appender);
      }
    }
  }
Пример #7
0
 /*  53:    */
 /*  54:    */ protected boolean checkEntryConditions() /*  55:    */ {
   /*  56:173 */ if (this.closed)
   /*  57:    */ {
     /*  58:174 */ LogLog.warn("Not allowed to write to a closed appender.");
     /*  59:175 */ return false;
     /*  60:    */ }
   /*  61:178 */ if (this.qw == null)
   /*  62:    */ {
     /*  63:179 */ this.errorHandler.error(
         "No output stream or file set for the appender named [" + this.name + "].");
     /*  64:    */
     /*  65:181 */ return false;
     /*  66:    */ }
   /*  67:184 */ if (this.layout == null)
   /*  68:    */ {
     /*  69:185 */ this.errorHandler.error(
         "No layout set for the appender named [" + this.name + "].");
     /*  70:186 */ return false;
     /*  71:    */ }
   /*  72:188 */ return true;
   /*  73:    */ }
  /**
   * Read configuration options from <code>properties</code>.
   *
   * <p>See {@link #doConfigure(String, LoggerRepository)} for the expected format.
   */
  public void doConfigure(Properties properties, LoggerRepository hierarchy) {
    repository = hierarchy;
    String value = properties.getProperty(LogLog.DEBUG_KEY);
    if (value == null) {
      value = properties.getProperty("log4j.configDebug");
      if (value != null)
        LogLog.warn("[log4j.configDebug] is deprecated. Use [log4j.debug] instead.");
    }

    if (value != null) {
      LogLog.setInternalDebugging(OptionConverter.toBoolean(value, true));
    }

    //
    //   if log4j.reset=true then
    //        reset hierarchy
    String reset = properties.getProperty(RESET_KEY);
    if (reset != null && OptionConverter.toBoolean(reset, false)) {
      hierarchy.resetConfiguration();
    }

    String thresholdStr = OptionConverter.findAndSubst(THRESHOLD_PREFIX, properties);
    if (thresholdStr != null) {
      hierarchy.setThreshold(OptionConverter.toLevel(thresholdStr, (Level) Level.ALL));
      LogLog.debug("Hierarchy threshold set to [" + hierarchy.getThreshold() + "].");
    }

    configureRootCategory(properties, hierarchy);
    configureLoggerFactory(properties);
    parseCatsAndRenderers(properties, hierarchy);

    LogLog.debug("Finished configuring.");
    // We don't want to hold references to appenders preventing their
    // garbage collection.
    registry.clear();
  }
Пример #9
0
 void printPeriodicity(int type) {
   switch (type) {
     case TOP_OF_MINUTE:
       LogLog.debug("Appender [" + name + "] to be rolled every minute.");
       break;
     case TOP_OF_HOUR:
       LogLog.debug("Appender [" + name + "] to be rolled on top of every hour.");
       break;
     case HALF_DAY:
       LogLog.debug("Appender [" + name + "] to be rolled at midday and midnight.");
       break;
     case TOP_OF_DAY:
       LogLog.debug("Appender [" + name + "] to be rolled at midnight.");
       break;
     case TOP_OF_WEEK:
       LogLog.debug("Appender [" + name + "] to be rolled at start of week.");
       break;
     case TOP_OF_MONTH:
       LogLog.debug("Appender [" + name + "] to be rolled at start of every month.");
       break;
     default:
       LogLog.warn("Unknown periodicity for appender [" + name + "].");
   }
 }
 void targetWarn(String val) {
   LogLog.warn("[" + val + "] should be System.out or System.err.");
   LogLog.warn("Using previously set target, System.out by default.");
 }
Пример #11
0
  void parseAppenderFilters(Properties props, String appenderName, Appender appender) {
    // extract filters and filter options from props into a hashtable mapping
    // the property name defining the filter class to a list of pre-parsed
    // name-value pairs associated to that filter
    final String filterPrefix = APPENDER_PREFIX + appenderName + ".filter.";
    int fIdx = filterPrefix.length();
    Hashtable filters = new Hashtable();
    Enumeration e = props.keys();
    String name = "";
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      if (key.startsWith(filterPrefix)) {
        int dotIdx = key.indexOf('.', fIdx);
        String filterKey = key;
        if (dotIdx != -1) {
          filterKey = key.substring(0, dotIdx);
          name = key.substring(dotIdx + 1);
        }
        Vector filterOpts = (Vector) filters.get(filterKey);
        if (filterOpts == null) {
          filterOpts = new Vector();
          filters.put(filterKey, filterOpts);
        }
        if (dotIdx != -1) {
          String value = OptionConverter.findAndSubst(key, props);
          filterOpts.add(new NameValue(name, value));
        }
      }
    }

    // sort filters by IDs, insantiate filters, set filter options,
    // add filters to the appender
    Enumeration g = new SortedKeyEnumeration(filters);
    while (g.hasMoreElements()) {
      String key = (String) g.nextElement();
      String clazz = props.getProperty(key);
      if (clazz != null) {
        LogLog.debug(
            "Filter key: ["
                + key
                + "] class: ["
                + props.getProperty(key)
                + "] props: "
                + filters.get(key));
        Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz, Filter.class, null);
        if (filter != null) {
          PropertySetter propSetter = new PropertySetter(filter);
          Vector v = (Vector) filters.get(key);
          Enumeration filterProps = v.elements();
          while (filterProps.hasMoreElements()) {
            NameValue kv = (NameValue) filterProps.nextElement();
            propSetter.setProperty(kv.key, kv.value);
          }
          propSetter.activate();
          LogLog.debug(
              "Adding filter of type ["
                  + filter.getClass()
                  + "] to appender named ["
                  + appender.getName()
                  + "].");
          appender.addFilter(filter);
        }
      } else {
        LogLog.warn("Missing class definition for filter: [" + key + "]");
      }
    }
  }
Пример #12
0
  protected void append(LoggingEvent event) {
    Connection connection = null;
    try {
      connection = connectionSource.getConnection();
      connection.setAutoCommit(false);

      PreparedStatement insertStatement;
      if (cnxSupportsGetGeneratedKeys) {
        insertStatement = connection.prepareStatement(insertSQL, Statement.RETURN_GENERATED_KEYS);
      } else {
        insertStatement = connection.prepareStatement(insertSQL);
      }

      /*          insertStatement.setLong(1, event.getSequenceNumber());*/
      insertStatement.setLong(1, 0);

      insertStatement.setLong(2, event.getTimeStamp());
      insertStatement.setString(3, event.getRenderedMessage());
      insertStatement.setString(4, event.getLoggerName());
      insertStatement.setString(5, event.getLevel().toString());
      insertStatement.setString(6, event.getNDC());
      insertStatement.setString(7, event.getThreadName());
      insertStatement.setShort(8, DBHelper.computeReferenceMask(event));

      LocationInfo li;

      if (event.locationInformationExists() || locationInfo) {
        li = event.getLocationInformation();
      } else {
        li = LocationInfo.NA_LOCATION_INFO;
      }

      insertStatement.setString(9, li.getFileName());
      insertStatement.setString(10, li.getClassName());
      insertStatement.setString(11, li.getMethodName());
      insertStatement.setString(12, li.getLineNumber());

      int updateCount = insertStatement.executeUpdate();
      if (updateCount != 1) {
        LogLog.warn("Failed to insert loggingEvent");
      }

      ResultSet rs = null;
      Statement idStatement = null;
      boolean gotGeneratedKeys = false;
      if (cnxSupportsGetGeneratedKeys) {
        try {
          rs = (ResultSet) GET_GENERATED_KEYS_METHOD.invoke(insertStatement, null);
          gotGeneratedKeys = true;
        } catch (InvocationTargetException ex) {
          Throwable target = ex.getTargetException();
          if (target instanceof SQLException) {
            throw (SQLException) target;
          }
          throw ex;
        } catch (IllegalAccessException ex) {
          LogLog.warn("IllegalAccessException invoking PreparedStatement.getGeneratedKeys", ex);
        }
      }

      if (!gotGeneratedKeys) {
        insertStatement.close();
        insertStatement = null;

        idStatement = connection.createStatement();
        idStatement.setMaxRows(1);
        rs = idStatement.executeQuery(sqlDialect.getSelectInsertId());
      }

      // A ResultSet cursor is initially positioned before the first row; the
      // first call to the method next makes the first row the current row
      rs.next();
      int eventId = rs.getInt(1);

      rs.close();

      // we no longer need the insertStatement
      if (insertStatement != null) {
        insertStatement.close();
        insertStatement = null;
      }

      if (idStatement != null) {
        idStatement.close();
        idStatement = null;
      }

      Set propertiesKeys = event.getPropertyKeySet();

      if (propertiesKeys.size() > 0) {
        PreparedStatement insertPropertiesStatement =
            connection.prepareStatement(insertPropertiesSQL);

        for (Iterator i = propertiesKeys.iterator(); i.hasNext(); ) {
          String key = (String) i.next();
          String value = event.getProperty(key);

          // LogLog.info("id " + eventId + ", key " + key + ", value " + value);
          insertPropertiesStatement.setInt(1, eventId);
          insertPropertiesStatement.setString(2, key);
          insertPropertiesStatement.setString(3, value);

          if (cnxSupportsBatchUpdates) {
            insertPropertiesStatement.addBatch();
          } else {
            insertPropertiesStatement.execute();
          }
        }

        if (cnxSupportsBatchUpdates) {
          insertPropertiesStatement.executeBatch();
        }

        insertPropertiesStatement.close();
        insertPropertiesStatement = null;
      }

      String[] strRep = event.getThrowableStrRep();

      if (strRep != null) {
        LogLog.debug("Logging an exception");

        PreparedStatement insertExceptionStatement =
            connection.prepareStatement(insertExceptionSQL);

        for (short i = 0; i < strRep.length; i++) {
          insertExceptionStatement.setInt(1, eventId);
          insertExceptionStatement.setShort(2, i);
          insertExceptionStatement.setString(3, strRep[i]);
          if (cnxSupportsBatchUpdates) {
            insertExceptionStatement.addBatch();
          } else {
            insertExceptionStatement.execute();
          }
        }
        if (cnxSupportsBatchUpdates) {
          insertExceptionStatement.executeBatch();
        }
        insertExceptionStatement.close();
        insertExceptionStatement = null;
      }

      connection.commit();
    } catch (Throwable sqle) {
      LogLog.error("problem appending event", sqle);
    } finally {
      DBHelper.closeConnection(connection);
    }
  }