Aller au contenu
← Retour aux projets

Laravel Teams Logging

Software License Total Downloads Version Maintained Framwork

#Laravel Teams Logging

A Laravel logging channel that sends application log messages directly to Microsoft Teams using an Incoming Webhook.

#Features

  • Supports Laravel and Lumen
  • Supports all Laravel log levels
  • Compatible with Laravel's stack logging channel
  • Two message styles:
    • Simple – lightweight notifications
    • Card – rich formatted messages with context
  • Application/project name (Optional)

#Installation

Install the package via Composer:

composer require zanysoft/laravel-teams-logging

#Laravel

Register the service provider in config/app.php if required:

ZanySoft\LaravelTeamsLogging\LoggerServiceProvider::class,

Publish the configuration file:

php artisan vendor:publish --provider="ZanySoft\LaravelTeamsLogging\LoggerServiceProvider"

#Lumen

Register the service provider in bootstrap/app.php:

$app->register(
    ZanySoft\LaravelTeamsLogging\LoggerServiceProvider::class
);

Copy the package configuration file to your application's config directory, then enable it in bootstrap/app.php:

$app->configure('teams');

#Configuration

Create a custom logging channel in config/logging.php:

'teams' => [
    'driver' => 'custom',
    'via'    => ZanySoft\LaravelTeamsLogging\LoggerChannel::class,
    'level'  => 'debug',
    'url'    => env('TEAMS_WEBHOOK_URL')
],

#Environment

Add folloing details to your .env file:

  • Message title (default value is APP_NAME)
  • Message style (default simple).
  • Microsoft Teams Incoming Webhook URL
TEAMS_MESSAGE_TITLE=
TEAMS_MESSAGE_STYLE=simple
TEAMS_WEBHOOK_URL=https://...

For instructions on creating an Incoming Webhook, refer to the Microsoft Teams documentation.

#Message Styles

The package supports two message styles:

Simple (Default)

Sends only the log message. (no context)

Log::channel('teams')->error('Something went wrong.');

Card

Displays a rich Teams card containing:

  • Log level
  • Message
  • Timestamp
  • Application name
  • Additional log context
Log::channel('teams')->error(
    'Unable to process payment.',
    [
        'order_id' => 1452,
        'customer' => 'John Doe',
    ]
);

#Usage

Log a simple message:

Log::channel('teams')->error('Something went wrong.');

Log a message with additional context:

Log::channel('teams')->error(
    'Unable to process payment.',
     [
        'name'  => 'value',
        'order_id' => 1452,
        'amount'   => 49.99,
     ]
);

Note: Log context is only included when using the card style.

#Using the Stack Channel

To automatically send all application logs to Microsoft Teams, add the teams channel to your default logging stack:

'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => [
            'single',
            'teams',
        ],
    ],
],

#Screenshots

Examples of log messages displayed in Microsoft Teams using the card style.

#Debug

Debug

#Error

Error

#Warning

Warning

#Critical

Critical

#License

This package is open-source software licensed under the MIT License.

See the LICENSE file for more information.

Nouvelle version disponible.