Log4jimpl.java // log4j Implementation class package com.ynwswst.enterprise.sys; / ***
Title:
*
Description:
*
Copyright: CopyRight (C) 2003 xiaowugui
*
Company: http://www.ynwswst.com
* @Author xiaowugui * @Version 1.0 * / import org.apache.log4j. *; import java.io. *; import java.util. *; / *** @Author administrator ** to change the template for this generated Type comment go to * Window> Preferences> Java> Code Generation> Code and Comments * / public class Log4jImpl {public static final String PROFILE = "log4j.properties"; / *** Holds singleton instance * / private static Log4jImpl impl; static { impl = new Log4jImpl ();} private Logger log4j; / *** prevents instantiation * / private Log4jImpl () {log4j = LogManager.getLogger (Log4jImpl.class); try {Properties pro = new Properties (); InputStream is = getClass () .getResourceAsStream (PROFILE); pro.load (is); PropertyConfigurator.configure (pro);} catch (IOException e) {BasicConfigurator.configure (); e.printStackTrace ();}} public void log (String level, Object MSG) {log (level, msg, null); public void log (string level, throwable e) {log (level, null, e);} public void log (String Level, Object MSG, Java.lang.Throwable e) {if (log4j! = null) {log4j.log ((priority) Level.Tolevel (Level), MSG , e);}} / *** Sample mode * / static public log4jimpl getInstance () {return impl;}} log.java // Record Log Using class package com.ynwswst.Enterprise.sys; / ***
Title:
*
Description:
*
Copyright: CopyRight (C) 2003 xiaowugui
*
COMPANY:
* @Author xiaowugui * @version 1.0 * / public class log = log4jimpl log = log4jimpl.getInstance (); / *** * / public log () {// super ();} public static void logerror (String MSG) ) {log.log ("Error", MSG);} public static void logerror (throwable e) {log.log ("Error", NULL, E);} public static void logwarn (String MSG) {log.log "Warn", msg);} public static void logwarn (throwable e) {log.log ("warn", null, e);} public static void loginfo (string msg) {log.log ("info", msg) Public static void loginfo (throwable e) {log.log ("info", null, e);} public static void logdebug (string msg) {log.log ("debug", msg);} public static void logdebug ("Debug", NULL, E);}} log4j.properties // log4j configuration file log4j.rootlogger = debug, a2, a1log4j.Appender.a2 = org.apache.log4j.rollingfileAppenderlog4j. appender.A2.File = G: /enterprise/log/error.loglog4j.appender.A2.Append=truelog4j.appender.R.MaxFileSize=10000KBlog4j.appender.A2.layout=org.apache.log4j.PatternLayoutlog4j.appender.A2 . ret.Tern = [% - 5P] [% T]% d {yyyy-mm-dd hh: mm: s s, SSS} message:% m% nlog4j.appender.A1 = org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout = org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number # log4j. .appender.stdout.Layout.conversionPattern =% 5P [% t] (% F:% L) -% M% N # print the date in ISO 8601 FormatLog4j.Appender.a1.Layout.conversionPattern =% D [% T % -5p -% m% ntestlog.jsp // call log class <% @ page language = "java" pageEncoding = "GBK"%> <% @ page import = "com.ynwswst.enterprise.s.log"%> <% Log.logdebug ("debug"); log.loginfo ("info"); log.logwarn ("warn");