Download the PHP package knotlog/knotlog without Composer

On this page you can find all versions of the php package knotlog/knotlog. 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 knotlog

Knotlog

Become a Supporter Latest Stable Version License Build Status

Wide logging for PHP

Knotlog is inspired by the ideas of loggingsucks.com and implements wide logging as a first-class pattern in PHP. Avoid the pitfalls of traditional logging by using a single structured log event that captures all relevant context of a request as a canonical log line, dramatically improving observability and debugging capabilities.

Transform debugging from archaeological grep sessions into analytical queries with structured, queryable data.

The Problem with Traditional Logging

Traditional logging is broken:

The Wide Logging Solution

Instead of asking "what is my code doing?", ask "what happened to this request?"

A proper wide event contains:

Installation

Requirements

Basic Usage

The Log class implements JsonSerializable, so it can be directly encoded to JSON for structured logging systems.

Collecting Multiple Entries

Knotlog also has an append() method that allows adding multiple values under a single key, without overwriting:

This is useful in situations where related items are populated by different parts of the codebase.

Service Logging

Additionally, Knotlog provides a LogList class that can be passed to dependencies and used to attach multiple entries under a single key. This is useful for cases where a service should be able to log multiple related items, without directly having access to the main Log instance, such as:

Then, inside the service class (Connection in this example), use the LogList to add entries:

⚠️ LogList entries MUST be objects. Complex objects SHOULD implement JsonSerializable.

The LogList maintains insertion order and will encode as a JSON array:

Exception Logging

It is not recommended to add exception objects to Knotlog. Exception tracing is better handled by other systems, such as Monolog or another PSR-3 logger.

For convenience, Log provides a hasError() method that will return true if either the exception or error keys are set in the log. This is particularly useful for determining if the log should be output when sampling is enabled.

HTTP Middleware

Knotlog provides a PSR-15 middleware to log request and response context.

Knotlog provides a middleware to log uncaught exception context and generate error responses.

Knotlog provides a middleware to flag every response with a 400+ status code as an error in the log. The error is set to the HTTP reason phrase (e.g., "Not Found", "Internal Server Error"). This is particularly useful when log sampling is in effect, ensuring that error responses are always logged.

When using these middleware, the order should be (from first to last):

⚠️ The order may depend on the application middleware stack. Some frameworks prefer a last-in-first-out order.

Console Events

Knotlog provides a Symfony Console event listener that logs command execution and error context.

If you prefer not to use the event system, you can manually log console context:

Log Writers

Knotlog provides a LogWriter interface to enable flexible output destinations for wide log events. The interface defines a contract with a single method write(Log $log): void.

FileWriter

The FileWriter writes log events to a file.

LoggerWriter

The LoggerWriter outputs log events to any PSR-3 compatible logger using message interpolation.

The writer automatically routes log events to the appropriate log level:

The entire log context is passed to the logger, allowing it to format and process the data according to its own implementation. The message key can be customized to match your logging schema.

SampledWriter

The SampledWriter is a decorator that samples log events based on a configurable rate, while always logging errors.

The sampled writer ensures that:

This is particularly useful for high-traffic applications where logging every successful request would be prohibitively expensive, while still capturing all errors for debugging.

ToggledWriter

The ToggledWriter is a decorator that allows log writing to be enabled or disabled at runtime.

This is useful for conditionally disabling log output based on runtime configuration, such as feature flags or environment-specific settings.

Log Formatters

Knotlog provides a LogFormatter interface to enable flexible formatting of log lines. The interface defines a contract with a single method format(Log $log): string.

JsonFormatter

The JsonFormatter formats log events as JSON strings. Additional flags may be passed through to json_encode:

License

MIT License, see LICENSE file for details.


All versions of knotlog with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
symfony/filesystem Version ^8.0
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 knotlog/knotlog contains the following files

Loading the files please wait ...