如果自定义log4j的级别

xuzhl 2004-04-28 10:28:52
大家都知道log4j定义了
fatal error warn info debug这几个级别
但是如果想向其中加入自定义的级别,应该如何实现?
...全文
438 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yikai123 2004-05-11
  • 打赏
  • 举报
回复
可以通过Priority类的子类去定义自己的优先级。其实log4j中的Level类就是继承了Priority类实现的默认的那五个级别。
你可以模仿Level类写一个自己的类,定义自己的级别就可以了!

具体的写法见Level类:)
xuzhl 2004-04-28
  • 打赏
  • 举报
回复
我说的不是这样意思?
我现在的项目组中自己定义了以下这些级别。
0 – Error 致命エラー、プログラム中断を引き起こす。
1 – Warring 警告、プログラム中断を引き起こさない。
2 – Info 重要な情報。
3 – Info 一般情報。
4 – In/Out 重要な関数入口と出口情報。
5 – In/Out 比較的に重要な関数入口と出口情報。
6 – In/Out 一般関数入口と出口情報。
我现在是想用这些级别替换log4j原有的fatal error warn info debug这几种。
那么,我是不是要重写Logger、Level这些类。或者有什么别的方法?
dugang106 2004-04-28
  • 打赏
  • 举报
回复
看看log4j.jar下面有个ie5的config

# For the general syntax of property based configuration files see the
# documenation of org.apache.log4j.PropertyConfigurator.

# The root category uses the appender called A1. Since no priority is
# specified, the root category assumes the default priority for root
# which is DEBUG in log4j. The root category is the only category that
# has a default priority. All other categories need not be assigned a
# priority in which case they inherit their priority from the
# hierarchy.

log4j.rootCategory=, A1

# A1 is set to be a LogMonitorAppender which outputs to a swing
# logging console.

log4j.appender.A1=org.apache.log4j.lf5.LF5Appender

读读注释就明白什么意思了,也可以到他们网站上去看看啊!

我们是这么配的:
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧