An artisan command to tail your application logs

Last update: Jun 16, 2022

Easily tail your logs

Latest Version GitHub Workflow Status Software License Total Downloads

This package offers an artisan command to tail the application log. It supports daily and single logs on your local machine.

To tail the log you can use this command:

php artisan tail

It can also tail logs on other environments:

php artisan tail production

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

You can publish the config file with:

php artisan vendor:publish --provider="Spatie\Tail\TailServiceProvider"

This is the contents of the file that will be published at config/tail.php:

return [
    'production' => [
        
        /*
         * The host that contains your logs.
         */
        'host' => env('TAIL_HOST_PRODUCTION', ''),

        /*
         * The user to be used to SSH to the server.
         */
        'user' => env('TAIL_USER_PRODUCTION', ''),

        /*
         * The path to the directory that contains your logs.
         */
        'log_directory' => env('TAIL_LOG_DIRECTORY_PRODUCTION', ''),

        /*
         * The filename of the log file that you want to tail.
         * Leave null to let the package automatically select the file.
         */
        'file' => env('TAIL_LOG_FILE_PRODUCTION', null),
        
    ],
];

Usage

To tail the local log you can use this command:

php artisan tail

You can start the output with displaying the last lines in the log by using the lines-option.

php artisan tail --lines=50

By default, the most-recently modified file in the directory will be used. You can specify the file that you would like to tail by using the file option.

php artisan tail --file="other-file.log"

It's also possible to fully clear the output buffer after each log item. This can be useful if you're only interested in the last log entry when debugging.

php artisan tail --clear

Should you wish to filter the log to return only certain keywords then you can also use the grep feature.

php artisan tail --grep="only display lines that contain this string"

Tailing remote logs

To tail remote logs, you must first specify values for host, user, log_directory, and file keys of an environment in the tail config file.

After that you can tail that logs of an environment like this

php artisan tail production

You can also use the --clear, --file, and --lines options described above.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

This package was created because the awesome tail command present in Laravel 4 was dropped in Laravel 5. The tail command from this package is equivalent to Laravel's old one minus the remote tailing features.

License

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

GitHub

https://github.com/spatie/laravel-tail
Comments
  • 1. Add '--hide-stack-traces' option

    Took a crack at adding this option, as per Freek's tweet: https://twitter.com/freekmurze/status/1031241488427114496

    Let me know if you'd like to see any changes!

    Reviewed by aryehraber at 2018-08-19 20:03
  • 2. Prefix all shell commands with backslashes to ignore aliases

    I recently began using exa to replace ls. To make the switch easier, I aliased ls:

    $ which ls
    ls: aliased to exa --icons --classify --header --git
    

    As a result, the command this package uses to get the latest log file (ls -t) throws an error instead of listing the sorted files:

    $ ls -t
    exa: Flag -t needs a value (choices: modified, changed, accessed, created)
    To sort newest files last, try "--sort newest", or just "-snew"
    

    The package uses the ls, head, tail, and grep shell commands, and they all could potentially be aliased/overwritten on the user's system. This could break the package, and there is no way of knowing because the output is suppressed:

    image

    This PR simply adds backslashes to the beginning of each shell command so that aliases are ignored and the native shell commands are used instead.

    I can manually specify the escaped command with --file to get it to work, but it's janky and you'll only know to do it this way if you know why it's throwing the error in the first place:

    php artisan tail --file="\`\\ls -t | \\head -1\`"
    

    Thanks!

    Reviewed by squatto at 2021-06-30 22:37
  • 3. Fix filter argument order

    Hopefully this one does the trick!

    As mentioned in the comments of the previous PR, there seems to be a slight limitation when mixing the --lines & --hide-stack-traces options. What seems to happen is tail -n [num] selects the log file lines before the filter is applied, so when using tail -n 50, for example, fewer lines might be output because the stack traces will be filtered from those 50 lines.

    Perhaps someone else can find a way around this, but I don't know if it's possible natively using tail's own options.

    Reviewed by aryehraber at 2018-08-20 20:32
  • 4. Laravel 8.x Compatibility

    This is an automated pull request from Shift to update your package code and dependencies to be compatible with Laravel 8.x.

    Before merging, you need to:

    • Checkout the l8-compatibility branch
    • Review all comments for additional changes
    • Thoroughly test your package

    If you do find an issue, please report it by commenting on this PR to help improve future automation.

    Reviewed by laravel-shift at 2020-09-08 02:51
  • 5. Refactor the registration to work with Laravel 5.4

    This PR seeks to resolve the error encountered in #7 with Laravel 5.4

    I am not 100% sure if this is the best possible fix, but it follows the way that Laravel Dusk does its registration and it works on my Laravel 5.4 install.

    Let me know how this looks!

    Cheers :)

    Reviewed by jkudish at 2017-01-20 00:22
  • 6. Add file option

    I've had a number of instances where I needed to tail a specific log file (for example, I log third-party API calls to a different file for each service). This PR adds a --file option that lets you specify the file that you want to tail, rather than only being able to see the last-modified file in the directory.

    The relevant test was added, and I updated the readme to describe the use case and usage. I also added a config value to allow the file to specified per-environment (optional, of course).

    Please let me know any feedback or requested changes. Thank you!

    Reviewed by squatto at 2020-10-01 06:48
  • 7. fix --grep option

    Without the equal sign I get an error The "--grep" option does not accept a value. But the tests still pass which is incorrect.

    From Laravel Docs: https://laravel.com/docs/7.x/artisan#options-with-values

    Next, let's take a look at an option that expects a value. If the user must specify a value for an option, suffix the option name with a = sign:

    Reviewed by ilzrv at 2020-06-06 13:09
  • 8. Updates required packages to remove 5.5-dev references.

    Composer.json file still had references to 5.5-dev that is preventing installation.

    Updated to:

        "require": {
            "php" : "^7.0",
            "illuminate/support": "^5.5",
            "illuminate/console": "^5.5",
            "symfony/process": "^3.3"
        },
    
    Reviewed by faasie at 2017-08-30 14:30
This package connects a Laravel Octance application with Tideways for PHP Monitoring, Profiling and Exception Tracking.

Tideways Middleware for Laravel Octane This package connects a Laravel Octance application with Tideways for PHP Monitoring, Profiling and Exception T

Jan 6, 2022
Php Debugger to run in terminal to debug your code easily.
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source lib to make a debug in php direct in terminal, without necessary configure an IDE. Th

May 20, 2022
Generate Laravel test factories from your existing models

Laravel Test Factory Generator php artisan generate:model-factory This package will generate factories from your existing models so you can get starte

Jul 2, 2022
Clockwork - php dev tools in your browser - server-side component
Clockwork - php dev tools in your browser - server-side component

Clockwork is a development tool for PHP available right in your browser. Clockwork gives you an insight into your application runtime - including requ

Jun 29, 2022
Test your routes without hassle
Test your routes without hassle

Laravel Api Tester Live demo Try it out: laravel-api-tester.asva.by Docs Those are short and easy to read. Take a look. Interface FAQ Installation Req

Jun 22, 2022
Ray server is a beautiful, lightweight php app build on Laravel that helps you debug your app. It runs without installation on multiple platforms.
Ray server is a beautiful, lightweight php app build on Laravel that helps you debug your app. It runs without installation on multiple platforms.

RayServer is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app. It runs without installation on multiple platforms.

Jun 28, 2022
Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app.
Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app.

A server for debugging more than just Laravel applications. Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps d

Jun 28, 2022
Php Debugger to run in terminal to debug your code easily.
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source library that allows a developer to debug in php direct in terminal, without necessary

May 20, 2022
A simple Craft module, inspired by Mildly Geeky's "Kint", to debug Twig within your browser
A simple Craft module, inspired by Mildly Geeky's

A simple Craft module, inspired by Mildly Geeky's "Kint", to debug Twig within your browser

Feb 2, 2022
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.

Dispatcher Dispatcher allows you to schedule your artisan commands within your Laravel project, eliminating the need to touch the crontab when deployi

Jun 22, 2022
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.

Dispatcher Dispatcher allows you to schedule your artisan commands within your Laravel project, eliminating the need to touch the crontab when deployi

Jun 22, 2022
An event stream library based on tail

TailEventStream An event stream library based on tail. Note: I don't think you should use this library in a real project, but it's great for education

Feb 19, 2022
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

May 27, 2022
📝 Artisan Menu - Use Artisan via an elegant console GUI
📝 Artisan Menu - Use Artisan via an elegant console GUI

?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

Mar 9, 2022
📝 Artisan Menu - Use Artisan via an elegant console GUI
📝 Artisan Menu - Use Artisan via an elegant console GUI

?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

Mar 9, 2022
Runs artisan command in web application
Runs artisan command in web application

Laravel Terminal Installation composer require recca0120/terminal --dev OR Add Presenter to your composer.json file: "require-dev": { "recca0120/t

Jun 25, 2022
Backup your laravel database by a simple artisan command

Backup your laravel database by a simple artisan command This package will allow you to backup your laravel app database and you can also choose to se

Feb 10, 2022
Your performance & security consultant, an artisan command away.
Your performance & security consultant, an artisan command away.

Enlightn A Laravel Tool To Boost Your App's Performance & Security Introduction Think of Enlightn as your performance and security consultant. Enlight

Jun 25, 2022
Tango is a command-line tool for analyzing access logs 💃
Tango is a command-line tool for analyzing access logs 💃

Tango Tool to get insights from the server access logs Tango is a dependency-free command-line tool for analyzing access logs ?? Currently, work on th

May 24, 2022