Logutil log Tool

Source: Internet
Author: User
Import Org. apache. log4j. *; import Org. apache. log4j. XML. domaggregator; import Java. io. *; public class logutil {// Private Static baselogutil objlog = new baselogutil (); Private Static final string logconfig = "log4j. properties "; Private Static logger objlog; Private Static logger getlogger () {If (objlog = NULL) {// domconfigurator. configure (getconfigfile (); objlog = logmanager. getlogger (logutil. class);} return objlog;} Private Static string getconfigfile () {string S = logutil. class. getclassloader (). getresource (""). tostring (); string filepath = S + logconfig; return filepath ;} // start info // record information // public static void Info (string message, exception) {try {log ("info ", message, exception);} catch (exception ex) {}}//// record information //// public static void Info (string message) {log ("info", message) ;}// end info // start error public static void trace (string message) {try {log ("trace", message );} catch (exception ex) {}} public static void trace (string message, exception) {try {log ("trace", message, exception);} catch (exception ex) {}}///// record an error message ///// message content /// exception object public static void error (string message, exception) {try {log ("error", message, exception);} catch (exception ex) {}}///// record an error message // public static void error (string message) {try {log ("error ", message);} catch (exception ex) {}}// end error // start warning ///// record a warning message ///// Information Content /// exception object public static void warning (string message, exception exception) {try {log ("Warn", message, exception);} catch (exception ex) {}}///// record a warning message ///// public static void warning (string message) {try {log ("Warn ", message);} catch (exception ex) {}}// end warning // start fatal //// record a program fatal error ///// information /// exception object public static void fatal (string message, exception exception) {try {log ("Fatal", message, exception);} catch (exception ex) {}}///// record a fatal program error // public static void fatal (string message) {try {log ("Fatal ", message);} catch (exception ex) {}}// end fatal // start debug ///// record debugging information ///// Information Content /// exception object public static void debug (string message, exception exception) {try {log ("debug", message, exception);} catch (exception ex) {}}///// record debugging information ///// public static void debug (string message) {try {log ("debug ", message);} catch (exception ex) {}} // end debug public static void log (string level, object MSG) {log (Level, MSG, null );} public static void log (string level, throwable e) {log (Level, null, e);} public static void log (string level, object MSG, throwable E) {try {stringbuilder sb = new stringbuilder (); throwable T = new throwable (); stringwriter Sw = new stringwriter (); printwriter PW = new printwriter (SW); T. printstacktrace (PW); string input = Sw. getbuffer (). tostring (); stringreader sr = new stringreader (input); bufferedreader BR = new bufferedreader (SR); For (INT I = 0; I <4; I ++) Br. readline (); string line = BR. readline (); // At COM. media. web. action. dicmanageaction. list (dicmanageaction. java: 89) int Paren = line. indexof ("at"); line = line. substring (Paren + 3); Paren = line. indexof ('); string invokeinfo = line. substring (0, Paren); int period = invokeinfo. lastindexof ('. '); sb. append ('['); sb. append (invokeinfo. substring (0, period); sb. append (':'); sb. append (invokeinfo. substring (period + 1); sb. append ("():"); Paren = line. indexof (':'); period = line. lastindexof ('); sb. append (line. substring (Paren + 1, period); sb. append (']'); sb. append ("-"); sb. append (MSG); getlogger (). log (priority) level. tolevel (level), sb. tostring (), e);} catch (exception ex) {system. out. println (ex. getlocalizedmessage ());}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.