0

Suppose I want to display the sql error in log file which has been created by me. For example ,error log file called "myerror.log "

Now i am using the following code to print my message in log file , " error_log(mysql_error(), 3, "tmp/myerror.log"); ". So Every time when message is printed in myerror.log file with same line, Here i want to print the message one after another.

Kindly help me Thanks Dinesh Kumar Manoharan

2 Answers 2

3

As I understand you want to have each entry/message on new line. If so:

error_log(mysql_error() . PHP_EOL, 3, "tmp/myerror.log");

If you want to have timestamp as well, you will have to add it yourself:

$dt = date('Y-m-d H:i:s', time());
error_log("[{$dt}] " . mysql_error() . PHP_EOL, 3, "tmp/myerror.log");

If you need to constantly use such formatting I recommend to create your own function (something like this):

define('MY_ERROR_LOG', 'tmp/myerror.log');

function myErrorLog($message)
{
    $dt = date('Y-m-d H:i:s', time());
    error_log("[{$dt}] " . $message . PHP_EOL, 3, MY_ERROR_LOG);
}
// use it
myErrorLog(mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

1

maybe you need function like this:

function error_log($message, $log_file) {
    file_put_contents($log_file, $message . "\n");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.