log4j

Usage of log4J levels

喜你入骨 提交于 2019-12-06 17:43:34
问题 What is the best practice in using log4j levels while coding. I mean when do we use INFO logging, when do we use DEBUG logging / ERROR logging etc. 回答1: The best way to learn is by example. Read source of some open source things, like, oh, Tomcat or whatever is in your application area, and see what you see. 回答2: In general, I follow these guidelines: DEBUG : low level stuff. cache hit, cache miss, opening db connection INFO : events that have business meaning - creating customer, charging cc

Grails log4j configuration - ERROR Method missing when configuring log4j: logger

▼魔方 西西 提交于 2019-12-06 16:39:21
For what ever reason when I attempt to add a logger {...} block to my Grails log4j configuration, I receive the following error: log4j:ERROR Method missing when configuring log4j: logger Can anyone see what might be wrong with my configuration? This is a Grails 1.3.3 application (soon to be upgraded to 2). TIA, John log4j = { error 'org.codehaus.groovy.grails.web.servlet', // controllers 'org.codehaus.groovy.grails.web.pages', // GSP 'net.sf.ehcache.hibernate' debug 'org.hibernate' appenders { console name:'stdout', layout:pattern(conversionPattern: '[%t] %-5p %c{2} %x - %m%n') } logger {

WAS Logging - Java Util Logging and Log4j

▼魔方 西西 提交于 2019-12-06 16:05:09
I am seeking confirmations on followings: Using Websphere Application Server Admin Console, we can specify some logging configurations and that shows classes of your application also (as shown below). If I enable logging in WAS console, will it work only if My Application (and other classes which are mentioned in there) have JUL implemented into it? By default the logging using WAS console is done in the trace file (${SERVER_LOG_ROOT}/trace.log). Can this be made to console also? (I think yes, just be changing it to ${SERVER_LOG_ROOT}/SystemOut.log) Is there any way to configure Log4j

Mybatis log4j how to confiure log4j to print sql log to file

不想你离开。 提交于 2019-12-06 15:30:23
问题 i use Spring 4 and MyBatis 3, want to confiure log4j to print sql log such as connection,select, insert, update, delete, statement, preparedStatement, resultSet to log file. My log4j.properties is as below: ### set log levels ### log4j.rootLogger=debug, stdout, log, index, D, I, W, E #log4j.rootLogger = debug,error, log, index, D, I, W, E log4j.FilePath=${catalina.home}/app_log ### print log to console ### log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target =

How to create process based log file using Log4j?

狂风中的少年 提交于 2019-12-06 15:15:31
below are my class details. ClassA and ClassD are runnable classes. From ClassA I am calling ClassB and ClassC. package comp1 -> Contains ClassA, ClassB, ClassC package comp2 -> Contains ClassD, ClassE Log for comp1 -> comp1.log Log for comp2 -> comp2.log I am using Log4j for logging. I have two loggers based on package name. I am calling ClassE and ClassB from ClassD . Now, comp1.log contains logging messages from ClassB and comp2.log contains log froms ClassD and ClassE . How can I make a process based log? If I run ClassD there should only one log file for ClassD , ClassE and ClassB . Is

How to specify Custom / Extended Logger in log4j.xml file?

冷暖自知 提交于 2019-12-06 14:09:48
问题 I am using Custom Logger for my project eg. class MyLogger. With that i am able to log the message correctly but Its not logging the Class & Method name correctly from where log initiated. So I think may we need to specify MyLoggger in log4j.xml but I don't know where & how ? All suggestions are appreciated. Thanks. 回答1: If you have a class MyClass: package com.acando.norolnes; public class MyClass { public String foo; public int bar; } That you want to custom format when logging, you can

内聚与耦合

你说的曾经没有我的故事 提交于 2019-12-06 13:44:23
简单理解一下内聚和耦合。 什么是模块 模块就是从逻辑上将系统分解为更细微的部分,分而治之。 复杂问题因为复杂性的问题,比较难解决,但是可以将复杂问题拆解为若干简单问题,逐个击破地解决这些简单问题,最后实现解决复杂问题的效果。 模块的粒度划分可大可小,可以是函数,类或功能块等等。 耦合主要描述的是模块与模块之间的关系,内聚则主要描述的是单个模块的内部构成。 什么是耦合 如果模块之间存在依赖,则可能会导致一个模块的改动影响了另外的模块的问题,甚至是相互影响。 两个模块之间的关系越紧密,耦合就越强,模块的独立性就会越差。 比如一个模块A直接操作了模块B中数据,则视为强耦合;若A只是通过数据与模块B交互,则视为弱耦合。 独立的模块便于扩展、维护和单元测试,如果模块之间重重依赖的话,就会极大降低开发效率。 什么是内聚 一个模块应当尽可能独立完成某个功能,模块内部的元素关联性越强,则内聚越高,模块单一性就越强。 如果有各种场景需要被引入到当前模块,代码的质量将变得非常脆弱,这种情况建议拆分为多个模块。 低内聚的模块代码,不管是维护、扩展还是重构都相当麻烦。因为要兼顾内部元素的关联性,如果不理清楚的话可能会难以下手。 接口设计原则 好的接口应当满足设计模式六大原则,很多的设计模式或框架都是基于高内聚低耦合这个出发点的。 1.单一职责原则:一个类只负责一个功能领域中的相应职责。 2.开闭原则

Log4j daily rolling catalina.out without restarting Tomcat?

房东的猫 提交于 2019-12-06 13:34:18
i am having trouble with configuring Log4j correctly. I was expecting Log4j to rotate my catalina.out file at midnight when configuring it like the following.. log4j.properties: log4j.rootLogger=INFO, CATALINA # Define all the appenders log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender log4j.appender.CATALINA.File=/var/log/tomcat7/catalina.out log4j.appender.CATALINA.Append=true log4j.appender.CATALINA.Encoding=UTF-8 # Roll-over the log once per day log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd-HH-mm'.log' log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout

javase基础知识03-异常Exception和自定义异常及测试

北慕城南 提交于 2019-12-06 12:57:58
1.异常的分类 Error:这是我们处理不了的异常。 我们要处理的异常有两种: 编译时被检测异常: 该异常在编译时,如果没有处理(没有抛也没有try),编译失败。该异常会被eclipse标识,代表这可以被处理。 运行时异常(编译时不检测) 该异常的发生说明,我们需要对某些代码进行修正。 2.异常体系的根类是:Throwable Throwable: |--Error: 重大的问题,我们处理不了。也不需要编写代码处理。比如说内存溢出。 |--Exception: 一般性的错误,是需要我们对编写的代码进行处理。 |--运行期异常: 在运行时出问题,需要修正代码 |--编译期异常,就是一般的异常(编译期异常) 3.常见异常 ConcurrentModificationException并发修改异常 IndexOutOfBoundsException元素越界 NoSuchElementException没有这样的元素 ClassNotFoundException找不到类 java.lang.IllegalStateException 非法参数异常 NullPointerException空指针 等等。。。。。 4.Throwable类的三个重要方法 getMessage():获取异常信息,返回字符串。 toString():获取异常类名和异常信息,返回字符串。

日志(slf4j,log4j)

老子叫甜甜 提交于 2019-12-06 12:32:04
常用的日志框架 Log4j: Log4j2: SLF4J:日志输出接口,底层依赖于其它的日志框架 Logback: Apache Commons Logging:和slf4j类似,是日志输出接口,依赖第三方日志框架 java.util.logging.Logger:JDK自带的日志系统 一般项目中使用slf4j作为日志抽象,这样以后系统替换日志框架的话,只需要替换jar,不需要修改代码。 slf4j slf4j仅仅是一个为Java程序提供日志输出的统一接口,并不是一个具体的日志实现方案,就比如JDBC一样,只是一种规则而已,所以单独的slf4j是不能工作的, 必须搭配其他具体的日志实现方案,比如log4j或者log4j2 slf4j+log4j 需要的jar:log4j-xxx.jar slf4j-api-xxx.jar slf4j-log4j12-xx.jar(桥接包) log4j的日志输出级别: TRACE > DEBUG > INFO > WARN > ERROR > FATAL 但是注意slf4j没有FATAL等级 package com.basic.work.log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * Slf4j+log4j 组合 * 需要的jar:log4j-xxx.jar