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