最近有这么一个需求,就是把android系统或应用程序里面的log进行本地化,既把日志信息保存在文件里面存储到终端上面或SDCard存储介质里面,日志文件到达一定的大小后要进行切割分存,整个日志文件存储大小过拉指定大小后要把最旧的日志文件进行删除,我知道日志本不应该这样处理的,但需求是这样的,没办法,整了两天也没有整出个啥东西出来,看了slf4j-android组件,但该组件貌似不能实现此功能,它只能把android本身的日志做了一个转换然后打印到客户端,也就是说只做显示,它也没有提供像log4j那样的属性配置文件进行配置信息。在网络也没有找到什么解决方案,这个问题很棘手,还请各位帮忙,谢谢。

解决方案 »

  1.   

    logcat -r 文件大小 -n 文件个数 -f 文件名
    http://developer.android.com/tools/help/logcat.html
    Option Description 
    -b <buffer> Loads an alternate log buffer for viewing, such as event or radio. The main buffer is used by default. See Viewing Alternative Log Buffers. 
    -c Clears (flushes) the entire log and exits. 
    -d Dumps the log to the screen and exits. 
    -f <filename> Writes log message output to <filename>. The default is stdout. 
    -g Prints the size of the specified log buffer and exits. 
    -n <count> Sets the maximum number of rotated logs to <count>. The default value is 4. Requires the -r option. 
    -r <kbytes> Rotates the log file every <kbytes> of output. The default value is 16. Requires the -f option. 
    -s Sets the default filter spec to silent. 
    -v <format> Sets the output format for log messages. The default is brief format. For a list of supported formats, see Controlling Log Output Format.