Laravel Helper Function: info

November 20, 2016 —John Koster

info($message, $context = [])

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 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.

3// An example message context.
4$context = ['name' => 'John Doe', 'email' => 'you@homestead'];
6// A log message without context.
7info('This is a log message without context');
9// A log message where the context is an array.
10info('This is a log message', $context);
12// A log message where the context is an array of objects.
13info('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):

2[2015-06-15 02:14:43] local.INFO: This is a log message without context
3[2015-06-15 02:14:43] local.INFO: This is a log message
4 {"name":"John Doe","email":"you@homestead"}
5[2015-06-15 02:14:43] local.INFO: This is another log message
6 [
7 "[object] (stdClass: {\"name\":\"John Doe\",\"email\":\"you@homestead\"})"
8 ]

Some absolutely amazing

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.