Send your Laravel/Lumen application logs straight to a Google Chat (Google Workspace) space via incoming webhooks.
theriddleofenigma/laravel-google-chat-log is a Laravel package for send your laravel/lumen application logs straight to a google chat (google workspace) space via incoming webhooks..
It currently has 24 GitHub stars and 74.121 downloads on Packagist (latest version v3.0.0).
Install it with composer require theriddleofenigma/laravel-google-chat-log.
Discover more Laravel packages by theriddleofenigma
or browse all Laravel packages to compare alternatives.
Last updated
♥ Made with <love/> And I love <code/>
Send your Laravel/Lumen application logs straight to a Google Chat space [Google Workspace, formerly GSuite] via incoming webhooks.
^8.2 (Laravel 13 requires PHP 8.3+)illuminate/support ^11.0|^12.0|^13.0)For Laravel 10 use
^2.x. For Laravel 9 or lower use^1.x.
composer require theriddleofenigma/laravel-google-chat-log
The package ships with Laravel package auto-discovery, so the service provider
is registered for you and it automatically adds a google-chat logging
channel. In most cases the only thing you need to do is set the webhook url:
LOG_GOOGLE_CHAT_WEBHOOK_URL=https://chat.googleapis.com/v1/spaces/XXXX/messages?key=...&token=...
Then log to the channel:
use Illuminate\Support\Facades\Log;
Log::channel('google-chat')->error('Something went wrong');
To route your default log stack through Google Chat, add google-chat to the
stack channel in config/logging.php, or set LOG_CHANNEL=google-chat.
The channel is registered with sensible defaults, but anything you define in
your application's config/logging.php always takes precedence. You can
publish the channel definition to tweak it:
php artisan vendor:publish --tag=google-chat-log-config
Or define it manually in the channels array of config/logging.php:
'google-chat' => [
'driver' => 'monolog',
'handler' => \Enigma\GoogleChatHandler::class,
'url' => env('LOG_GOOGLE_CHAT_WEBHOOK_URL'),
'level' => env('LOG_LEVEL', 'debug'),
'notify_users' => [
'default' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_DEFAULT'),
'emergency' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_EMERGENCY'),
'alert' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_ALERT'),
'critical' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_CRITICAL'),
'error' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_ERROR'),
'warning' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_WARNING'),
'notice' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_NOTICE'),
'info' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_INFO'),
'debug' => env('LOG_GOOGLE_CHAT_NOTIFY_USER_ID_DEBUG'),
],
],
Lumen: make sure
$app->withFacades();is uncommented inbootstrap/app.php, and registerEnigma\GoogleChatLogServiceProvider.
You can provide the eight logging levels defined in the
RFC 5424 specification: emergency,
alert, critical, error, warning, notice, info, and debug.
Set multiple Google Chat webhook urls as a comma separated value for the
LOG_GOOGLE_CHAT_WEBHOOK_URL env variable (or as an array in the channel
config) and every space receives the log.
@mentionNotify a specific user by setting the corresponding user id. Ids mapped under
LOG_GOOGLE_CHAT_NOTIFY_USER_ID_DEFAULT are notified for all log levels:
LOG_GOOGLE_CHAT_NOTIFY_USER_ID_DEFAULT=1234567890
To find a USER_ID, right-click the user icon of the person you want to
notify in Google Chat and select inspect. On the div element find the
data-member-id attribute — the id is the value in
data-member-id="user/human/{USER_ID}".
To notify everyone (@all), set LOG_GOOGLE_CHAT_NOTIFY_USER_ID_DEFAULT=all.
Multiple ids can be provided as a comma separated value, and each log level can
target different users via its matching LOG_GOOGLE_CHAT_NOTIFY_USER_ID_* env
variable.
Append extra key-value pairs to every Google Chat message by assigning a
closure to GoogleChatHandler::$additionalLogs. The closure receives the
current Monolog\LogRecord and must return an array:
use Enigma\GoogleChatHandler;
use Monolog\LogRecord;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
GoogleChatHandler::$additionalLogs = function (LogRecord $record) {
return [
'tenant' => request()->user()?->tenant->name,
'request' => request()->fullUrl(),
];
};
}
}
Non-string values are JSON encoded automatically.
composer test # run the PHPUnit suite
composer lint # check code style with Laravel Pint
composer format # fix code style automatically
Contributions are welcome — please read the contributing guide first. For security issues, see the security policy.
Copyright © Kumaravel
Laravel Google Chat Log is open-sourced software licensed under the MIT license.