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?
-
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.– RichardDec 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.– guntbertDec 2, 2013 at 21:07
2 Answers
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.
-
1Since 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
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.
-
1watch - execute a program periodically, showing output fullscreen... "watch /home/username/log.errors" this will not work...– WolfyDec 2, 2013 at 20:59
-
-