本文整理匯總了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);
}
示例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 ) );
}
示例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;
}
示例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());
}
示例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();
}
示例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;
}
示例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());
}
}
示例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());
}
}
示例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();
}
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}