當前位置: 首頁>>代碼示例>>Java>>正文


Java Category類代碼示例

本文整理匯總了Java中org.apache.log4j.Category的典型用法代碼示例。如果您正苦於以下問題:Java Category類的具體用法?Java Category怎麽用?Java Category使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Category類屬於org.apache.log4j包,在下文中一共展示了Category類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: attachPassiveDbAppender

import org.apache.log4j.Category; //導入依賴的package包/類
private void attachPassiveDbAppender(
                                      DbAppenderConfiguration appenderConfiguration,
                                      long timestamp ) {

    // create the new appender
    PassiveDbAppender attachedAppender = new PassiveDbAppender(ThreadsPerCaller.getCaller());

    // calculate the time stamp offset, between the test executor and the agent
    attachedAppender.calculateTimeOffset(timestamp);

    attachedAppender.setAppenderConfig(appenderConfiguration);
    // use a default pattern, as we log in the db
    attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
    attachedAppender.activateOptions();

    // attach the appender to the logging system
    Category log = Logger.getRootLogger();

    log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
    log.addAppender(attachedAppender);

}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:AgentConfigurationServiceImpl.java

示例2: testAutoPopulate

import org.apache.log4j.Category; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void testAutoPopulate ()
{
	final TestClock tc = new TestClock ( 1234567890123L );

	final EcompLayout layout = new EcompLayout ();
	MDC.put ( EcompFields.kBeginTimestampMs, Long.toString ( SaClock.now () ) );

	tc.forward ( 60*1000L );
	layout.format ( new LoggingEvent ( "foo.bar", Category.getRoot (), Priority.INFO, "foobar", null ) );

	assertEquals ( "2009-02-13T23:31:30.123+00:00", MDC.get ( EcompFields.kBeginTimestamp ) );
	assertEquals ( "2009-02-13T23:32:30.123+00:00", MDC.get ( EcompFields.kEndTimestamp ) );
	assertEquals ( "60000", MDC.get ( EcompFields.kElapsedTimeMs ) );
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:17,代碼來源:EcompLayoutTest.java

示例3: LoggingOutputStream

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 * Creates the LoggingOutputStream to flush to the given Category.
 * 
 * @param cat        the Category to write to
 * 
 * @param priority   the Priority to use when writing to the Category
 * 
 * @exception IllegalArgumentException
 *                   if cat == null or priority == null
 */
public LoggingOutputStream(Category cat, Priority priority)
throws IllegalArgumentException {
  if (cat == null) {
    throw new IllegalArgumentException("cat == null");
  }
  if (priority == null) {
    throw new IllegalArgumentException("priority == null");
  }

  this.priority = priority;
  category = cat;
  bufLength = DEFAULT_BUFFER_LENGTH;
  buf = new byte[DEFAULT_BUFFER_LENGTH];
  count = 0;
}
 
開發者ID:MakeITBologna,項目名稱:zefiro,代碼行數:26,代碼來源:LoggingOutputStream.java

示例4: setUp

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 * @throws Exception
 */
@Before public void setUp() throws Exception {

  new MockUp<Category>() {
    @SuppressWarnings("unused")
    @Mock public boolean isDebugEnabled() {
      return true;
    }

    @SuppressWarnings("unused")
    @Mock public boolean isEnabledFor(Priority level) {
      return true;
    }

    @SuppressWarnings("unused")
    @Mock public boolean isInfoEnabled() {
      return true;
    }
  };

  logService = new StandardLogService(this.getClass().getName());
}
 
開發者ID:carbondata,項目名稱:carbondata,代碼行數:25,代碼來源:StandardLogServiceTest_UT.java

示例5: getHibernateSession

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 * Gets the hibernate session.
 *
 * @return the hibernate session
 * @throws UNISoNException
 *             the UNI so n exception
 */
@SuppressWarnings("deprecation")
public synchronized Session getHibernateSession() throws UNISoNException {
	HibernateHelper.logger.debug("getHibernateSession");
	if (null == HibernateHelper.sessionFactory) {
		try {
			final Configuration config = this.getHibernateConfig();

			// FIXME - couldn't stop the NoInitialContext warning so this
			// hack will stop it being displayed
			final Level level = Category.getRoot().getLevel();
			Category.getRoot().setLevel(Level.FATAL);
			HibernateHelper.sessionFactory = config.buildSessionFactory();
			Category.getRoot().setLevel(level);

		}
		catch (final Throwable e) {
			e.printStackTrace();
			throw new UNISoNException("Failed to connect to DB", e);
		}
	}
	HibernateHelper.logger.debug("getHibernateSession");

	return HibernateHelper.sessionFactory.openSession();

}
 
開發者ID:leonarduk,項目名稱:unison,代碼行數:33,代碼來源:HibernateHelper.java

示例6: addIdeFatalMessage

import org.apache.log4j.Category; //導入依賴的package包/類
@Nullable
public LogMessage addIdeFatalMessage(final IdeaLoggingEvent aEvent) {
  Object data = aEvent.getData();
  final LogMessage message = data instanceof LogMessage ? (LogMessage)data : new LogMessage(aEvent);
  if (myIdeFatals.size() < MAX_POOL_SIZE_FOR_FATALS) {
    if (myFatalsGrouper.addToGroup(message)) {
      return message;
    }
  } else if (myIdeFatals.size() == MAX_POOL_SIZE_FOR_FATALS) {
    String msg = DiagnosticBundle.message("error.monitor.too.many.errors");
    LogMessage tooMany = new LogMessage(new LoggingEvent(msg, Category.getRoot(), Priority.ERROR, null, new TooManyErrorsException()));
    myFatalsGrouper.addToGroup(tooMany);
    return tooMany;
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:MessagePool.java

示例7: testLocationInfoNoFQCN

import org.apache.log4j.Category; //導入依賴的package包/類
/**
   * Tests LoggingEvent.getLocationInfo() when no FQCN is specified.
   * See bug 41186.
   */
public void testLocationInfoNoFQCN() {
    Category root = Logger.getRootLogger();
 Priority level = Level.INFO;
    LoggingEvent event =
      new LoggingEvent(
        null, root, 0L,  level, "Hello, world.", null);
    LocationInfo info = event.getLocationInformation();
 //
 //  log4j 1.2 returns an object, its layout doesn't check for nulls.
 //  log4j 1.3 returns a null.
 //
 assertNotNull(info);
 if (info != null) {
    assertEquals("?", info.getLineNumber());
 assertEquals("?", info.getClassName());
 assertEquals("?", info.getFileName());
 assertEquals("?", info.getMethodName());
 }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:LoggingEventTest.java

示例8: test

import org.apache.log4j.Category; //導入依賴的package包/類
public void test() {
    ListHandler listHandler = new ListHandler();
    java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
    root.addHandler(listHandler);
    root.setLevel(Level.FINEST);
    Logger log4jLogger = Logger.getLogger("a");
    Category log4jCategory = Logger.getLogger("b");

    int n = 0;

    log4jLogger.log(org.apache.log4j.Level.DEBUG, "hello" + (++n));
    log4jCategory.log(org.apache.log4j.Level.DEBUG, "world" + (++n));

    assertEquals(n, listHandler.list.size());

    for (int i = 0; i < n; i++) {
        LogRecord logRecord = (LogRecord) listHandler.list.get(i);
        assertEquals("test", logRecord.getSourceMethodName());
    }
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:21,代碼來源:Bug139.java

示例9: doEndTag

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 * 
 * 
 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
 */
public int doEndTag() throws JspException
{
    try {
        //pageContext.getOut().println(bodyContent.toString());
        long end = System.currentTimeMillis();
        Category.getInstance("timer").debug("time (ms): " + (end-start));
        start = 0L;
        return EVAL_PAGE;
    }
    /*
    catch (IOException e) {
        throw new JspException(e);
    }
    */
    catch (Exception e) {
        logger.error(e);
        if (e instanceof JspException)
            throw (JspException) e;
        throw new JspException(e);
    }
    finally {
        reset();
    }
}
 
開發者ID:nyla-solutions,項目名稱:nyla,代碼行數:30,代碼來源:QuestionaireTag.java

示例10: testAppendNormalEvent

import org.apache.log4j.Category; //導入依賴的package包/類
@Test
public void testAppendNormalEvent(){
	Category cat=Category.getRoot();
	long date=System.currentTimeMillis();
	Level level=Level.DEBUG;
	String msg="this is a message";
	String thread=Thread.currentThread().getName();
	database.command(new OCommandSQL("delete from "+DB_TABLE_NAME)).execute();
	LoggingEvent event= new LoggingEvent(null, cat,date , level, msg,thread , null, null, null, null);
	appender.append(event);
	appender.finalize();
	List<ODocument> list=database.command(new OCommandSQL("select * from "+DB_TABLE_NAME+" limit 1")).execute();
	ODocument result=list.get(0);
	Assert.assertEquals(new Date(date), result.field(EventMapper.TIMESTAMP));
	Assert.assertEquals(level.toString(),result.field(EventMapper.LEVEL));
	Assert.assertEquals(msg,result.field(EventMapper.MESSAGE));
	Assert.assertEquals(cat.getName(),result.field(EventMapper.LOGGER_NAME));
	Assert.assertEquals(thread,result.field(EventMapper.THREAD));
}
 
開發者ID:zahidMed,項目名稱:log4j-database,代碼行數:20,代碼來源:TestOrientDBAppender.java

示例11: internalInit

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 *  initializes the log system using the logfile argument
 */
private void internalInit( String logfile )
    throws Exception
{
    /*
     *  do it by our classname to avoid conflicting with anything else 
     *  that might be used...
     */

    logger = Category.getInstance(this.getClass().getName());
    logger.setAdditivity(false);

    /*
     * Priority is set for DEBUG becouse this implementation checks 
     * log level.
     */
    logger.setPriority(Priority.DEBUG);

    RollingFileAppender appender = new RollingFileAppender( new PatternLayout( "%d - %m%n"), logfile, true);
    
    appender.setMaxBackupIndex( 1 );
    
    appender.setMaximumFileSize( 100000 );
    
    logger.addAppender(appender);
}
 
開發者ID:BowlerHatLLC,項目名稱:feathers-sdk,代碼行數:29,代碼來源:SimpleLog4JLogSystem.java

示例12: getLogClasses

import org.apache.log4j.Category; //導入依賴的package包/類
/**
 * Get all log classes names
 *
 * @return
 */
public static Map<String,Object> getLogClasses(){
    SortedMap<String,Object> loggers = new TreeMap<String, Object>();
    Map<String,Object> res = Objects.newHashMap(
            "level",LogManager.getRootLogger().getLevel().toString().toUpperCase(),
            "loggers",loggers
    );

    Enumeration<Category> en = LogManager.getCurrentLoggers();
    while(en.hasMoreElements()){
        Category e = en.nextElement();
        loggers.put(e.getName(),e.getEffectiveLevel().toString().toUpperCase());
    }

    return res;
}
 
開發者ID:s1-platform,項目名稱:s1,代碼行數:21,代碼來源:Loggers.java

示例13: getAllAppendersIncludingParents

import org.apache.log4j.Category; //導入依賴的package包/類
public static Set<Appender> getAllAppendersIncludingParents(Logger logger)
{
	Set<Appender> ret = new LinkedHashSet<Appender>();
	for (Category category = logger; category != null; category = category.getParent())
	{
		Enumeration<?> enumeration = category.getAllAppenders();
		while (enumeration.hasMoreElements())
		{
			// I have to use RTTI, since current version of log4j provides no
			// other alternative.
			Appender appender = (Appender) enumeration.nextElement();
			ret.add(appender);
		}
	}
	return ret;
}
 
開發者ID:hltfbk,項目名稱:Excitement-TDMLEDA,代碼行數:17,代碼來源:LoggerUtilities.java

示例14: getErrorAppender

import org.apache.log4j.Category; //導入依賴的package包/類
/** Lazily load the error appender */
synchronized private FileAppender getErrorAppender() {
    if (this.errorAppender == null && !this.noLogFile) {
        try {
            Layout layout = new PatternLayout("%X{[email protected]} - [%p %20.20c{2}] %m%n");
            ProActiveRuntimeImpl part = ProActiveRuntimeImpl.getProActiveRuntime();
            String runtimeName = part.getVMInformation().getName();
            this.errorAppender = new FileAppender(layout, "throttlingProvider-" + runtimeName + ".log");

            // Add an explanatory message at the begining of the file
            String msg = "This file has been created to prevent logging event loss when the distributed log4j framework is enabled. If a logging event is created while the provider is sending the buffered logging events to the log collector, it is dumped into this file. It prevents logging events loss and infinite loops. If you see this file, most likely, the log collector became unreachable or some low level ProActive loggers have been activated.";
            Logger l = Logger.getLogger(this.getClass());
            LoggingEvent le = new LoggingEvent(Category.class.getName(), l, Level.INFO, msg, null);
            this.errorAppender.append(le);
        } catch (IOException e) {
            System.err.println("Failed to create FileAppender");
            e.printStackTrace();
        }
    }

    return this.errorAppender;
}
 
開發者ID:mnip91,項目名稱:proactive-component-monitoring,代碼行數:23,代碼來源:ThrottlingProvider.java

示例15: testLogLevel

import org.apache.log4j.Category; //導入依賴的package包/類
@Test
public void testLogLevel() throws Exception {
	Logger targetLogger = logTestSample.getTargetLogger();

	assertEquals("egovframework.rte.fdl.logging.sample.LogTestSample",
			targetLogger.getName());
	Category selectedCategory = targetLogger;
	// 대상 클래스 풀패키지명에 매칭되는 정의된 로거(Category)가 없으면 parent 를 따라 설정되므로
	// 등록된 Category 는 level 이 정의되 있다는 가정하에 해당 Category 를 찾음
	while (selectedCategory.getLevel() == null) {
		selectedCategory = selectedCategory.getParent();
	}
	assertEquals("egovframework", selectedCategory.getName());
	assertTrue(selectedCategory.isDebugEnabled());
	assertEquals(Level.DEBUG, selectedCategory.getLevel());
	assertTrue(!selectedCategory.getAdditivity());

	// 현재 egovframework 로그 레벨이 log4j.xml 에 DEBUG 로 정의되 있으므로
	// 해당 로거 정의(Category) 를 따르는 logTestSample 의 메서드를 실행하면
	// DEBUG, INFO, WARN, ERROR, FATAL 에 대한 모든 로그가 출력될 것임. console 창에서 확인
	logTestSample.executeSomeLogic();

}
 
開發者ID:eGovFrame,項目名稱:egovframework.rte.root,代碼行數:24,代碼來源:LogLevelTest.java


注:本文中的org.apache.log4j.Category類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。