Download the PHP package terrazza/logger without Composer

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

Terrazza/Logger

This component is an implementation of PSR/Log standard with some extensions.

Structure

  1. the Logger component
    has to be initialized with 0-n ChannelHandler
    and provides the common known methods:
    • warning
    • error
    • notice
    • ...
  2. the ChannelHandler component
    is responsible to determine
    1. the target/writer (required)
    2. the recordFormatter (required)
    3. a channelFilter (optional)
    4. all related LogHandler for this channel
  3. the LogHandler component
    determines
    • the logLevel
    • the format (optional, default: from ChannelHandler->recordFormatter)

The Terrazza/Logger component differ to the common PSR/Log implementation in handling the "Format". The Writer Component handles multiple "rows" and combines it. Within this difference its possible to forward a transformed format and keep his keys per row.
For example: write the message/format into a json object or db.

Object/Classes

  1. Logger
    1. method: registerChannelHandler
    2. method: registerExceptionHandler
    3. method: registerErrorHandler
    4. method: registerFatalHandler
    5. method: setExceptionFileName
    6. constructor: context (array)
  2. Handler
    1. ChannelHandler
    2. LogHandler
  3. LogRecord
    1. LogRecordTrace
  4. LogRecordFormatter
  5. LogHandlerFilter
  6. Converter
  7. Install
  8. Requirements
  9. Examples

Logger

The Logger object/methods is/are close to the common PSR implementations but!
The Logger is initialized with channelHandler(s) and not Handler

each channelHandler executes only one logHandler

method: registerChannelHandler

adds a channelHandler to the logger (not immutable).

method: registerExceptionHandler

register a callback for php exception handler.

well-developed projects should handle/cover all exceptions by themselves, but ;-)

method: registerErrorHandler

register a callback for php error handler.

sometime this kind of errors can't be catched without this workaround

method: registerFatalHandler

register a callback for php shutdown.

sometime this kind of errors can't be catched without this workaround

method: setExceptionFileName

The method:addMessage itself is covered with try/catch.
The catch handler writes the Exception.Message to a file which can be set with the method setExceptionFileName.

notice:
default: php://stderr

constructor: context (array)

The logger can be initialized, next to the name, with an initialized context.
This context can be addressed separately.

example of usage
a class is injected with the component and inside the constructor

Handler

ChannelHandler

A ChannelHandler collects LogHandler to the same channel and provides

A ChannelHandler can be registered through the Logger with

method: getWriter
method: getFormatter
method: getFilter
method: getLogHandler (LogHandlerInterface[])
method: pushLogHandler

Method to add a new LogHandler.
The logHandler-array will be key-sorted, to prevent multiple write transaction for different LogLevels.

method: getEffectedHandler

return the matched LogHandler for a given LogRecord.

method: writeRecord

for a passed LogHandler the record will be

LogHandler

The SingleHandler provides the common way to create a handler for a Logger. The only difference to the common implementation:

LogRecord

Against the common PSR implementation our component deals with an object and not an array.
LogRecord properties:

additional, the object provides

method/static createRecord

this method is used inside Logger to create a new LogRecord object.

method: getToken()

this method is used in the LogRecordFormatterInterface to get the LogRecord "encoded". Every element can be accessed through his "format" e.g. {Level}{LevelName}{Context.name}

LogRecordTrace

The LogRecordTrace object is generated in the LogRecord is created.
Base on _debug_backtrace(DEBUG_BACKTRACE_IGNOREARGS) every Record get additional properties:

LogRecordFormatter

The LogRecordFormatter converts/maps a record to an array
. Initialized properties:

NonScalarConverter (NonScalarConverterInterface)

The NonScalarConverter convert a nonScalar value (e.g. from Context) into a string.
Actually the provided class NonScalarJsonEncode use json_encode and prefix it with the attribute name.

The NonScalarConverter is used, when a formatter-line includes a nonScalar and a scalar content.

example of usage:

a ValueConverter (LogRecordValueConverterInterface) can be used to convert special value based on his key.

method: pushConverter

to map/convert a special value, based on his key, push a special converter.
This converter has to fulfill LogRecordValueConverterInterface.

method: formatRecord

Maps the Record against the $format and returns a mapped array.
Unknown patterns (e.g. {undefined}) are removed from the response.
Empty "Lines" are also removed.

example

The example uses an additional ValueConverter for the Record value "Date". `

LogHandlerFilter

LogHandler can have a LogHandlerFilter.
Properties:

Converter

A RecordFormatter
Afterwards, it depends on the target/writer the array has to be formatted again.

We actually include/provide two Converter:

FormattedRecordFlat

Converts the mapped LogRecord into a string within a delimiter for each row.
For nonScalar values we use json_encode to convert the value.

method: setNonScalarPrefix(string $delimiter)

by using this method nonScalar values will be prefixed with the dataKey and the delimiter.
arguments:

example of usage:

FormattedRecordJson

Converts the mapped LogRecord into a string by using json_encode.
arguments:

example of usage:

Writer

StreamFile

Save converted record to a file.
arguments:

the converter should convert the formatted LogRecord into a string.

How to install

Install via composer

Requirements

Examples

1. create a ChannelHandler

2. create a LogHandler

notice
next code lines depends on previous example... (create a ChannelHandler)

3. create within a handler

notice:
next code lines depends on previous example... (create a LogHandler)

create and registerChannelHandler

Usage of Logger

produce a NOTICE

produce an ERROR


All versions of logger with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
psr/log Version 1.1.*
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 terrazza/logger contains the following files

Loading the files please wait ....