0

If I want log everything that happens on the websites on my server into the terminal (where you type) and into a file, well how would I do that using PHP?

2
  • For example if I wanted to say like "User Logged in from: IP" and I want to see that instaly on the servers terminal and for it to be put into a file.
    – Richard
    Dec 1, 2013 at 22:25
  • Welcome to Ask Ubuntu! 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
    Dec 2, 2013 at 21:07

2 Answers 2

1

If your already have logs in files, you can use tailf <file> or tail -f <file> (tailf is the same as tail -f)

From man page:

tail - output the last part of files

-f output appended data as the file grows

with this command you will always see new data in your logs and at the same time you have all logged in files.

1
  • 1
    Since webservers often log to multiple files, you can specify more than one -f option, like: tail -f /var/log/apache2/access.log -f /var/log/apache2/error.log Dec 2, 2013 at 21:10
1

This is a 99% programming (StackExchange - PHP), and only 1% Linux (/Ubuntu) question.

All you need is to write your output (this is pure PHP) from the sites to file, or files.
Like into a global error file in /home/username/log.errors

In the Terminal you will need to use the watch command.
Like so: watch cat /home/username/log.errors
Of course you can utilise cat, tail, and other commands you want.
Watch will periodically run the command, and show the result.

But PHP errors already DO get logged by default.
These logs can be found under /var/log, and they sometime require root to read them.
Good luck.

3
  • 1
    watch - execute a program periodically, showing output fullscreen... "watch /home/username/log.errors" this will not work...
    – Wolfy
    Dec 2, 2013 at 20:59
  • Indeed, but cat would work. Or cat and tail. Why didn't you edit? :)
    – Apache
    Dec 2, 2013 at 23:15
  • My mistake... I always forget that I can edit too :)
    – Wolfy
    Dec 3, 2013 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .