Package org.apache.log4j

Examples of org.apache.log4j.Appender


  }

  public static FileAppender getFileAppender(String name, LoggerRepository repository) {
      Set allAppenders = getAllAppenders(repository);
    for (Object allAppender : allAppenders) {
      Appender appender = (Appender) allAppender;
      if (appender instanceof FileAppender) {
        FileAppender fileAppender = (FileAppender) appender;
        if (fileAppender.getName() != null
            && fileAppender.getName().equals(name)) {
          return fileAppender;
View Full Code Here


  }

  private LogMessage[] getLogsForKey(String keyword) {
    int DEFAULT_NO_OF_LOGS = 100;
    int definedAmount;
    Appender appender = Logger.getRootLogger().getAppender(
        LoggingConstants.WSO2CARBON_MEMORY_APPENDER);
    if (appender instanceof MemoryAppender) {
      MemoryAppender memoryAppender = (MemoryAppender) appender;
      if ((memoryAppender.getCircularQueue() != null)) {
        definedAmount = memoryAppender.getBufferSize();
View Full Code Here

  }

  private LogMessage[] getLogsForType(String type) {
    int DEFAULT_NO_OF_LOGS = 100;
    int definedAmount;
    Appender appender = Logger.getRootLogger().getAppender(
        LoggingConstants.WSO2CARBON_MEMORY_APPENDER);
    if (appender instanceof MemoryAppender) {
      MemoryAppender memoryAppender = (MemoryAppender) appender;
      if ((memoryAppender.getCircularQueue() != null)) {
        definedAmount = memoryAppender.getBufferSize();
View Full Code Here

  }

  private LogMessage[] getLogsMessages() throws AxisFault {
    int DEFAULT_NO_OF_LOGS = 100;
    int definedamount;
    Appender appender = Logger.getRootLogger().getAppender(
        LoggingConstants.WSO2CARBON_MEMORY_APPENDER);
    PatternLayout tt;
    if (appender instanceof MemoryAppender) {
      MemoryAppender memoryAppender = (MemoryAppender) appender;
      if ((memoryAppender.getCircularQueue() != null)) {
View Full Code Here

     * @param appenderName The name of the appender
     * @return The appender information the given appender with name <code>appenderName</code>
     */
    public AppenderData getAppenderData(String appenderName) {
        Logger rootLogger = Logger.getRootLogger();
        Appender targetAppender;
        if (appenderName == null || appenderName.length() == 0) {
            targetAppender = getTheFirstAppenderInLogger(rootLogger);
        } else {
            targetAppender = getAppenderInLoggerWithName(rootLogger, appenderName);
        }
View Full Code Here

            Logger logger = (Logger) loggers.nextElement();
            if (logger.getLevel() != null) {
                addAppendersToSet(logger.getAllAppenders(), appenderSet);
            }
        }
        Appender appender = null;
        for (Iterator<Appender> iter = appenderSet.iterator(); iter.hasNext();) {
            appender = iter.next();
            if (appender.getName().equals(appenderName)) {
                break;
            }
        }

        if (appender != null) {
            if (appender instanceof FileAppender) {
                isFileAppender = true;
            } else if (appender instanceof SyslogAppender) {
                isSysLogAppender = true;
            }

            //Registry operations are performed before updating the actual appender in the memory
            if (isFileAppender) {
              //TODO add syslogPattern to  appenderPattern
              appenderPattern = addSyslogPattern(appenderPattern);
                // Check if the file is valid
                logFileName = logFileName.replace('\\', '/');
                File logFile = new File(logFileName);
                if (!logFile.isAbsolute()) {
                    if (logFileName.startsWith("./")) {
                        logFileName = logFileName.substring(2);
                    }
                    logFileName = (System.getProperty(ServerConstants.CARBON_HOME) + "/" +
                            logFileName).replace('\\', '/');
                    logFile = new File(logFileName);
                }
                if (!logFile.exists()) {
                    int lastIndex = logFileName.lastIndexOf("/");
                    String msg = "Cannot create logfile " + logFileName +
                            ". Please verify that the logging directory exists, log file name is " +
                            "valid and that you have read-write access to this file.";
                    if (lastIndex != -1) {
                        String dirName = logFileName.substring(0, lastIndex);
                        File dir = new File(dirName);
                        if (!dir.exists() && !dir.mkdirs()) {
                            throw new Exception(msg);
                        }
                    }
                    try {
                        if (!logFile.createNewFile()) {
                            throw new Exception(msg);
                        }
                    } catch (IOException e) {
                        throw new Exception(msg);
                    }
                }
                if (persist) {
                    registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
                            logFileName, null, null, true, false);
                }
            } else if (isSysLogAppender) {
                if (persist) {
                    registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
                            null, sysLogHost, facility, false, true);
                }
            } else {
                if (persist) {
                    registryManager.updateAppender(appender, appenderName, appenderPattern, threshold,
                            null, null, null, false, false);
                }
            }

            if ((appender.getLayout() != null) &&
                    (appender.getLayout() instanceof PatternLayout)) {
                ((PatternLayout) appender.getLayout()).setConversionPattern(appenderPattern);
            }

            if (appender instanceof FileAppender) {

                ((FileAppender) appender).setFile(logFileName);
                if (LoggingAdmin.log.isDebugEnabled()) {
                    LoggingAdmin.log.debug("change the logfile of the appender ==> " +
                            appender.getName() + " to " + logFileName);
                }
                ((FileAppender) appender).activateOptions();
            }

            if (appender instanceof SyslogAppender) {
View Full Code Here

        // update the appender data stored in the registry
        Collection appenderCollection = registryManager.getAppenders();
        if (appenderCollection != null) {
            String[] appenderResourcePaths = appenderCollection.getChildren();
            for (String appenderResourcePath : appenderResourcePaths) {
                Appender appender = LoggingUtil.getAppenderFromSet(appenderSet, appenderResourcePath.substring(
                        LoggingConstants.APPENDERS.length()));
                Resource appenderResource = registryManager.getAppender(appenderResourcePath);
                if (appenderResource != null && appender != null) {
                    if (appender instanceof AppenderSkeleton) {
                        appenderResource.setProperty(LoggingConstants.AppenderProperties.THRESHOLD, logLevel);
View Full Code Here

                });
        return appenderDataArray;
    }

    private void addAppendersToSet(Enumeration appenders, Set<Appender> appenderSet) {
        Appender appender;
        while (appenders.hasMoreElements()) {
            appender = (Appender) appenders.nextElement();
            appenderSet.add(appender);
            if (LoggingAdmin.log.isDebugEnabled()) {
                LoggingAdmin.log.debug("Add appender ==> " + appender.getName() + " to appender set");
            }
        }
    }
View Full Code Here

        return appenderData;
    }

    private Appender getAppenderInLoggerWithName(Logger logger, String appenderName) {
        Enumeration appenders = logger.getAllAppenders();
        Appender targetAppender = null;
        while (appenders.hasMoreElements()) {
            Appender appender = (Appender) appenders.nextElement();
            if (appender.getName().equals(appenderName)) {
                targetAppender = appender;
                break;
            }
        }
        return targetAppender;
View Full Code Here

        return targetAppender;
    }

    private Appender getTheFirstAppenderInLogger(Logger logger) {
        Enumeration appenders = logger.getAllAppenders();
        Appender targetAppender = null;
        if(appenders.hasMoreElements()) {
            targetAppender = (Appender) appenders.nextElement();
        }
        return targetAppender;
    }
View Full Code Here

TOP

Related Classes of org.apache.log4j.Appender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.