java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

日志记录器

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56611
package com.swoky.util;

import java.util.Arrays; import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
*
@author SWOKY
* @Msn    swoky@hotmail.com
*
@version 1.0
*/

public class Debug {

       
public static void out(Object... objects) {

       
if (objects != null && objects.length > 0) {
            StackTraceElement ste
= new Throwable().getStackTrace()[1];
            StringBuilder record
= new StringBuilder();
            Calendar rightNow
= Calendar.getInstance();
            record.append(rightNow.get(
1));
            record.append(
"-");
            record.append(rightNow.get(
2) + 1);
            record.append(
"-");
            record.append(rightNow.get(
5));
            record.append(
" ");
            record.append(rightNow.get(
11));
            record.append(
":");
            record.append(rightNow.get(
12));
            record.append(
":");
            record.append(rightNow.get(
13));
            record.append(
"  ");
            record.append(ste.getClassName());
            record.append(
".");
            record.append(ste.getMethodName());
            record.append(
"()");
            record.append(
"\r\n");
            record.append(ste.getFileName());
            record.append(
"(");
            record.append(ste.getLineNumber());
            record.append(
"");
           
for (Object obj : objects) {
                record.append(objectParser(obj));
                record.append(
",");
            }
            record.deleteCharAt(record.length()
- 1);
            System.out.println(record);
            record.delete(
0, record.length());
            record
= null;
            ste
= null;
        }
    }

   
private static String objectParser(Object obj) {
       
if (obj instanceof Object[]) {
           
return Arrays.toString((Object[]) obj);
        }
else if (obj instanceof Collection) {
           
return Arrays.toString(((Collection) obj).toArray());
        }
else if (obj instanceof Map) {
           
return Arrays.toString(((Map)obj).entrySet().toArray());
        }
       
return obj.toString();
    }
}

posted on 2009-06-10 21:42 rrong_m 阅读(253) 评论(0)  编辑  收藏

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜