debug_log question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

debug_log question

Post by johnhelen »

Hi

To know how the application runs in my application, I add some messages using error_log such as

Code: Select all

error_log ("Start the script)";
....
error_log ("End the script)";
And I have this in the application config (Apache virtual host application):
[syntax]
<VirtualHost _default_:*>
..
ErrorLog /home/mycomputer/myapp/logs/apache-error.log
..
[/syntax]
By this way, I can see the application runs when view the file apache-error.log

However, in production server, I do not want to see these messages; I only want to see them in staging and development servers. Could you please tell me how to fix this

Many thanks
john
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: debug_log question

Post by Benjamin »

:arrow: Moved to PHP - Code
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: debug_log question

Post by requinix »

Write your own function that checks which server it's on. $_SERVER["SERVER_NAME"] is your friend.
johnhelen
Forum Commoner
Posts: 45
Joined: Mon Feb 19, 2007 9:17 pm

Re: debug_log question

Post by johnhelen »

> Write your own function that checks which server it's on. $_SERVER["SERVER_NAME"] is your friend.

Is there more simple solution? can I have something like debug_log('...."). On staging and development, I can turn debug on but in production server ini, I can set debug off ?

Thanks
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: debug_log question

Post by Jonah Bron »

This is what tasairis was talking about.

Code: Select all

function my_debug_log($text) {
    if ($_SERVER['SERVER_NAME'] == 'the name of my server') {
        debug_log($text);
    }
}
Another option would be, instead of checking the server name, have it check a constant that you define. This would require you to manually switch, and is probably unnecessary.
Post Reply