log4j principle Java console personalized output plus hyperlink tag

Source: Internet
Author: User
Tags log4j

Programmers are lazy, you know.

Package name : Package com.herman.test;

Import Java.io.File;

Import Java.io.PrintStream; /** * @see output test for custom logs * @author Herman.xiong * @date April 22, 2014 14:22:18 * @version V1.0 * @since JDK 1.6/public
	Class Testlog {//input to file private static final String output_type_file= "file";
	Output to console private static final String output_type_console= "console";
	Output to console location private static final printstream out;
	private static final PrintStream ERR;
		static{out=system.out;
		Err=system.err;
		try {//Log Output path System.setout (New PrintStream (System.getproperty ("User.dir") + "\\TestLog.TestLog"));
		catch (Exception e) {e.printstacktrace ();
		}/** * Custom log Output path */public static void Test0 () {System.out.println ("Custom log Output test");
	SYSTEM.OUT.PRINTLN ("Output path for custom log");
	/** * Output Log to console/public static void Test1 () {out.println ("I output to console"); /** * Output log per log output/public static void Test2 (String type) {if (Output_type_file.equals (type)) {SYSTEM.OUT.PR
		INTLN ("Output log according to log output position"); }else if (OUTPUT_type_console.equals (TYPE)) {out.println ("Output log from log output location");
	}/** * Output to the console and the font is red/public static void Test3 () {err.println ("Output to console and font is Red"); /** * Output to console plus trace (trace Element) */public static void Test4 () {stacktraceelement[] traces = new Throwable (). Getstacktrac  
        E ();
        for (int i=0 i < traces.length; i++) {err.println ("" + traces[i]);
		
		} public static void Main (string[] args) {//test output to File Test0 ();
		
		Test output to console test1 ();
		The test output target is the console and the file Test2 (output_type_file);
		
		Test2 (Output_type_console);
		
		Output to the console and the font is Red test3 ();
	Test4 ();
 }
}

More features, please click to download demo download address: http://download.csdn.net/detail/xmt1139057136/7234033

You are welcome to pay attention to my blog. If you have questions, please add QQ Group:135430763

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.