- 浏览: 497298 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (250)
- concurrent (11)
- io (1)
- CI (10)
- linux (57)
- windows (2)
- java (38)
- mac (4)
- eclipse (9)
- db (13)
- python (5)
- groovy (5)
- flex (7)
- hibernate (5)
- odb (8)
- netbeans (1)
- web (31)
- book (14)
- erlang (2)
- communication (2)
- virtualization (5)
- jUnit (0)
- jsf (1)
- perl (1)
- java jax-rs (5)
- Jenkins (2)
- Jenkins Plugin (3)
- android (2)
- git (1)
- big data (0)
- 试读 (1)
最新评论
-
yzzy4793:
讲的很清楚,明白
同步synchronized方法和代码块 -
aa51513:
中文乱码式硬伤
Jersey2.x对REST请求处理流程的分析 -
feiwomoshu1991:
...
同步synchronized方法和代码块 -
marshan:
启动失败的原因是加载的类版本冲突,因此你首先要保证依赖的版本和 ...
richfaces中facelet版本升级到2时的典型错误和解决办法 -
zhaohang6688:
请问我按照你的方式修改还是报错 错误信息还是这个 是为什么啊 ...
richfaces中facelet版本升级到2时的典型错误和解决办法
log4j.rootLogger=WARN, stdout, logfile log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n log4j.appender.logfile=org.apache.log4j.RollingFileAppender log4j.appender.logfile.File=${log4jDIR}/dialOut.log log4j.appender.logfile.append=true log4j.appender.logfile.layout=org.apache.log4j.PatternLayout log4j.appender.logfile.layout.ConversionPattern=%d [%c] - %m%n log4j.appender.logfile.MaxFileSize=2MB log4j.appender.logfile.MaxBackupIndex=3
The above code block is log4j.properties, you can save this file anywhere.
Look at the block, you can find a parameter:log4jDIR. This is a user define one. you could understand it at the following code block.
package com.rv.stresstest.logger; import java.io.File; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import com.rv.stresstest.StressApplication; public class RVAppLog { private static Logger logger; @SuppressWarnings("unchecked") public static Logger getLogger(Class clazz, Level level) { if (logger == null) { String path = StressApplication.getInstance().getRootPath(); System.setProperty("log4jDIR", path+"logs"+File.separator); String property = path + "log4j.properties"; PropertyConfigurator.configure(property); logger = Logger.getLogger(clazz); logger.setLevel(level); } return logger; } }
In this block, I use a class to find the path. You can review this class in the following .
package com.rv.stresstest; public class StressApplication { private static StressApplication a; private StressApplication() { } public static StressApplication getInstance() { if (a == null) a = new StressApplication(); return a; } public String getClassRootPath() { try { String result = StressApplication.class.getResource("StressApplication.class").toString(); int index = result.indexOf("classes"); result = result.substring(0, index) + "classes"; if (result.startsWith("jar")) { result = result.substring(10); } else if (result.startsWith("file")) { result = result.substring(6); } String os = System.getProperty("os.name"); if (os.indexOf("Windows") >= 0) return result; else return "/" + result; } catch (Exception e) { return ""; } } public String getRootPath() { String result = StressApplication.class.getResource("StressApplication.class").toString(); int index = result.indexOf("WEB-INF"); if (index == -1) { index = result.indexOf("bin"); } result = result.substring(0, index); if (result.startsWith("jar")) { result = result.substring(10); } else if (result.startsWith("file")) { result = result.substring(6); } String os = System.getProperty("os.name"); if (os.indexOf("Windows") >= 0) return result; else return "/" + result; } }
At last, I will give guys a test.
package com.rv.stresstest.logger; import org.apache.log4j.Level; import org.apache.log4j.Logger; public class TestLog { public static void main(String[] args) { Logger logger = RVAppLog.getLogger(TestLog.class, Level.DEBUG); for (int i = 0; i < 111; i++) { logger.debug(i); } } }
The result log as the following.
2009-04-28 17:37:13,123 [com.rv.stresstest.logger.TestLog] - 0 2009-04-28 17:37:13,123 [com.rv.stresstest.logger.TestLog] - 1 2009-04-28 17:37:13,123 [com.rv.stresstest.logger.TestLog] - 2 …… 2009-04-28 17:37:13,154 [com.rv.stresstest.logger.TestLog] - 110
发表评论
-
拥抱Java8第一弹
2014-01-17 11:59 2719package creative.air.java8.com ... -
Log4j2 整理
2013-12-09 12:25 812http://logging.apache.org/log4j ... -
profilers
2013-12-01 20:15 739SonarQube http://www.sonarqu ... -
JProfiler download
2013-12-01 20:01 1103Version: 8.0.1 (2013-07-31) h ... -
yjp download
2013-12-01 19:12 1089Download YourKit Java Profile ... -
Ubuntu中Java IDE启动器配置
2013-09-23 11:06 1422sudo nano /usr/share/applicati ... -
JAVA SYS TIME
2013-07-29 07:50 1059public class TestSys { //@Tes ... -
计划任务的顺序执行[Quartz Scheduler v.2.1.6]
2013-04-07 13:39 7790使用Quartz做计划任务时,默认情况下,当前任务总会执行 ... -
test list
2013-01-21 16:05 1029import java.util.ArrayList; p ... -
使用HashMap实现缓存
2012-09-07 01:28 4179本类开发中 欢迎拍砖 重伤我者 必须答谢! 实现: ... -
architect mark
2012-07-25 23:46 9651Z0_864 1Z0_865 1Z0 ... -
Windows下多版本Java并存问题
2012-05-01 23:59 9724跨平台的Java配置如下: C:\Users\Admi ... -
使用gitHub下载richfaces代码
2011-12-28 17:40 1542richfaces的源代码位于 https://github. ... -
jvm command
2011-10-18 22:05 1042/System/Library/Java/Java ... -
[童虎退壳系列]判等与哈希值的覆写
2011-10-13 01:57 1113public final class EqualsHas ... -
Java枚举
2011-06-22 10:00 867public enum TransportTy ... -
highcharts在richfaces下的实现
2011-01-12 19:40 3228highcharts是优秀的javascript图表生成工具( ... -
使用richfaces玩转json
2011-01-10 18:16 4441richfaces封装了jQuery和json,因此我们在ri ... -
JSF项目打包
2010-09-05 22:30 1176同事问我,JSF项目发布的时候,为什么编译后的类放在class ... -
SLF4J version conflict
2010-08-31 11:21 1644Here are the exception detail ...
相关推荐
- Support for a log formatter (similar to Layouts in Log4J) - Support for console log - Support for smtp formatter - Support for XML logs - Support for syslog - Support for changing format and level ...
**Ease of Use:** Since logging is rarely the main focus of an application, the Log4j API strives to be simple to understand and use. Its straightforward configuration and setup process make it easy ...
Tomcat8下使用Log4j接管生成日志文件,按天存放,日志转换成json格式 亲测可用,日志格式如下: {"time":"2017-09-06 10:24:48,356","logtype":"INFO","loginfo":"org.apache.catalina.startup.HostConfig:Deploying...
TNT4J是一个改进Log4J新的开源Java应用日志框架。用于应用程序活动的跟踪、相关性检查、诊断,可以跨多个应用程序,运行时,服务器,地理的位置。这个API是专门用以解决分布式,并发,多线程,多用户应用,包括活动...
在Java开发中,框架的应用是不可或缺的,这里我们聚焦于Java框架的学习,特别是Spring和相关日志管理的Log4j。下面将详细讲解这些知识点。 首先,Log4j是Java中广泛使用的日志记录框架,它允许开发者自定义日志级别...
LOG4J 1.2.13 or higher This is a simple image editing and printing application. The distribution is composed of the following directories: The distribution directory () The Distribution directory ...
实际上,`OCS4J.properties.tmp`文件用于定义Oracle Cluster Synchronization Services (CSS)的一些关键参数,而CSS是Oracle Real Application Clusters (RAC)的重要组成部分之一。 ##### 2.2 文件的作用 - **...
DLL: When using J-Trace PRO with IAR EWARM a "failed to allocate x bytes of memory" error could occur. Fixed. DLL: Windows: Renesas RX: When using FINE interface and disabling ongoining debug mode on ...
**Log4Net** 是一个开源的日志框架,适用于.NET环境,灵感来源于Java的Log4j。它允许开发者定义不同级别的日志(如DEBUG、INFO、WARN、ERROR和FATAL),并将日志信息写入不同的目标,如控制台、文件、数据库等。通过...
- Note: We have seen a report of the Video Playback failing (crash) due to a faulty video codec, ffdshow.ax. If you are using this we suggest you try a different Video file and codec. Release ...
在本项目中,我们主要探讨的是如何在Spring MVC框架下集成MongoDB 3.0数据库,同时利用log4j2进行日志管理,并且运用注解进行程序的简化与优化。下面将对这些核心知识点进行详细阐述。 首先,Spring MVC是Spring...
Table of Contents Preface 1 Chapter 1: Getting Started with Geronimo ...Logging using the ApplicationLog4jConfigurationGBean 332 Using the Java Logging API 333 Using the SLF4j logging adapter ...
- **Logging**: Discusses how to configure logging frameworks like Log4j or SLF4J for Hibernate. - **Implementing a Naming Strategy**: Explains how to customize the naming strategy used by Hibernate ...
Access, Excel 95/97 (VBA) Windows Scripting Host (cscript / wscript) Perl 5.x for Win32 Inprise Delphi 4 Microsoft Visual C++ 4.x/5.x/6.x Microsoft Visual J++ 1.x/6.0 (Java) <END>...
19.2. Running as a Packaged Application 19.3. Using the Maven Plugin 19.4. Using the Gradle Plugin 19.5. Hot Swapping 20. Developer Tools 20.1. Property Defaults 20.2. Automatic Restart 20.2.1. ...
A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- A addCookie(Cookie) - Method in class javax.servlet.http.HttpServletResponseWrapper ...
9. **日志和调试**:了解如何使用Log4j、SLF4J等日志框架,以及IDE中的调试工具,帮助定位和解决问题。 10. **测试**:可能包含JUnit或其他测试框架的使用,确保代码的质量和稳定性。 11. **版本控制**:由于提到...
What you need to use this book To run the samples in this book you will need: o Java 2 Platform, Standard Edition SDK v...o Apache Log4j 1.2 o An implementation of the JSP Standard Tag Library (JSTL) 1.0