linux - storing logs/error message on C programming -
when error occurs, c code store error before exiting program. advised store stderr
file (e.g., /home/logs.txt) or advised use different method keep logs/error report (considering programming environment linux
). e.g., code below, how apply method store logs/error message on /home/log.txt
or /home/log
file *fp1; fp1 = fopen("/sys/class/gpio/export","w"); if(fp1 == null){ fprintf(stderr, "errno:%s - opening gpio136 failed - line 739\n ", strerror(errno)); close(fp1); exit(1); }
thank you.
if stderr
used print out error message, so, can redirect output specific file.
$ program 2>~/logs.txt
for better logging tool, can use:
Comments
Post a Comment