PHPackages                             onesimus-systems/oslogger - 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. onesimus-systems/oslogger

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

onesimus-systems/oslogger
=========================

Simple, modular, PSR-3 compliant logging library.

2.3.2(10y ago)0122[2 issues](https://github.com/onesimus-systems/oslogger/issues)BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jun 15Pushed 10y agoCompare

[ Source](https://github.com/onesimus-systems/oslogger)[ Packagist](https://packagist.org/packages/onesimus-systems/oslogger)[ RSS](/packages/onesimus-systems-oslogger/feed)WikiDiscussions master Synced 1mo ago

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

OSLogger
--------

[](#oslogger)

[![Build Status](https://camo.githubusercontent.com/819f2ce9233b55d7ef35d014b331a2bc482da0704259ae98e305c6d4f2431580/68747470733a2f2f7472617669732d63692e6f72672f6f6e6573696d75732d73797374656d732f6f736c6f676765722e737667)](https://travis-ci.org/onesimus-systems/oslogger)

OSLogger is a PSR3 compatible, modularized logger. It allows for multiple logging targets through the use of adaptors.

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

[](#requirements)

- PHP &gt;= 5.3.0

Features
--------

[](#features)

- Quick and easy setup
- [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) compliant
- Multiple adaptors:
    - Files
    - Console
    - Echo
    - Null
    - [Chrome Logger](https://craig.is/writing/chrome-logger)
- Set minimum and maximum handled log level for an adaptor

Usage
-----

[](#usage)

OSLogger works by using adaptors to write to multiple targets. These adaptors can be for the usual things like a file, or database. They can also be created for more complex things such as sockets and streams. You can make your own adaptors or use one of the ones provided.

Here's how the FileAdaptor would be used:

```
$adaptor = new \Onesimus\Logger\Adaptors\FileAdaptor('logfile.log');
$logger = new \Onesimus\Logger\Logger($adaptor);

$logger->error("Here's a message with {placeholders}", array('placeholders' => 'turtles'));
// The log message will be "Here's a message with turtles" due to the placeholder interpolation
// per PSR3 spec.
```

If you don't want to actually log anything but don't want to add conditional logging to your application, you can use a NullAdaptor or simple not provide an adaptor to the Logger constructor (a NullAdaptor is made by the object at construction if one isn't provided).

Multiple adaptors can be added to the same logger by calling `Logger::addAdaptor($adaptor)`:

```
$adaptor2 = new \Onesimus\Logger\Adaptors\EchoAdaptor();
$logger->addAdaptor($adaptor2);
```

When a log is generated it will be sent to all registered adapters that are set to handle the particular log level. So you can have multiple FileAdaptors logging to separate places, a FileAdaptor and database adaptor, what ever you want. You can also have logs above or below a certain threshold log to one place and all logs to another. You can completely customize how the logger works for you.

Special Handlers
----------------

[](#special-handlers)

OSLogger comes with builtin handlers for PHP errors, shutdowns (only does something if error\_get\_last() returns anything), and uncaught exceptions. If you wish to use any of these, create a new `Logger\ErrorHandler` object and call the methods `registerErrorHandler()`, `registerShutdownHandler($loglevel)`, or `registerExceptionHandler($loglevel)` and pass in a Logger object. The handlers will take the errors or exceptions and log them using an appropiate log level.

Handler log levels:

- Shutdown: All are `critical` (unless specified otherwise)
- Exception: All are `critical` (unless specified otherwise)
- Errors:
    - E\_USER\_ERROR, E\_RECOVERABLE\_ERROR are `error`
    - E\_USER\_WARNING, E\_WARNING are `warning`
    - E\_USER\_NOTICE, E\_NOTICE are `notice`
    - E\_STRICT are `debug`

Note: The shutdown handler will only do something if the function error\_get\_last() returns anything. The handler does not call exit() or die() so you can register another shutdown handler.

Adaptors (\\Onesimus\\Logger\\Adaptors)
---------------------------------------

[](#adaptors-onesimusloggeradaptors)

\###All Adaptors

- `isHandling($level)` - Check if the adaptor handles logs at the given level.
- `setLevel($min, $max)` - Set the min/max level handled by the adaptor. If you want to set only the max, pass `null` as the first argument.
- `setDateFormat($format)` - Set the date format used in logs.
- `getDateFormat()` - Get the date format used in logs.
- `restoreDateFormat()` - Sets date format to the default "Y-m-d H:i:s T".
- `getLastLogLine()` - Returns last log line written.
- `setName($name)` - Name of adaptor used by Logger, set before adding to a Logger object.
- `getName()` - Returns name of adaptor

\###NullAdaptor

Logging blackhole. All logs are thrown away and never seen again. Saves to /dev/null

\###EchoAdaptor

Echo all messages. That's all.

- `__construct($minimumLevel = LogLevel::DEBUG, $echoStr = "")` - $echoStr will default to "{date}: \[{level}\] Message: {message}\\n"
- `setEchoString($string)` - Sets the template used to echo log messages. See the Placeholders section.
- `getEchoString()` - Returns the currently assigned echo template.

\###ConsoleAdaptor

Fancier version of EchoAdaptor that echos logs with color and better default formatting

- `__construct($minimumLevel = LogLevel::DEBUG)`
- `setTextColor($levels, $color)` - Set the color used for the level tag in logs. Color codes can be accessed through the Logger\\AsciiCodes class. $levels can be either a string for a single log level, or an array of levels.

\###FileAdaptor

Saves logs to files.

- `__construct($file, $minimumLevel = LogLevel::DEBUG)`
- `setLogLevelFile($levels, $filename)` - Save specific log levels to separate files. Eg: `fileLogLevels(['emergancy', 'alert'], 'the_world_is_ending.log');`
- `getLogLevelFiles()` - Returns array of current filenames for a level. The array is keyed to the different log levels. An empty value means it uses the default file.
- `separateLogFiles($ext = '.txt')` - Separates all log levels to their own files. $ext is the file extension used for the log files.
- `setDefaultFile($filename)` - Set the default file if a specific file hasn't been defined by fileLogLevels(). The constructor calls this with the filename it's given.
- `getDefaultFile()` - Returns current default file.

\###ChromeLoggerAdaptor

Sends logs to Chrome using the Chrome Logger extension. Website: [Chrome Logger](https://craig.is/writing/chrome-logger)

- `logBacktrace($onoff)` - Record a backtrace (file, line #) in logs. Default: true

Placeholders
------------

[](#placeholders)

Some adaptors allow a customized string pattern used when making logs. When this is available, a few placeholders can be used. Placeholders are case-sensative.

- `{level}` - Log level in all lowercase
- `{levelU}` - Log level in all uppercase
- `{message}` - Log message or formatted string for objects
- `{date}` - Datetime of log

License
-------

[](#license)

OSLogger is released under the terms of the BSD 3-Clause license. The full license text is available in the LICENSE.md file.

Versioning
----------

[](#versioning)

For transparency into the release cycle and in striving to maintain backwards compatibility, This library is maintained under the Semantic Versioning guidelines. Sometimes we screw up, but we'll adhere to these rules whenever possible.

Releases will be numbered with the following format:

`..`

And constructed with the following guidelines:

- Breaking backward compatibility **bumps the major** while resetting minor and patch
- New additions without breaking backward compatibility **bumps the minor** while resetting the patch
- Bug fixes and misc changes **bumps only the patch**

For more information on SemVer, please visit .

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

10

Last Release

3985d ago

Major Versions

0.1.0 → 1.0.02015-06-18

1.0.1 → 2.0.02015-06-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b0c8b2c3cadee570c224131bb905fcd14df14a41d0100796509d6a9df402618?d=identicon)[dragonrider23](/maintainers/dragonrider23)

---

Top Contributors

[![lfkeitel](https://avatars.githubusercontent.com/u/6619743?v=4)](https://github.com/lfkeitel "lfkeitel (54 commits)")

---

Tags

chrome-loggerlogginglogging-librarymultiple-adaptorsphplogginglogsPSR3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/onesimus-systems-oslogger/health.svg)

```
[![Health](https://phpackages.com/badges/onesimus-systems-oslogger/health.svg)](https://phpackages.com/packages/onesimus-systems-oslogger)
```

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k227.1M273](/packages/sentry-sentry)[analog/analog

Fast, flexible, easy PSR-3-compatible PHP logging package with dozens of handlers.

3451.5M24](/packages/analog-analog)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[open-telemetry/api

API for OpenTelemetry PHP.

1933.0M214](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2322.9M248](/packages/open-telemetry-sdk)[struggle-for-php/sfp-phpstan-psr-log

Extra strict and opinionated psr/log (psr-3) rules for PHPStan

42257.6k9](/packages/struggle-for-php-sfp-phpstan-psr-log)

PHPackages © 2026

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