Friday, May 3, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 4227  / 2 Years ago, wed, february 9, 2022, 12:54:23

I want to know how to get a log file of a program. This is useful to find the faults in an application when it crashes.



I mean opening the application through the terminal and at the same time writing a log file.



Are there special commands to do this, or is it automatically done whenever an application is run? If so, where is that log file stored?


More From » command-line

 Answers
7

Not all applications will leave a log behind, it depends on the coding behind them, even complex ones might not have logging capabilities.



If an application has a debug, verbose or log capabilities that option will be declared in the man page of that application, ie: man ssh will show you that if you use ssh -v you will get a verbose output of what the command is doing on the background when opening a tunnel to a host, ssh -y will output to syslog instead of stderr.



But some applications are just not programmed with that capability. For those strace can be used as a debugging utility for any application though, it logs all system calls and signals, I find it useful when I have any crashes or unexpected faults while running an application, and most of the times it helps me sort issues with applications that do not have a debug or a log option built in to their code, ie strace ls outputs:



execve("/usr/bin/ls", ["ls"], [/* 95 vars */]) = 0
brk(0) = 0x20b6000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd7e5ca3000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=118369, ...}) = 0
mmap(NULL, 118369, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd7e5c86000
close(3) = 0
open("/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "177ELF21100000000030>0100020l000000"..., 832) = 832
...
...
...


This allows you to have an idea of what is happening and why is an application failing to halting in its code.


[#28416] Wednesday, February 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
erranbe

Total Points: 118
Total Questions: 95
Total Answers: 117

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;