Package org.apache.log4j

Examples of org.apache.log4j.Appender


    return options;
  }
 
  public void execute(String commandName, final ConsoleInput ci, CommandLine commandLine)
  {
    Appender con = Logger.getRootLogger().getAppender("ConsoleAppender");
    List args = commandLine.getArgList();
    if ((con != null) && (!args.isEmpty())) {
      String subcommand = (String) args.get(0);
      if ("off".equalsIgnoreCase(subcommand) ) {
        if ( args.size() == 1 ){
          con.addFilter(new DenyAllFilter());
          ci.out.println("> Console logging off");
        }else{
         
          String  name = (String)args.get(1);
         
          Object[]  entry  = (Object[])channel_listener_map.remove( name );
         
          if ( entry == null ){
           
            ci.out.println( "> Channel '" + name + "' not being logged" );
           
          }else{
           
            ((LoggerChannel)entry[0]).removeListener((LoggerChannelListener)entry[1]);
           
            ci.out.println( "> Channel '" + name + "' logging off" );
          }
        }
      } else if ("on".equalsIgnoreCase(subcommand) ) {
       
        if ( args.size() == 1 ){

          if( commandLine.hasOption('f') )
          {
            // send log output to a file
            String filename = commandLine.getOptionValue('f');
           
            try
            {
              Appender newAppender = new FileAppender(new PatternLayout("%d{ISO8601} %c{1}-%p: %m%n"), filename, true);
              newAppender.setName("ConsoleAppender");
              Logger.getRootLogger().removeAppender(con);
              Logger.getRootLogger().addAppender(newAppender);
              ci.out.println("> Logging to filename: " + filename);
            } catch (IOException e)
            {
View Full Code Here


    return commands;
  }
 
  public static void initRootLogger() {
    if (Logger.getRootLogger().getAppender("ConsoleAppender")==null) {
      Appender app;
      app = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN));
      app.setName("ConsoleAppender");
      app.addFilter( new DenyAllFilter() )//'log off' by default
      Logger.getRootLogger().addAppender(app);
    }
  }
View Full Code Here

    this.userProfile   = UserProfile.DEFAULT_USER_PROFILE;
    this.controlling   = false;
    this.br       = new CommandReader( new InputStreamReader( new ByteArrayInputStream(new byte[0])));
       
    if (Logger.getRootLogger().getAppender("ConsoleAppender")==null) {
        Appender app;
        app = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN));
        app.setName("ConsoleAppender");
        app.addFilter( new DenyAllFilter() )//'log off' by default
        Logger.getRootLogger().addAppender(app);
      }
   
    initialise();
  }
View Full Code Here

                // Initialize the Component factory
                new ComponentFactory();
               
                Enumeration en = Logger.getRootLogger().getAllAppenders();
                while (en.hasMoreElements()) {
                    Appender appender = (Appender) en.nextElement();
                    if (appender instanceof TextPaneAppender)
                        ((TextPaneAppender) appender).addListener(LogPanel.getInstance());
                }            
       
                logger.info(DcResources.getText("msgApplicationStarts"));
View Full Code Here

    private void shutdownLogger()
    {
        Enumeration appenders = logger.getAllAppenders();
        while (appenders.hasMoreElements())
        {
            Appender appender = (Appender) appenders.nextElement();
            if (appender.getName() != null)
            {
                appender.close();
            }
        }
    }
View Full Code Here

   */
  public void printEndTag(PageRequest request, PageResponse response)
    throws RegainException
  {
    if (mMemoryAppender == null) {
      Appender app = (MemoryAppender) Logger.getRootLogger().getAppender("memory");
      if (app instanceof MemoryAppender) {
        mMemoryAppender = (MemoryAppender) app;
      } else {
        response.print("No MemoryAppender with the name 'memory' configured!");
        return;
View Full Code Here

  public static void setLogLevelAndAppender(String configStr) {
    StringTokenizer st = new StringTokenizer(configStr, "=");
    String anIpAddress = st.nextToken();
    String logConfig = st.nextToken();
    Level level;
    Appender appender;
    if (logConfig.contains(",")) {
      st = new StringTokenizer(logConfig, ",");
      level = Level.toLevel(st.nextToken());
      String categoryAppenderStr = st.nextToken();
      Logger l = Logger.getLogger(categoryAppenderStr);
View Full Code Here

  public static void setLogLevelAndAppender(String configStr) {
    StringTokenizer st = new StringTokenizer(configStr, "=");
    String username = st.nextToken();
    String logConfig = st.nextToken();
    Level level;
    Appender appender;
    if (logConfig.contains(",")) {
      st = new StringTokenizer(logConfig, ",");
      level = Level.toLevel(st.nextToken());
      String categoryAppenderStr = st.nextToken();
      Logger l = Logger.getLogger(categoryAppenderStr);
View Full Code Here

   * @param message the message which should be logged (or not, depending on levels)
   */
  private final void threadLocalAwareLog(String fQCN, Priority priority, Object message, Throwable t) {
    if (isForcedToLog(priority)) {

      final Appender forcedAppender = getForcedAppender();
     
      // force the logging and modify the log message (the latter might return the original message)
      if (forcedAppender!=null) {
        // only call the forced appender
        forcedAppender.doAppend(new LoggingEvent(fQCN, this, priority, modifyLogMessage(message), t));
      } else {
        // go via the normal appenders
        forcedLog(fQCN, priority, modifyLogMessage(message), t);
      }
   
View Full Code Here

      if(pattern == null)
        msg = key;
      else
        msg = java.text.MessageFormat.format(pattern, params);

      final Appender forcedAppender = getForcedAppender();
     
      // force the logging and modify the log message (the latter might return the original message)
      if (forcedAppender!=null) {
        // only call the forced appender
        forcedAppender.doAppend(new LoggingEvent(FQCN, this, priority, modifyLogMessage(msg), t));
      } else {
        // go via the normal appenders
        forcedLog(FQCN, priority, modifyLogMessage(msg), t);
      }
     
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.