April 14, 2018 —John Koster
The info
helper will write an information entry into Laravel's log files. It allows a $message
to be set, as well as an optional $context
(which is an array of data). While the $context
must be an array, the actual elements of the array do not have to be arrays themselves.
The signature of the info
function is:
1function info(2 $message,3 $context = []4);
The following example shows the usage of the info
helper. An example of what the function calls would produce in the log files follows the code examples.
1// An example message context. 2$context = ['name' => 'John Doe', 'email' => 'you@homestead']; 3 4// A log message without context. 5info('This is a log message without context'); 6 7// A log message where the context is an array. 8info('This is a log message', $context); 9 10// A log message where the context is an array of objects.11info('This is another log message', [(object) $context]);
The above code would produce results similar to the following (some lines have been indented to prevent wrapping and improve readability):
1... 2[2015-06-15 02:14:43] local.INFO: 3 This is a log message without context 4[2015-06-15 02:14:43] local.INFO: 5 This is a log message 6 {"name":"John Doe","email":"you@homestead"} 7[2015-06-15 02:14:43] local.INFO: 8 This is another log message 9 [10 "[object] (stdClass: {\"name\":\"John Doe\",11 \"email\":\"you@homestead\"})"12 ]13...
The following method calls are all equivalent:
1use Illuminate\Support\Facades\Log; 2 3app('info')->info('Log an informative message'); 4 5resolve('info')->info('Log an informative message'); 6 7info('Log an informative message'); 8 9log()->info('Log an informative message');10 11Log::info('Log an informative message');
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.