Config log4j
来源:互联网 发布:淘宝网页装修模板 编辑:程序博客网 时间:2024/05/17 07:01
reference:http://www.vipan.com/htdocs/log4jhelp.html
package log4j;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
public class TestLogging ...{
// Initialize a logging category. Here, we get THE ROOT CATEGORY
// static Category cat = Category.getRoot();
// Or, get a custom category
static Category cat = Category.getInstance(TestLogging.class.getName());
public void init() ...{
Properties prop = System.getProperties();
Enumeration enum1 = prop.propertyNames();
cat.info("***System Environment As Seen By Java***");
cat.debug("***Format: PROPERTY = VALUE***");
while (enum1.hasMoreElements()) ...{
String key = (String) enum1.nextElement();
cat.info(key + " = " + System.getProperty(key));
}
}
public static void main(String args[]) ...{
// Try a few logging methods
// Use debug to write debugging messages which should not be printed
// when the application is in production
cat.debug("Start of main()");
// Use info for messages similar to the "verbose" mode of many
// applications.
cat.info("Just testing a log message with priority set to INFO");
// Use warn for warning messages which are logged to some log but the
// application is able to carry on without a problem.
cat.warn("Just testing a log message with priority set to WARN");
// Use error for application error messages which are also logged to
// some log but, still, the application can hobble along. Such as when
// some administrator-supplied configuration parameter is incorrect and
// you fall back to using some hard-coded default value.
cat.error("Just testing a log message with priority set to ERROR");
// Use fatal for critical messages, after logging of which the
// application quits abnormally.
cat.fatal("Just testing a log message with priority set to FATAL");
// Alternate but INCONVENIENT form
cat.log(Priority.DEBUG, "Calling init()");
new TestLogging().init();
}
}
import java.util.Enumeration;
import java.util.Properties;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
public class TestLogging ...{
// Initialize a logging category. Here, we get THE ROOT CATEGORY
// static Category cat = Category.getRoot();
// Or, get a custom category
static Category cat = Category.getInstance(TestLogging.class.getName());
public void init() ...{
Properties prop = System.getProperties();
Enumeration enum1 = prop.propertyNames();
cat.info("***System Environment As Seen By Java***");
cat.debug("***Format: PROPERTY = VALUE***");
while (enum1.hasMoreElements()) ...{
String key = (String) enum1.nextElement();
cat.info(key + " = " + System.getProperty(key));
}
}
public static void main(String args[]) ...{
// Try a few logging methods
// Use debug to write debugging messages which should not be printed
// when the application is in production
cat.debug("Start of main()");
// Use info for messages similar to the "verbose" mode of many
// applications.
cat.info("Just testing a log message with priority set to INFO");
// Use warn for warning messages which are logged to some log but the
// application is able to carry on without a problem.
cat.warn("Just testing a log message with priority set to WARN");
// Use error for application error messages which are also logged to
// some log but, still, the application can hobble along. Such as when
// some administrator-supplied configuration parameter is incorrect and
// you fall back to using some hard-coded default value.
cat.error("Just testing a log message with priority set to ERROR");
// Use fatal for critical messages, after logging of which the
// application quits abnormally.
cat.fatal("Just testing a log message with priority set to FATAL");
// Alternate but INCONVENIENT form
cat.log(Priority.DEBUG, "Calling init()");
new TestLogging().init();
}
}
log4j.properties is below:
log4j.rootCategory=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
Note:
log4j.properties must be under the src dir
src
-log4j
-TestLogging.java
-log4j.properties
- Config log4j
- log4j config
- log4j config
- Config log4j in standalone app
- grails1.1 log4j DailyRollingFileAppender 配置 config.groovy
- Config log4j to print SOAP content with AXIS2
- Config
- .config
- config
- Config
- config
- config
- config
- config
- Config
- Config
- config
- config
- 马云:阿里巴巴设七个分公司是因为讲究风水
- 高精度整数除法
- C#中父窗口和子窗口之间实现控件互操作
- 在asp.net中单击清空TextBox中的内容
- .NET 中的对象序列化
- Config log4j
- 利用API 实现 字符串的镜像
- WEB PACS with JPIP
- javascript设计模式交流(四) ——Interpreter Pattern
- 线程的实现
- 你知道C#中main函数参数的用处吗?
- 网游“包身工”:我们是累并枯燥的哑巴
- javascript设计模式交流(五) ——Composite Pattern
- 法拉利340教程(详细教程)[转载]