PHPackages                             alexya-framework/logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. alexya-framework/logger

ActiveFramework[Framework](/categories/framework)

alexya-framework/logger
=======================

Alexya's Logger

3.0.5(9y ago)0661GNUPHPPHP &gt;=7.0

Since Aug 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/AlexyaFramework/Logger)[ Packagist](https://packagist.org/packages/alexya-framework/logger)[ RSS](/packages/alexya-framework-logger/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (8)Used By (1)

Logger
======

[](#logger)

Alexya's logger componets

Contents
--------

[](#contents)

- [Abstract logger](#abstract_logger)
- [File logger](#file_logger)
- [Database logger](#database_logger)

Abstract logger
---------------

[](#abstract-logger)

`\Alexya\Logger\AbstractLogger` is the base class for all different loggers available. It is the class that checks which messages can be logged and formats them.

Its constructor accepts the following parameters:

- A string being the format that each log message will have.
- An array with the log levels that the logger can log.

The string parameter can contain placeholders for formatting the message, this are the available placeholders:

- `{YEAR}`, current year.
- `{MONTH}`, current month.
- `{DAY}`, current day.
- `{HOUR}`, current hour.
- `{MINUTE}`, current minute.
- `{SECOND}`, current second.
- `{SERVER_NAME}`, server's name (`localhost`, `test.com`...).
- `{CALLING_FUNCTION}`, the function that called the logger.
- `{CALLING_FILE}`, the file that called the logger.
- `{CALLING_LINE}`, the line that called the logger.
- `{CALLING_CLASS}`, the class that called the logger.
- `{CALLING_TYPE}`, `->` if the logger was called by an object, `::` if it was called statically.
- `{LEVEL}`, the level on which the log has been called.
- `{LOG}`, the string to log.

If the string is empty the logger will use `[{HOUR}:{MINUTE}] ({LEVEL}) {LOG}` as format.

The array parameter contains the levels that the logger can log, if it's empty it will log all levels. This are supported levels:

- `emergency`
- `alert`
- `critical`
- `error`
- `warning`
- `notice`
- `info`
- `debug`

The class `\Psr\Log\LogLevel` contains the constants definitions for all levels.

The `log` method will first see if the log message can be logged and then format it (if it can be logged), it accepts three parameters:

- A string being the level on which the message should be logged.
- A string being the message to log (can contain placeholders).
- An array containing custom placeholders.

If the level isn't any of the costants defined in `\Psr\Log\LogLevel` it will throw an exception of type `\Psr\Log\InvalidArgumentException`.

All classes that extends this class must implement the method `_write` which will write the log message to wherever the child class wants. It accepts as parameter the formatted message and an the placeholders array:

```
