PHPackages                             mootly/mp\_errors - 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. mootly/mp\_errors

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

mootly/mp\_errors
=================

MoosePlum Error Management Class

v1.0.0(3y ago)1231MITPHPPHP &gt;=8.0.0

Since Jul 14Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/Mootly/mp_errors)[ Packagist](https://packagist.org/packages/mootly/mp_errors)[ Docs](https://github.com/Mootly/mp_errors)[ RSS](/packages/mootly-mp-errors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (1)

MoosePlum Error Management Class
================================

[](#mooseplum-error-management-class)

Repo: [Mootly/mp\_errors](https://github.com/Mootly/mp_errors)

This is a standalone version of the error class used by MoosePlum, for those who want a really simple in-application error logger for their PHP apps.

This is for logging errors that are internal to the application and do not, and in most cases should not, generate system errors.

Warning

This is NOT a secure solution.

The error log is stored internally in an array that defaults to only storing the last 100 entries.

The class also stores an array of status messages for use in reporting. It starts with a default set that can be added to.

The primary function of this class is to standardize error logging across all objects in an application.

System Requirements
-------------------

[](#system-requirements)

Requirements are pretty simple.

- This was developed using PHP 8.1. It should work in PHP 7.0 and up, but has **not** been test for backward compatibility.
- A web server, or what's the point really?

Dependencies
------------

[](#dependencies)

None.

Defaults
--------

[](#defaults)

The default namespace for this class is '`mpc`', which is short for 'MoosePlum Class'.

The default location for this class definition should be your vendor library. For inclusion with other MoosePlum stuff that would be `/_lib/mootly/mp_errors/`.

Assets
------

[](#assets)

The files in this set are as follows:

pathdescriptioncomposer.jsonYep, we are using [Composer](https://getcomposer.org).CHAMGELOG.mdThe changelog for this utility.LICENSE.mdLicense notice ( [MIT](https://mit-license.org) ).README.mdThis document.mpt\_errors.phpLocal unit test file to make sure things work.src/mpc\_errors.phpThe class definition.src/mpi\_errors.phpThe interface for the class.Installation
------------

[](#installation)

### Manual Installation

[](#manual-installation)

Put this class definition and any dependencies into your vendor library. For inclusion with other MoosePlum stuff that would be `/_lib/mootly/mp_errors/`.

Use your preferred method for including classes in your code.

### Composer Installation

[](#composer-installation)

This class definition is listed on [Packagist](https://packagist.org/users/Mootly/packages/) for installation using Composer.

See the [Composer](https://getcomposer.org) website for a directions on how to properly install Composer on your system.

Once Composer is installed and running, add the following code to the `composer.json` file at the root of your website.

Make sure you have the following listed as required. Adjust version numbers as necessary. See the `composer.json` in this class definition for required versions of dependencies for this version of the package.

```
"require": {
  "php": ">=8.0.0",
  "mootly/mp_errors": "*",
}
```

If necessary for your configuration, make sure you have the following autoload definitions listed in your `composer.json`. Adjust the first step in the path as needed for the location of your vendor library.

```
"autoload": {
  "classmap": [
    "_lib/mootly/mp_errors",
  ]
}
```

In your terminal app of choice, navigate to the root of your website and run the following command. (Depending on how you installed composer, this may be different.)

```
composer update
```

This should install this class definition and any related dependencies in your vendor library and sets up composer to link them into your application.

To be safe you can also run the following to rebuild the composer autoloader and make sure your classes are correctly registered.

```
composer dump-autoload -o
```

Make sure you have the following line to your page or application initialization code before using this class definition. Adjust accordingly based on the location of your vendor library.

```
require_once "//autoload.php";
```

That should be all your need to do to get it up and running.

Configuration
-------------

[](#configuration)

If you are using autoloading, the recommended method for instantiation is as follows:

```
if (!isset($mpo_errors)) { $mpo_errors  = new \mpc\mpc_errors(); }
```

The constructor takes three optional arguments.

1. Status Codes (array) - An array of status codes. See the format below.
2. Replace Flag (bool) - Whether to allow existing status codes to be replaced or not when the code is matched by a new entry. Default is false. True will override at any time.
3. Log Size (int) - Length of status log. Default is 100.

It is recommended that you create a single class instance and load it into your other objects as a depedency. For example:

```
if (!isset($mpo_secure)) { $mpo_secure  = new \mpc\mpc_secure($mpo_errors); }
```

Usage
-----

[](#usage)

The use of namespaces or other unique identifiers to create unique strings for locking is strongly encouraged.

Examples:

- mpo\_parts::main\_body
- mpo\_menus::main\_nav::home\_link

Autogeneration examples:

- `__CLASS__.'::'.someProp`
- `__CLASS__.'::'.__METHOD__`
- `__CLASS__.'_'.self::$iCount++` (for multiple instances)

For security add a hash of some sort that is always used for all calls by a given class. This prevents others without access to private properties from overwriting any locks. Examples of PHP hash generators:

- `php md5(__CLASS__)`
- `md5(rand())`
- `uniqid()`
- `bin2hex(random_bytes(16))`

Since these will only persist for as long as it takes for PHP to generate and send out an HTTP response, they do not need to be overly secure. There are only milliseconds to guess the hash before it is gone.

MoosePlum classes define the following property on instantiation to ensure unique names.

```
$this->classRef = bin2hex(random_bytes(8)).'::'.__CLASS__;
```

### The Status Code Array

[](#the-status-code-array)

Status codes are stored in an array. Each array element is structured as follows:

```
string status code => [ string severity, string message ]
```

For example, these are the predefined status codes.

```
'none'          => ['Notice'  ,'Success.'],
'noAction'      => ['Notice'  ,'No action taken.'],
'mpe_set00'     => ['Warning' ,'Some properties already exist and were not replaced.'],
'mpe_set01'     => ['Warning' ,'This property already exists and was not replaced.'],
'mpe_locked'    => ['Warning' ,'Requested property is locked from updates.'],
'mpe_secure'    => ['Warning' ,'Requested property is secured from further updates.'],
'unknown'       => ['Error'   ,'Unknown error code.'],
'mpe_null'      => ['Error'   ,'Requested value or property does not exist.'],
'mpe_nomethod'  => ['Error'   ,'Requested method does not exist.'],
'mpe_badURL'    => ['Error'   ,'Invalid URL.'],
'mpe_param00'   => ['Error'   ,'Invalid parameter.'],
'mpe_param01'   => ['Error'   ,'Invalid history length.'],
'mpe_param02'   => ['Error'   ,'Attempted to add invalid error message entry.'],
'mpe_param03'   => ['Error'   ,'Too few parameters.'],
'mpe_param04a'  => ['Error'   ,'Too many parameters.'],
'mpe_param04b'  => ['Warning' ,'Too many parameters. Not all were processed.'],
```

### The Status Log

[](#the-status-log)

Status messages are added to an array that is defined as follows:

```
log => [
  success  => bool
  code     => string  // status code from status code array
  source   => string  // calling class and method
  severity => string  // severity from status code array
  message  => string  // message from status code array
]
```

The array functions as a stack so last in, first out. The most recent status code is entered at position 0.

A `get()` call will return the last element recorded as an array with the above values, or false if an out of range request is made.

### Methods

[](#methods)

#### setStatus

[](#setstatus)

Add an entry to the status log. See above for the structure of the status log.

```
public setStatus(string code, ?string source) : bool
```

If the status log exceeds maximum size, remove the oldest element.

If a source is not specified, log as 'source not specified'.

Return false is the status code does not exist in the status code array.

#### getStatus

[](#getstatus)

Return the most recently logged status message as an array (see above), or the one specified in the call. The most recent message has a position of 0.

Return false if asking for an out of bounds element.

```
public getStatus(int index) : array|bool
```

#### getStatusCodes

[](#getstatuscodes)

Return array of all available error codes.

This method tkes no arguments.

```
public getStatusCodes() : array
```

#### getStatusCount

[](#getstatuscount)

Return the number of messages in the status log.

This method takes no arguments.

```
public getStatusCount() : int
```

#### addStatusCodes

[](#addstatuscodes)

Submit an array of error codes to add to the status code array.

Pass a replaces flag of true to overwrite existing codes in the case of matches.

See above for the structure of the status code array.

```
public addStatusCodes(array codes, bool replace) : bool
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance43

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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 ~110 days

Total

2

Last Release

1293d ago

Major Versions

v0.1.0 → v1.0.02022-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec7768520f744ea680eefc650c99580eb9fe0e2f24eac2db78bcf57bf1bc6e18?d=identicon)[Mootly](/maintainers/Mootly)

---

Top Contributors

[![Mootly](https://avatars.githubusercontent.com/u/1514228?v=4)](https://github.com/Mootly "Mootly (16 commits)")

---

Tags

phploggingerrorerrors

### Embed Badge

![Health badge](/badges/mootly-mp-errors/health.svg)

```
[![Health](https://phpackages.com/badges/mootly-mp-errors/health.svg)](https://phpackages.com/packages/mootly-mp-errors)
```

###  Alternatives

[analog/analog

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

3451.5M24](/packages/analog-analog)[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[jenssegers/rollbar

Rollbar error monitoring integration for Laravel projects

3301.1M2](/packages/jenssegers-rollbar)[e2ex/e2ex

Converts PHP Errors to Exceptions and (optionally) logs PHP Errors, Notices and Warnings with a PSR-3 compatible logger

101.5k](/packages/e2ex-e2ex)

PHPackages © 2026

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