PHPackages                             zooxsmart/los-log - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. zooxsmart/los-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

zooxsmart/los-log
=================

LosLog provides some log utility

3.3.2(2y ago)0818↓100%MITPHPPHP ^8.2

Since Nov 1Pushed 2y agoCompare

[ Source](https://github.com/zooxsmart/los-log)[ Packagist](https://packagist.org/packages/zooxsmart/los-log)[ Docs](http://github.com/Lansoweb/LosLog)[ RSS](/packages/zooxsmart-los-log/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (32)Used By (0)

LosLog
======

[](#loslog)

[![Build Status](https://camo.githubusercontent.com/3ab99c356c8b852a9d013266213e3e0856d678dace063253a8d38ba69975bef6/68747470733a2f2f7472617669732d63692e6f72672f4c616e736f7765622f4c6f734c6f672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Lansoweb/LosLog) [![Latest Stable Version](https://camo.githubusercontent.com/fbd3dfea898eb2495c97575183a75123a5e0fa9c6c58198eea1184c521ac8195/68747470733a2f2f706f7365722e707567782e6f72672f6c6f732f6c6f736c6f672f762f737461626c652e737667)](https://packagist.org/packages/los/loslog) [![Total Downloads](https://camo.githubusercontent.com/8a58eb635668a67741cf77785514deef68eff97c89c8b3771e39e3d897a46595/68747470733a2f2f706f7365722e707567782e6f72672f6c6f732f6c6f736c6f672f646f776e6c6f6164732e737667)](https://packagist.org/packages/los/loslog) [![Coverage Status](https://camo.githubusercontent.com/e6e8377d137eaa9366fd44dde2cac497ac77e70d37a539790a7d55cb2f2c46a6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4c616e736f7765622f4c6f734c6f672f62616467652e737667)](https://coveralls.io/r/Lansoweb/LosLog) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/5417645f84cdf37ea58c0c276e5e837a272a1f0bdd7f6724fc649dcc972d2238/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c616e736f7765622f4c6f734c6f672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Lansoweb/LosLog/?branch=master) [![SensioLabs Insight](https://camo.githubusercontent.com/dfd5930890e247cb1ec0ad195b3ee26994ddd82dd2f7a9d3a9fcc78667407fd2/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f37613534323165332d353439342d346162382d626266632d3966626165333638313438642e7376673f7374796c653d666c6174)](https://insight.sensiolabs.com/projects/7a5421e3-5494-4ab8-bbfc-9fbae368148d) [![Dependency Status](https://camo.githubusercontent.com/b4c48ee8720cafa31c0dfa12e32479fc0a990e787d1db6137db6ebef7beb3092/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3534646138333466633162626264613031333030303238322f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/54da834fc1bbbda013000282)

Introduction
------------

[](#introduction)

This is the 2.0 documentation version. Please refer to the README-1.0 for 1.0 documentation.

This module provides some useful log classes:

- LosLog = An error middleware for PSR-7 compatible frameworks/applications
- HttpLog = Use to log request and response from a PSR-7 application
- ErrorLogger = PHP error
- ExceptionLogger = PHP Exception
- StaticLogger = "Shortcut" to a generic file logger. Can be attached to the Z-Ray in Zend Server
- Rollbar writer = A Rollbar writer. Uploads errors and exceptions to [Rollbar](https://rollbar.com) service

Requirements
------------

[](#requirements)

- php &gt;= 5.6.0
- laminas/laminas-stratigility
- laminas/laminas-diactoros
- laminas/laminas-log

Instalation
-----------

[](#instalation)

For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/).

```
php composer.phar require los/loslog
```

Usage
-----

[](#usage)

Copy the file loslog.global.php.dist to your config/autoload/ , rename it to loslog.global.php and change the default options, if needed.

### LosLog Middleware

[](#loslog-middleware)

#### Zend Expressive

[](#zend-expressive)

Expressive 2.0 introduced a new method to handle errors, using listeners to the ErrorHandler and delegator factories, so this is the preferable method.

Add the delegator factory to the ErrorHandler, like:

```
return [
    'dependencies' => [
        'factories' => [
            LosMiddleware\LosLog\LosLog::class => LosMiddleware\LosLog\LosLogFactory::class,
        ],
        'delegators' => [
      		ErrorHandler::class => [
            	LosMiddleware\LosLog\ErrorHandlerListenerDelegatorFactory::class,
        	],
    	],
    ],
];
```

#### General use

[](#general-use)

If using other framework, you can add the LosLogFactory to your factory system, manually create a LosLog instance or call the LosLogFactory directly.

### HttpLog Middleware

[](#httplog-middleware)

It will log requests and responses in compact or full mode. It will include X-Request-Id and X-Response-Time headers if present.

#### Zend Expressive

[](#zend-expressive-1)

Add the middleware as the first middleware in your pipeline, like:

```
return [
    'middleware_pipeline' => [
        'before' => [
            'middleware' => [
                LosMiddleware\LosLog\HttpLog::class,
            ],
            'priority' => 10000,
        ],
    ],
];
```

Set the desired options in loslog.global.php (or loslog.local.php):

```
'http_logger_file' => 'http.log',
'log_request' => true,
'log_response' => true,
'full' => false,
```

You can integrate with [los/request-id](https://github.com/Lansoweb/request-id) and [los/response-time](https://github.com/Lansoweb/response-time). The order is important, use as bellow:

```
return [
    'middleware_pipeline' => [
        'before' => [
            'middleware' => [
                LosMiddleware\RequestId\RequestId::class,
                LosMiddleware\LosLog\HttpLog::class,
                LosMiddleware\ResponseTime\ResponseTime::class
            ],
            'priority' => 10000,
        ],
    ],
];
```

This will produce:

```
2015-11-20T14:04:51+00:00 INFO (6): Request: GET /shop/v1/item/1 RequestId: 12dbf2d2-52c5-4954-b573-3aa2fee58612
2015-11-20T14:04:51+00:00 INFO (6): Response: 200 OK RequestId: 12dbf2d2-52c5-4954-b573-3aa2fee58612 ResponseTime: 14.90ms

```

### ErrorLogger

[](#errorlogger)

To enable the ErrorLogger just add the registerHandlers inside your public/index.php

#### Zend Framework 2

[](#zend-framework-2)

```
chdir(dirname(__DIR__));

require 'init_autoloader.php';

\LosMiddleware\LosLog\ErrorLogger::registerHandlers();

Laminas\Mvc\Application::init(require 'config/application.config.php')->run();
```

#### Zend Expressive

[](#zend-expressive-2)

```
chdir(dirname(__DIR__));
require 'vendor/autoload.php';

/** @var \Interop\Container\ContainerInterface $container */
$container = require 'config/container.php';

\LosMiddleware\LosLog\ErrorLogger::registerHandlers('error.log', '/tmp');

/* @var \Mezzio\Application $api */
$app = $container->get('Mezzio\Application');

$app->run();
```

You can use the logger with your phpunit tests. Just call it in your bootstrap file just after the autoload is created:

```
\LosLog\Log\ErrorLogger::registerHandlers();
```

#### Output example

[](#output-example)

```
2015-10-30T17:58:10-02:00 ERR (3): Error: Call to a member function format() on a non-object in  on line

```

The default logfile is data/log/error.log

### ExceptionLogger

[](#exceptionlogger)

To enable the ExceptionLogger just add the registerHandlers inside your public/index.php

#### Zend Framework 2

[](#zend-framework-2-1)

```
chdir(dirname(__DIR__));

require 'init_autoloader.php';

\LosMiddleware\LosLog\ExceptionLogger::registerHandlers('exception.log', '/tmp');

Laminas\Mvc\Application::init(require 'config/application.config.php')->run();
```

#### Zend Expressive

[](#zend-expressive-3)

```
chdir(dirname(__DIR__));
require 'vendor/autoload.php';

/** @var \Interop\Container\ContainerInterface $container */
$container = require 'config/container.php';

\LosMiddleware\LosLog\ExceptionLogger::registerHandlers('exception.log', '/tmp');

/* @var \Mezzio\Application $api */
$app = $container->get('Mezzio\Application');

$app->run();
```

#### Output example

[](#output-example-1)

```
2015-11-01T09:23:53-02:00 ERR (3): Exception- An exception was raised while creating "Application\Service\Test"; no instance returned in /vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php in line 733.
Previous: "data/logs2/erros.log" cannot be opened with mode "a" in /vendor/zendframework/zendframework/library/Zend/Log/Writer/Stream.php in line 87.
Previous: fopen(data/logs2/erros.log): failed to open stream: No such file or directory in /vendor/zendframework/zendframework/library/Zend/Log/Writer/Stream.php in line 84.
Trace:
#0 /vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(843): Laminas\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'teste', 'Application\Service\Tes...')
#1 /vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(487): Laminas\ServiceManager\ServiceManager->createFromFactory('teste', 'Application\Service\Tes...')
#2 /vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php(442): Laminas\ServiceManager\ServiceManager->create(Array)
#3 /src/Application/Module.php(29): Laminas\ServiceManager\ServiceManager->get('Application\Service\Tes...')
#4 [internal function]: Application\Module->onBootstrap(Object(Laminas\Mvc\MvcEvent))
#5 /vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Laminas\Mvc\MvcEvent))
#6 /vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(208): Laminas\EventManager\EventManager->triggerListeners('bootstrap', Object(Laminas\Mvc\MvcEvent), Array)
#7 /vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(146): Laminas\EventManager\EventManager->trigger('bootstrap', Object(Laminas\Mvc\MvcEvent))
#8 /vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(243): Laminas\Mvc\Application->bootstrap()
#9 /public/index.php(23): Laminas\Mvc\Application::init(Array)
#10 {main}

```

The default logfile is data/log/exception.log

### StaticLogger

[](#staticlogger)

This logger is usually used to log development or debug messages, arrays and objects. Just call it statically anywhere in your code.

```
\LosMiddleware\LosLog\StaticLogger::save("Test message");
\LosMiddleware\LosLog\StaticLogger::save("Test message 2", 'test.log');
```

will generate

```
2015-10-29T19:32:30-02:00 DEBUG (6): Test message

```

Or an object:

```
\LosMiddleware\LosLog\StaticLogger::save($myObj);
```

will generate

```
2015-10-30T17:26:37-03:00 DEBUG (7): {"User\\Entity\\User":[],"nome":{"type":"string","content":"Leandro"},"sobrenome":{"type":"string","content":"Silva"},"permissao":{"type":"string","content":"usuario"},"email":{"type":"string","content":"leandro@leandrosilva.info"},"acessos":{"type":"object","class":"Doctrine\\ORM\\PersistentCollection"},"login":{"type":"NULL","content":null},"senha":{"type":"string","content":"admin"},"inputFilter":{"type":"NULL","content":null},"id":{"type":"integer","content":3},"cadastrado":{"type":"object","class":"DateTime"},"atualizado":{"type":"object","class":"DateTime"}}

```

The default logfile is data/log/static.log

#### Z-Ray

[](#z-ray)

Z-Ray is an awesome resource from Zend Server that provides several information about the request, errors and the framework. It also has the possibility to add your own informations, so i added the StaticLogger messages to it.

More information can be seen [here](http://www.zend.com/en/products/server/z-ray-top-7-features).

##### Installation

[](#installation)

The LosLog module is available via the Official Z-Ray plugin system, just access the tab from your Zend Server UI and install it.

##### Usage

[](#usage-1)

Just use the StaticLogger and the messages will appear inside a LosLog section of the Z-Ray bar.

Optionally, you can pass a "null" value to the file argument to use just the Z-Ray, without writing the message to a file:

```
\LosMiddleware\LosLog\StaticLogger::save("Test message", null);
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~145 days

Recently: every ~523 days

Total

29

Last Release

881d ago

Major Versions

1.0.15 → 2.0.02015-11-02

1.0.16 → 2.0.32016-11-22

2.1.1 → 3.0.02018-03-03

PHP version history (7 changes)1.0.0PHP &gt;=5.3.3

1.0.12PHP &gt;=5.4.0

2.0.0PHP &gt;=5.6.0

2.1.0PHP ^5.6 || ^7.0 || ^7.1

3.0.0PHP ^7.0

3.1.0PHP ^7.1

3.3.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/9155a672b863ca2243f6b3d69d61d55bf35ae8e421c1b4f1655293a34d0451ba?d=identicon)[talbuquerque](/maintainers/talbuquerque)

---

Top Contributors

[![Lansoweb](https://avatars.githubusercontent.com/u/2109813?v=4)](https://github.com/Lansoweb "Lansoweb (62 commits)")[![basz](https://avatars.githubusercontent.com/u/143068?v=4)](https://github.com/basz "basz (12 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (4 commits)")[![dmetzler1988](https://avatars.githubusercontent.com/u/8446518?v=4)](https://github.com/dmetzler1988 "dmetzler1988 (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![talbuquerque](https://avatars.githubusercontent.com/u/20418669?v=4)](https://github.com/talbuquerque "talbuquerque (1 commits)")

---

Tags

logmodulezf2expressivezf3los

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zooxsmart-los-log/health.svg)

```
[![Health](https://phpackages.com/badges/zooxsmart-los-log/health.svg)](https://phpackages.com/packages/zooxsmart-los-log)
```

###  Alternatives

[los/loslog

LosLog provides some log utility

1751.2k2](/packages/los-loslog)[facile-it/sentry-module

This module allows integration of Sentry Client into laminas and mezzio

19372.5k](/packages/facile-it-sentry-module)[jhuet/zdt-logger-module

A ZF3 module to log data using Zend\\Log and write them to ZendDeveloperTools toolbar.

1765.6k4](/packages/jhuet-zdt-logger-module)[opengento/module-webapi-logger

This module allows you to analyze all the webapi rest done call toward your Magento.

1014.9k](/packages/opengento-module-webapi-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
