log文件格式是固定的吗?
如果是固定的,读入不就可以生成你想要的吗

解决方案 »

  1.   

    取apache的网站看看,找相关log的部分。
    apache的log应该是在Log4j的基础上进行了一些扩充的。还有为什么不直接显示?
      

  2.   

    /*
    @author [email protected]
    @version 1.0
    */import java.io.*;
    import java.util.*;public class Str { public static void main(String[] args){
    String str="";
        try{
    String s="";
        java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("access.log"));
        while((s=br.readLine())!=null){
         StringTokenizer st_ip = new StringTokenizer(s);
    if (st_ip.hasMoreTokens()) {
             
              String str_ip=st_ip.nextToken();
              System.out.println(str_ip);
              String str_Date=st_ip.nextToken(" - - [ ");
              System.out.println(str_Date);
              String str_port=st_ip.nextToken(" + ] ");
              System.out.println(str_port);
              String str_method=st_ip.nextToken(" ] \" ");
              System.out.println(str_method);
              String str_url=st_ip.nextToken(" \" ");
              System.out.println(str_url);
              String str_prot=st_ip.nextToken(" \" ");
              System.out.println(str_prot);
              String str_code=st_ip.nextToken();
              System.out.println(str_code);
              String str_wait=st_ip.nextToken();
              System.out.println(str_wait);
             
              System.out.println("\n");       }
            } 
        }catch(Exception e){
         System.out.println(e.toString());
        } }
    }我的代码。其实主要目的是把他放入 数据库(或者XML)。。便于做统计分析。