Skip to content

Commit 2946274

Browse files
committed
Merge pull request laravel#1473 from s4wny/patch-1
Added a pretty_print option to the log class
2 parents ff682d6 + 62f25c7 commit 2946274

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

laravel/log.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ protected static function exception_line($e)
3333
*
3434
* // Write an "error" message using the class' magic method
3535
* Log::error('Something went horribly wrong!');
36+
*
37+
* // Log an arrays data
38+
* Log::write('info', array('name' => 'Sawny', 'passwd' => '1234', array(1337, 21, 0)), true);
39+
* //Result: Array ( [name] => Sawny [passwd] => 1234 [0] => Array ( [0] => 1337 [1] => 21 [2] => 0 ) )
40+
* //If we had omit the third parameter the result had been: Array
3641
* </code>
3742
*
3843
* @param string $type
3944
* @param string $message
4045
* @return void
4146
*/
42-
public static function write($type, $message)
47+
public static function write($type, $message, $pretty_print = false)
4348
{
49+
$message = ($pretty_print) ? print_r($message, true) : $message;
50+
4451
// If there is a listener for the log event, we'll delegate the logging
4552
// to the event and not write to the log files. This allows for quick
4653
// swapping of log implementations for debugging.
@@ -75,11 +82,18 @@ protected static function format($type, $message)
7582
*
7683
* // Write a "warning" message to the log file
7784
* Log::warning('This is a warning!');
85+
*
86+
* // Log an arrays data
87+
* Log::info(array('name' => 'Sawny', 'passwd' => '1234', array(1337, 21, 0)), true);
88+
* //Result: Array ( [name] => Sawny [passwd] => 1234 [0] => Array ( [0] => 1337 [1] => 21 [2] => 0 ) )
89+
* //If we had omit the second parameter the result had been: Array
7890
* </code>
7991
*/
8092
public static function __callStatic($method, $parameters)
8193
{
82-
static::write($method, $parameters[0]);
94+
$parameters[1] = (empty($parameters[1])) ? false : $parameters[1];
95+
96+
static::write($method, $parameters[0], $parameters[1]);
8397
}
8498

8599
}

0 commit comments

Comments
 (0)