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?

  • 2
    This question is way to broad to get an objective answer. Different programmes have different ways of logging. And there are also system logs. Please be more specific in your question. – Luís de Sousa Nov 14 '13 at 10:03
  • What is the purpose of this logging? If we know what you are trying to achieve (even if it's debugging an entire operating system) it's easier to help. – l0b0 Nov 14 '13 at 12:48
  • There is a question that mentioned, software center get crashed. It was a unanswered for some time. I wanted to find a solution. If in such a instance, how can find the error point ? – user224082 Nov 14 '13 at 15:02
  • 1
    The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself. – guntbert Nov 14 '13 at 17:23
  • Ok. But it was not a question of mine. I tried to help. – user224082 Nov 14 '13 at 17:35

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, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20l\0\0\0\0\0\0"..., 832) = 832

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


I think all you want is to see the text in the terminal and at the same time write it to a file:

ls -l | tee -a ls.log

This lists your files to the terminal and to ls.log. The -a is for appending instead of overwriting in case ls.log exists.

Note that this does not work for terminal applications, like less or top or anything that has menus and scrolls.

If some text is missing in the "log" you have to redirect the error messages to the standard output:

ls filedoesnotexist_or_whatever_leads_to_an_error 2>&1 | tee -a ls.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy