Upgrading from 2.x

Log Viewer v3 introduces multiple log types, as well as the ability to register additional log types. You can read more about Log Types here.

This required some parts to be rewritten from scratch, thus breaking the public API from v2. In this short guide you will learn what changed and how you can prepare for the upgrade.

Upgrade time: 5 minutes

Update composer.json

Update your composer.json file with the new Log Viewer version requirement:

"require": {     // ...-    "opcodesio/log-viewer": "^2.0"+    "opcodesio/log-viewer": "^3.0"},

Then, run composer update to update Log Viewer to the latest version.

Then, run php artisan log-viewer:publish to publish the updated front-end assets.

Changes to config/log-viewer.php

If you have previously published the configuration file for Log Viewer, there are only 2 small changes you might need to make.

Updated: include_files config option

Log Viewer v3 now supports a few extra log types by default:

  • Redis
  • Supervisor
  • Apache access & error
  • Nginx access & error
  • Postgres

To take advantage of this new feature, you should add additional paths to your include_files attribute, which contain logs for the above services.

Here is an example of how you may want to update your config/log-viewer.php configuration:

    /*    |--------------------------------------------------------------------------    | Include file patterns    |--------------------------------------------------------------------------    |    */    'include_files' => [        '*.log',        '**/*.log',        // You can include paths to other log types as well, such as apache, nginx, and more.        '/var/log/httpd/*',        '/var/log/nginx/*',        // MacOS Apple Silicon logs        '/opt/homebrew/var/log/nginx/*',        '/opt/homebrew/var/log/httpd/*',        '/opt/homebrew/var/log/php-fpm.log',        '/opt/homebrew/var/log/postgres*log',        '/opt/homebrew/var/log/redis*log',        '/opt/homebrew/var/log/supervisor*log',        // '/absolute/paths/supported',    ],    

Removed: patterns config option

The ability to configure the regex pattern for matching Laravel logs has now been moved to the Laravel-specific log file.

If you would like to override the regex used for Laravel logs, or any other log types included with Log Viewer, please create (extend) your custom Log class.

Added: Gzipped indices

Log Viewer keeps a cached index of the log files for faster navigation. This helps immensely to speed up the navigation after the file has been indexed.

For a large log file, such as 4GB Nginx access log, the index itself could grow into 600-700 MB range. For a 4 GB Laravel logs file, the index could grow into 100-200 MB size.

To reduce that, Log Viewer can compress the indices before storage, which results in 3-4x smaller indices. Log Viewer will automatically apply compression if it detects the zlib extension in PHP, which is recommended.

Log reader changes

The rest of the guide only applies to you if you were overriding Log Viewer classes, or if you were using Log Viewer to programmatically read your logs.

If you only used Log Viewer via its provided UI, then you are now done with the upgrade!

Some of the code was refactored, moved to different namespaces, and otherwise improved. If you used Log Viewer to programmatically access/process logs, such as LogViewer::getFiles()->first()->logs()->..., you should know the following changes.

Logs

Breaking changes.

The previous Opcodes\LogViewer\Log class has now been moved to Opcodes\LogViewer\Logs\LaravelLog to explicitly represent a Laravel log instance.

More log classes have been added for various other types of logs, such as Horizon, Redis, Postgres, etc. You can read about the available log classes here.

All log classes extend the Opcodes\LogViewer\Logs\Log base class. Please check the updated class methods/properties.

Log files

No breaking changes.

Custom log file class can now be used by extending the Opcodes\LogViewer\LogFile class and calling Opcodes\LogViewer\Facades\LogViewer::useLogFileClass(string $class) method to use your custom log file class instead of the default one.

Log Reader

Breaking changes.

The previous Opcodes\LogViewer\LogReader class has been moved to Opcodes\LogViewer\Readers\IndexedLogReader to signify its use of indices to speed up further reads.

The previous Opcodes\LogViewer\MultipleLogReader class has been moved to Opcodes\LogViewer\Readers\MultipleLogReader.

Custom log readers are now possible by extending the Opcodes\LogViewer\Readers\BaseLogReader class and calling Opcodes\LogViewer\Facades\LogViewer::useLogReaderClass(string $class) method to use your custom log reader class instead of the default one.

Support

If you have any questions, feedback, or need any help setting up Log Viewer within your project, feel free to reach out via GitHub Discussions or GitHub Issues .