Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spatie/laravel-log-dumper
A function to dump anything to the log
https://github.com/spatie/laravel-log-dumper
development dump laravel log
Last synced: 5 days ago
JSON representation
A function to dump anything to the log
- Host: GitHub
- URL: https://github.com/spatie/laravel-log-dumper
- Owner: spatie
- License: mit
- Created: 2020-04-02T20:11:48.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-02T10:06:08.000Z (9 months ago)
- Last Synced: 2024-12-21T18:07:34.795Z (12 days ago)
- Topics: development, dump, laravel, log
- Language: PHP
- Homepage: https://spatie.be/open-source
- Size: 82 KB
- Stars: 115
- Watchers: 7
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# A function to dump anything to the log
[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-log-dumper.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-log-dumper)
[![run-tests](https://github.com/spatie/laravel-log-dumper/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-log-dumper/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-log-dumper.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-log-dumper)This package contains a function `ld`. Any argument you pass to it will be dumped to the log. You can pass any kind of value to it.
```php
ld('a string', ['an array'], new Class());
```Under the hood, Symfony's `VarDumper` is used to create string representations.
## Support us
[](https://spatie.be/github-ad-click/laravel-log-dumper)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Installation
You can install the package via composer:
```bash
composer require spatie/laravel-log-dumper
```## Usage
You can pass any variable you want to `ld`.
```php
ld('a string', ['an array'], new Class());
```All arguments will be converted to strings and will be written to the application log using the `info` level.
## Using other log levels
If you want to use another log level, you can just call the method you want on `ld`. You can pass these methods any type of argument and any number of arguments. They will all be logged.
```php
// logs using the `error` level
ld()->error('a string', ['an array'], new Class())
```Of course, you can mix and chain different levels.
```php
ld()
->debug('Debug info', ['an array'])
->error('Error info', new Class);
```## Enabling and disabling logging
You can disable logging by calling `disable`.
```php
ld('foo'); // will be loggedld()->disable();
ld('bar'); // will not be logged
ld()->enable();
ld('baz'); // will be logged
```You can pass a boolean to `enable`. This can be handy when you want to log only one iteration of a loop.
```php
foreach (range(1, 3) as $i) {
// only things in the third iteration will be logged
ld()->enable($i === 3);ld('we are in the third iteration');
}
```## Logging queries
You can log all queries with `logQueries`.
````php
ld()->logQueries(); // all queries after this call will be logged
````If you wish to stop logging queries, call `stopLoggingQueries`.
````php
ld()->stopLoggingQueries(); // all queries after this call will not be logged 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 logged.
````php
ld()->logQueries(function() {
$this->mailAllUsers(); // all queries executed in this closure will be logged
});User::get(); // this query will not be logged
````## Testing
``` bash
composer test
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security
If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker.
## Credits
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.