Download the PHP package devdot/monolog-parser without Composer

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

Monolog Parser

Test Automation

A library for parsing monolog logfiles.

This library is compatible with Monolog 2 and provides parse options for multiline logs and Laravel logfiles.

Installation

Install the library using composer:

Basic Usage

Example for parsing a logfile test.log using the default options:

You can create a new Parser object by using the static function new as well:

Documentation

Parser instance

Create new Parser instances:

For parameters, see Method Reference.

Most methods return the Parser instance itself, allowing the calls to be chained in one line as seen in the examples below.

Every Parser is meant to be linked to only one file, however that is not a hard restriction and depends on your usage.

Files and Ready State

The parser has to be provided a filename (or a string, see constructor or with setFile. Check, whether a parser is ready with isReady:

Parsing

Parsing happens either when parse or get are called. The Parser object will store the results and return them from cache when get is called unless parse is called again directly or clear is called.

Clear the cached records:

Parse a string instead of a file:

Log Records

The log records are returned as a Log object by get. The Log is a readonly array containing the records of type LogRecord. These objects are readonly too and can be accessed like this:

You may also access the LogRecord properties like array keys: $record['datetime'] instead of $record->datetime.

For reference, Monolog log records look like this:

Patterns

Besides the default pattern, there are other patterns provided as listed below. Patterns have to have named subpatterns to work correctly. You can set any pattern like this:

Parsing Options

The parsing process can be modified with the following options:

Option Description
OPTION_SORT_DATETIME Sort the records by their timestamps in descending order.
OPTION_JSON_AS_TEXT Return the JSON of context and extra as string instead of decoded JSON. Use this option if your logfiles have context or extra fields that cannot be decoded with json_decode. Has priority over OPTION_JSON_FAIL_SOFT.
OPTION_JSON_FAIL_SOFT Return the JSON of context and extra as string only if exceptions during JSON decode happen. Use this option if your logfiles may have context or extra fields that cannot be decoded with json_decode, or if you don't want to handle exceptions. Has priority over OPTION_SKIP_EXCEPTIONS.
OPTION_SKIP_EXCEPTIONS Skip any exceptions that occur during parsing. For example, if the JSON of context cannot be decoded, it will return null and will not throw a LogParsingException.
OPTION_NONE Reset to default options.

The options may be set like this:

Exceptions

Monolog-Parser will throw exceptions as listed below.

Limits and failing logs

If reading your logs fails, please make sure the logs are generated correctly and not listed on the list below. If files generated by the default LineFormatter pattern of Monolog fail to be parsed, please let me know and submit an issue. If you are using non-default patterns, I would still be interested to provide parse patterns if they are commonly used.

Log files or records that can (currently) not be parsed by Monolog-Parser:

Method Reference

If not stated otherwise, methods return the object $this.

Method Parameters Description
__construct string $filename: see setFile Create a new instance of Parser.
::new string $filename: see setFile Create a new instance (equivalent to __construct).
setFile string $filename: full path to a valid file Set the file at $filename. If the files does not exist, this will throw a FileNotFoundException.
setPattern string $pattern = '': regex pattern that will be used by parse. Set the pattern that will be used by parse when parsing the logfile. The regex needs to be valid PHP regex with named subpatterns (see Patterns).
setOptions int $options: options for the parser configuration. Set parsing options with the provided option flags that are listed here.
isReady Returns true when the parser is ready to parse, otherwise false. This state requires that an existing, readable file to be set.
parse string $string: optional string to be parsed instead of a file. This will parse the given string or the set file (see setFile) if $string is empty.
get bool $returnFromCache = true: optional bool to decided whether cache from previous parse or get should be returned. Get the results of the last parse. If no results exist, parse will be called internally. Set $returnFromCache to false if you do not want the records to be loaded from cache but to re-parse the file.
clear Clear the cache from previous parse and rewind the file if it was already read.

About

Requirements

License

Monolog-Parser is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This library was inspired by ddtraceweb's monolog parser and haruncpi's laravel log reader.


All versions of monolog-parser 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 devdot/monolog-parser contains the following files

Loading the files please wait ....