程序>log.txt
但是这种方式,打印到文件上便不能显示到屏幕上了,所以有一定的局限性。
于是写了一个程序用意实现。
改程序有以下几个文件
Debug.c
Debug.h
改打印log程序可以关闭和打开文件输出、屏幕输出详细说明如下:
debug_term_on();//将打印信息输出到屏幕上
debug_term_off();//不将打印信息输出到屏幕上
debug_file_off();//不将打印信息输出到文件中
debug_set_dir( “./log” ) ; //设置log文件夹
debug_file_on();//将打印信息输出到文件中
输出例子:
01 | #include <stdio.h> |
02 | #include "debug.c" |
03 | int main( int argc, char *argv[]) |
04 | { |
05 | /*--------------------初始化---------------------*/ |
06 | char * log_dir = "./log" ; //the dir |
07 | unsigned int log_terminal = 1; //debug on terminal: yes or not |
08 | /* init the debug info */ |
09 | if ( log_terminal ) |
10 | { |
11 | debug_term_on(); |
12 | } |
13 | else |
14 | { |
15 | debug_term_off(); |
16 | } |
17 | if ( log_dir == NULL ){ |
18 | debug_file_off(); |
19 | } else { |
20 | debug_set_dir( log_dir ); |
21 | debug_file_on(); |
22 | } |
23 | /*-------------------使用测试---------------------*/ |
24 | DBG( "I printf on stdout and logfile...\n" ); |
25 | return 0; |
26 | } |
联系客服