Skip to content

Latest commit

 

History

History
145 lines (93 loc) · 4.05 KB

README.md

File metadata and controls

145 lines (93 loc) · 4.05 KB

Easily debug Laravel apps

Latest Version on Packagist GitHub Tests Action Status Total Downloads

This package can send messages to the Timber app.

timber('hi there!')
timber('I am big and green')->green()->large()

Here's how that looks like in the app.

TODO: add screenshot

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-timber

You can publish and run the migrations with:

You can publish the config file with:

php artisan vendor:publish --provider="Spatie\Timber\TimberServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    /*
     * When enabled, all things logged to the application log
     * will be sent to Timber as well.
     */
    'send_log_calls_to_timber' => true,

    /*
     * The port number to communicate with Timber.
     */
    'port' => 23517,
];

Usage

You can pass any variable you want to timber:

timber('a string', ['an array'], new MyClass)

All arguments will be converted to strings and will be sent to Timber.

Enabling and disabling logging

You can disable sending to Timber by calling disable.

timber('foo'); // will be sent to Timber

timber()->disable();

timber('bar') // will not be sent to Timber

timber()->enable();

timber('baz'); // will be sent to Timber

You can pass a boolean to enable. This can be handy when you want to log only one iteration of a loop.

foreach (range(1, 3) as $i) {
   // only things in the third iteration will be sent to Timber
   timber()->enable($i === 3);
    
   timber('we are in the third iteration');
}

Logging queries

You can send all queries to Timber using logQueries.

timber()->logQueries(); // all queries after this call will be sent to Timber

If you wish to stop logging queries, call stopLoggingQueries.

timber()->stopLoggingQueries(); // all queries after this call will not be sent to Timber anymore

Alternatively to manually starting and stopping listening for queries, you can also pass a closure to logQueries. Only the queries executed inside the closure will be sent to Timber.

timber()->logQueries(function() {
    $this->mailAllUsers(); // all queries executed in this closure will be sent to Timber
}); 

User::get(); // this query will not be sent to Timber

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.