Download the PHP package ravols/lara-logs-toolkit without Composer

On this page you can find all versions of the php package ravols/lara-logs-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lara-logs-toolkit

Lara Logs Toolkit

A Laravel package that helps you track deployments and monitor log file growth by providing deployment markers and log record counting capabilities.

Problems This Package Solves

Problem 1: Log Files Filling Up After Deployment

The Issue: After a deployment, your logs might start filling up with errors, but if you're distracted or not actively monitoring, you might miss critical issues until they become severe.

The Solution: This package provides a command to quickly check how many log records exist in any specified log channel from your config/logging.php. Run it after deployments or set it up in monitoring to get instant visibility into log growth.

Extended Possibilities: You can create your own custom commands that check for new log records and send notifications (Slack, email, or SMS) when a threshold is met. This allows you to set up automated alerting that triggers when log growth exceeds acceptable levels after deployments.

Problem 2: When Did Errors Occur?

The Issue: When you see errors in your logs, it's often impossible to tell if they happened before or after your latest deployment. This makes debugging much harder, especially when you need to determine if a deployment introduced new issues.

The Solution: This package automatically logs a timestamp marker whenever composer dump-autoload finishes. By adding a single line to your composer.json, you'll have clear deployment markers in your logs, making it easy to see which errors occurred before or after each deployment.

Installation

You can install the package via composer:

Configuration

Publish the configuration file:

This will create config/lara-logs-toolkit.php where you can configure the composer dump-autoload log channel and cache settings:

Configuration Options:

Usage

Deployment Tracking

To automatically log when composer dump-autoload finishes, you need to add the command to your composer.json file.

Step 1: Open your composer.json file in the root of your Laravel project.

Step 2: Find the scripts section. If it doesn't exist, create it at the root level of your JSON.

Step 3: Add or update the post-autoload-dump array. Add "@php artisan lara-logs:composer-dump-autoload" as the last item in the array.

Example - of a post-autoload-dump script:

Important: The line "@php artisan lara-logs:composer-dump-autoload" should be added as the last item in the post-autoload-dump array, after the existing Laravel commands.

Now, every time you run composer dump-autoload (which happens automatically during deployments), you'll see a log entry like:

This creates a clear marker in your logs, making it easy to identify which errors occurred before or after each deployment.

Checking Log Record Counts

To check how many log records exist in a specific channel:

If no channel is specified, it defaults to daily.

Examples:

The command will output:

This is especially useful after deployments to quickly see if error counts have increased, or you can integrate it into your monitoring/alerting system.

Deleting Log Records

To delete log records from configured log channels:

Options:

Examples:

Interactive Features:

Safety Features:

Delete Actions:

Comparing Log Analysis with Cached Results

The package provides a method to compare current log analysis with previously cached results. This is useful for detecting changes in log counts over time:

The method automatically caches the current analysis results for comparison on the next call. The cache TTL is configurable via config/lara-logs-toolkit.php using the comparison_cache_ttl key (default: 600 seconds).

Return Type: LogAnalysisComparisonData containing:

LogCountsData Properties:

Analyzing All Log Channels

You can analyze all log channels at once using getAllChannelsLogAnalysis(). This method automatically excludes certain channels by default (like stack, null, single, daily, etc.) but allows you to customize which channels to include or exclude.

Default Excluded Channels: single, daily, null, papertrail, stderr, syslog, errorlog, slack, emergency

AllChannelsLogAnalysisData Methods:

Creating Custom Alert Commands

You can create your own commands that monitor log growth and send notifications when thresholds are exceeded. Here's an example:

You can then schedule this command in your app/Console/Kernel.php:

LogCountsData

Represents log counts for all log levels. Provides readonly properties for direct access to log level counts.

Properties:

Methods:

Example:

LogAnalysisComparisonData

Represents a comparison between current and cached log analysis results.

Properties:

Helper Methods:

Example:

API Reference

Available Methods

The LaraLogsToolkit class provides the following methods:

getLogAnalysis(LoggerInterface $logger): LogCountsData

Analyzes logs and returns a LogCountsData with detailed log counts by level.

getLogAnalysisComparison(LoggerInterface $logger): LogAnalysisComparisonData

Compares current log analysis with cached results and returns a LogAnalysisComparisonData containing:

The results are automatically cached for the next comparison. Cache TTL is configurable.

LogAnalysisComparisonData Helper Methods:

getAllChannelsLogAnalysis(bool $useCache = false): AllChannelsLogAnalysisData

Analyzes all log channels defined in config/logging.php (excluding default excluded channels) and returns an AllChannelsLogAnalysisData DTO with aggregated results.

Default Excluded Channels: single, daily, null, papertrail, stderr, syslog, errorlog, slack, emergency

Parameters:

Chainable Configuration Methods:

AllChannelsLogAnalysisData Methods:

Example with aggregated totals:

getLastError(string $channel = 'stack', bool $withStackTrace = false): ?string

Retrieves the last error message from a specific log channel. By default, returns only the error message without the stack trace.

Parameters:

Returns: string|null - The last error message (or full error with stack trace), or null if no error is found

Example:

getLastRecord(string $channel = 'stack', bool $withStackTrace = false): ?string

Retrieves the last log record from a specific channel, regardless of log level (ERROR, INFO, WARNING, etc.). Useful for getting the most recent log entry of any type.

Parameters:

Returns: string|null - The last log record (or full entry with stack trace), or null if no record is found

Example:

Tinker Helper Functions

The package provides convenient helper functions for use in artisan tinker. These functions allow you to quickly access the last error and last record methods without using the facade or dependency injection.

lastError(string $channel = 'stack', bool $withStackTrace = false): ?string

Helper function to get the last error from a specific log channel. This is a convenience wrapper around LaraLogsToolkit::getLastError().

Note: This function is intended for use in artisan tinker only.

Parameters:

Returns: string|null - The last error message (or full error with stack trace), or null if no error is found

Example in Tinker:

lastRecord(string $channel = 'stack', bool $withStackTrace = false): ?string

Helper function to get the last log record from a specific channel, regardless of log level. This is a convenience wrapper around LaraLogsToolkit::getLastRecord().

Note: This function is intended for use in artisan tinker only.

Parameters:

Returns: string|null - The last log record (or full entry with stack trace), or null if no record is found

Example in Tinker:

Available Commands

Changelog

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

License

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


All versions of lara-logs-toolkit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ravols/lara-logs-toolkit contains the following files

Loading the files please wait ...