Package org.apache.log4j

Examples of org.apache.log4j.Category


  }

  static
  void test() {
    int i = -1;
    Category root = Category.getRoot();
   
    CAT.debug("Message " + ++i);
    root.debug("Message " + i);       

    CAT.info ("Message " + ++i);
    root.info("Message " + i);       

    CAT.warn ("Message " + ++i);
    root.warn("Message " + i);       

    CAT.error("Message " + ++i);
    root.error("Message " + i);
   
    CAT.log(Priority.FATAL, "Message " + ++i);
    root.log(Priority.FATAL, "Message " + i);   
   
    Exception e = new Exception("Just testing");
    CAT.debug("Message " + ++i, e);
    root.debug("Message " + i, e);
   
    CAT.info("Message " + ++i, e);
    root.info("Message " + i, e);   

    CAT.warn("Message " + ++i , e);
    root.warn("Message " + i , e);   

    CAT.error("Message " + ++i, e);
    root.error("Message " + i, e);   

    CAT.log(Priority.FATAL, "Message " + ++i, e);
    root.log(Priority.FATAL, "Message " + i, e);   
  }
View Full Code Here


    // In the lines below, the category names are chosen as an aid in
    // remembering their priority values. In general, the category
    // names should have no bearing to priority values.
   
    Category ERR = Category.getInstance("ERR");
    ERR.setPriority(Priority.ERROR);
    Category INF = Category.getInstance("INF");
    INF.setPriority(Priority.INFO);
    Category INF_ERR = Category.getInstance("INF.ERR");
    INF_ERR.setPriority(Priority.ERROR);
    Category DEB = Category.getInstance("DEB");
    DEB.setPriority(Priority.DEBUG);
   
    // Note: categories with undefined priority
    Category INF_UNDEF = Category.getInstance("INF.UNDEF");
    Category INF_ERR_UNDEF = Category.getInstance("INF.ERR.UNDEF");   
    Category UNDEF = Category.getInstance("UNDEF");  


    // These should all log.----------------------------
    ERR.log(Priority.FATAL, "Message " + i); i++;  //0
    ERR.error( "Message " + i); i++;         

    INF.log(Priority.FATAL, "Message " + i); i++; // 2
    INF.error( "Message " + i); i++;        
    INF.warn ( "Message " + i); i++;
    INF.info ( "Message " + i); i++;

    INF_UNDEF.log(Priority.FATAL, "Message " + i); i++;  //6
    INF_UNDEF.error( "Message " + i); i++;        
    INF_UNDEF.warn ( "Message " + i); i++;
    INF_UNDEF.info ( "Message " + i); i++;
   
   
    INF_ERR.log(Priority.FATAL, "Message " + i); i++;  // 10
    INF_ERR.error( "Message " + i); i++; 

     INF_ERR_UNDEF.log(Priority.FATAL, "Message " + i); i++;
    INF_ERR_UNDEF.error( "Message " + i); i++;            

    DEB.log(Priority.FATAL, "Message " + i); i++;  //14
    DEB.error( "Message " + i); i++;        
    DEB.warn ( "Message " + i); i++;
    DEB.info ( "Message " + i); i++;
    DEB.debug( "Message " + i); i++;

   
    // defaultPriority=DEBUG
    UNDEF.log(Priority.FATAL, "Message " + i); i++;  // 19
    UNDEF.error("Message " + i); i++;        
    UNDEF.warn ("Message " + i); i++;
    UNDEF.info ("Message " + i); i++;
    UNDEF.debug("Message " + i, new Exception("Just testing.")); i++;   

    // -------------------------------------------------
    // The following should not log
    ERR.warn("Message " + i);  i++;
    ERR.info("Message " + i);  i++;
View Full Code Here

      TopicSubscriber topicSubscriber =
           topicSession.createDurableSubscriber(topic, "x");


      LoggingEvent event;
      Category remoteCategory;

      while(true) {
  ObjectMessage msg = (ObjectMessage)topicSubscriber.receive();
  event = (LoggingEvent) msg.getObject();
  remoteCategory = Category.getInstance(event.categoryName);
  remoteCategory.callAppenders(event);

  // dump the JMSMessage
  // remoteCategory.debug(msg);

      }
View Full Code Here

         *  configure log4j to log to console
         */

        BasicConfigurator.configure();

        Category log = Category.getInstance( CATEGORY_NAME );

        log.info("Hello from Log4jCategoryExample - ready to start velocity");

        /*
         *  now create a new VelocityEngine instance, and
         *  configure it to use the category
         */

        VelocityEngine ve = new VelocityEngine();

        ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
            "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" );

        ve.setProperty("runtime.log.logsystem.log4j.category", CATEGORY_NAME);

        ve.init();

        log.info("this should follow the initialization output from velocity");
    }
View Full Code Here

      if (desiredOraOopLoggingLevel == Level.DEBUG
          || desiredOraOopLoggingLevel == Level.ALL
          || sqoopLogLevel == Level.DEBUG || sqoopLogLevel == Level.ALL) {

        Category oraOopLogger =
            Logger.getLogger(OraOopManagerFactory.class.getName()).getParent();
        oraOopLogger.setLevel(Level.DEBUG);
        LOG.debug("Enabled OraOop debug logging.");
        result = true;

        conf.set(OraOopConstants.ORAOOP_LOGGING_LEVEL, Level.DEBUG.toString());
      }
View Full Code Here

    System.exit(1);
  }

  static
  void init(String host, String portStr) {
    Category root = Category.getRoot();
    BasicConfigurator.configure();
    try {
      int port   = Integer.parseInt(portStr);
      cat.info("Creating socket appender ("+host+","+port+").");
      s = new SocketAppender(host, port);
      s.setName("S");
      root.addAppender(s);
    }
    catch(java.lang.NumberFormatException e) {
      e.printStackTrace();
      usage("Could not interpret port number ["+ portStr +"].");
    }
View Full Code Here

    }
  }

  static
  void loop() {
    Category root = Category.getRoot();
    InputStreamReader in = new InputStreamReader(System.in);
    System.out.println("Type 'q' to quit");
    int i;
    int k = 0;
    while (true) {
      cat.debug("Message " + k++);
      cat.info("Message " + k++);
      cat.warn("Message " + k++);
      cat.error("Message " + k++, new Exception("Just testing"));
      try {i = in.read(); }
      catch(Exception e) { return; }
      if(i == -1) break;
      if(i == 'q') break;
      if(i == 'r') {
  System.out.println("Removing appender S");
  root.removeAppender("S");
      }
    }
  }
View Full Code Here

  }

  static
  void test() {
    int i = -1;
    Category root = Category.getRoot();
   
    cat.trace("Message " + ++i);
    cat.debug("Message " + ++i);
    root.debug("Message " + i);
    cat.info ("Message " + ++i);
    cat.warn ("Message " + ++i);
    cat.error("Message " + ++i);   
    cat.log(Priority.FATAL, "Message " + ++i);   
    Exception e = new Exception("Just testing");
View Full Code Here

  }

  static
  void test() {
    int i = -1;
    Category root = Category.getRoot();
   
    cat.debug("Message " + ++i);
    root.debug("Message " + i);       

    cat.info ("Message " + ++i);
    root.info("Message " + i);       

    cat.warn ("Message " + ++i);
    root.warn("Message " + i);       

    cat.error("Message " + ++i);
    root.error("Message " + i);
   
    cat.log(Priority.FATAL, "Message " + ++i);
    root.log(Priority.FATAL, "Message " + i);   
   
    Exception e = new Exception("Just testing");
    cat.debug("Message " + ++i, e);
    root.debug("Message " + i, e);
   
    cat.error("Message " + ++i, e);
    root.error("Message " + i, e);   

    Category.shutdown();
  }
View Full Code Here

  protected
  void parseCategory (Element categoryElement, Hierarchy hierarchy) {
    // Create a new org.apache.log4j.Category object from the <category> element.
    String catName = subst(categoryElement.getAttribute(NAME_ATTR));

    Category cat;   

    String className = subst(categoryElement.getAttribute(CLASS_ATTR));


    if(EMPTY_STR.equals(className)) {
      LogLog.debug("Retreiving an instance of org.apache.log4j.Category.");
      cat = hierarchy.getInstance(catName);
    }
    else {
      LogLog.debug("Desired category sub-class: ["+className+']');
       try {  
   Class clazz = Class.forName(className);
   Method getInstanceMethod = clazz.getMethod("getInstance",
                ONE_STRING_PARAM);
   cat = (Category) getInstanceMethod.invoke(null, new Object[] {catName});
       } catch (Exception oops) {
   LogLog.error("Could not retrieve category ["+catName+
          "]. Reported error follows.", oops);
   return;
       }
    }

    // Setting up a category needs to be an atomic operation, in order
    // to protect potential log operations while category
    // configuration is in progress.
    synchronized(cat) {
      boolean additivity = OptionConverter.toBoolean(
                           subst(categoryElement.getAttribute(ADDITIVITY_ATTR)),
         true);
   
      LogLog.debug("Setting ["+cat.getName()+"] additivity to ["+additivity+"].");
      cat.setAdditivity(additivity);
      parseChildrenOfCategoryElement(categoryElement, cat, false);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.log4j.Category

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.