PHPackages                             afrihost/base-command-bundle - 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. afrihost/base-command-bundle

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

afrihost/base-command-bundle
============================

Afrihost’s ‘swiss-army-knife’ extension of Symfony’s ContainerAwareCommand that defines common reusable functionality (such as logging) across commands

v1.1.1(6y ago)727.9k↓36.7%10[3 issues](https://github.com/afrihost/BaseCommandBundle/issues)[1 PRs](https://github.com/afrihost/BaseCommandBundle/pulls)MITPHPPHP ~7.1CI failing

Since Dec 14Pushed 6y ago3 watchersCompare

[ Source](https://github.com/afrihost/BaseCommandBundle)[ Packagist](https://packagist.org/packages/afrihost/base-command-bundle)[ Docs](https://github.com/afrihost/BaseCommandBundle)[ RSS](/packages/afrihost-base-command-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (0)

Afrihost BaseCommandBundle
==========================

[](#afrihost-basecommandbundle)

[![Latest Stable Version](https://camo.githubusercontent.com/79471fd0f28d70d32fd691adb70e2000acee993a9d4a8fdca7168bdf3b33a0a6/68747470733a2f2f706f7365722e707567782e6f72672f61667269686f73742f626173652d636f6d6d616e642d62756e646c652f762f737461626c65)](https://packagist.org/packages/afrihost/base-command-bundle)[![Total Downloads](https://camo.githubusercontent.com/0c9ad9e49e9dcf03fee7539fbd9c04b5b77fdd5c7b6cfbbaf4f4022418ebada4/68747470733a2f2f706f7365722e707567782e6f72672f61667269686f73742f626173652d636f6d6d616e642d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/afrihost/base-command-bundle)[![License](https://camo.githubusercontent.com/5c607ae53c4d8dfa2cc437653f1961efb142e589119bdbcdd24cd8972f428493/68747470733a2f2f706f7365722e707567782e6f72672f61667269686f73742f626173652d636f6d6d616e642d62756e646c652f6c6963656e7365)](https://packagist.org/packages/afrihost/base-command-bundle)[![Build Status](https://camo.githubusercontent.com/bdc00af25be0655a37b3933ad129042cf491e194945ba9489577bf0f1ec69b3d/68747470733a2f2f7472617669732d63692e6f72672f61667269686f73742f42617365436f6d6d616e6442756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/afrihost/BaseCommandBundle)

**If you have lots of Symfony Commands, or if you simply want to skip the boilerplate involved in setting up commands, this bundle is for you.** At its core is an abstract class that extends Symfony’s ContainerAwareCommand. This adds our own opinionated initialization for a range of boilerplate, such as logging and locking, so that you don’t have to re-invent the wheel with every command.

The overall design goal is to enable you to define defaults (such as whether to duplicate log output to your console) globally in your Symphony configuration while still having the freedom to override these in a single command (e.g. This command must always obtain a lock) and then change your mind again at runtime (to set the Log Level to DEBUG for this execution for example).

It is a small piece of ‘developer friendly’ code that we want to share with you in the hopes that it makes your life a little easier. If this appeals to you, Pull Requests are always welcome.

Installation
------------

[](#installation)

First install this bundle using composer

```
composer require afrihost/base-command-bundle
```

> **Note:** Support for Symfony 2 and PHP 5 is still available under version zero (*~0.6*). We will continue to publish any important bug and security fixes as point releases on this version, however, new features will not be backported. The current version supports Symfony *~3.0* and PHP *~7.0*

Then, enable the bundle by adding it to the list of registered bundles in the `app/AppKernel.php` file of your project:

```
// in AppKernel::registerBundles()
$bundles = array(
    // there should be a bunch of symfony bundles and your bundles already added here
    new Afrihost\BaseCommandBundle\AfrihostBaseCommandBundle(),
    // ...
);
```

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

[](#configuration)

Defaults are specified for all options so that no configuration is needed, but if you'd like, you can override the default configuration options in your `app/config/config.yml` file:

```
afrihost_base_command:
    locking:
        lock_file_folder:     storage
        enabled:              true
    logger:
        handler_strategies:
            file_stream:
                enabled:              true
                line_format:          '%%datetime%% [%%level_name%%]: %%message%%'
                file_extension:       .log.txt
            console_stream:
                enabled:              true
                line_format:          '%%datetime%% [%%level_name%%]: %%message%%'
```

**Locking:**You may opt to enable/disable locking via configuration. Locking is enabled by default.

You might also want to change the default location where the lock files are created. If you do not specify a lock file folder, locks will be created in the system's default temporary directory. If you specify a relative directory, locks will be created relative to the Symfony Kernel root (which is "app" in most cases). If you specify an absolute path, the directory must already exist and be accessible by the PHP process. In POSIX environments, paths can be provided that start with ~/. This will be expanded using the $HOME environment variable and the full path subjected to he same constraints as absolute paths.

Example (relative): "storage" &gt;&gt; this will assume you want it under app/storage. "storage/lockfiles" &gt;&gt; this will assume you want it under "app/storage/lockfiles". Example (absolute): "/var/my-lockfiles" &gt;&gt; this will store it under "/var/my-lockfiles". "~/my-lockfiles" &gt;&gt; lock files will be created under "/home/your\_username/my-lockfiles".

Full documentation for the locking functionality can be found at [Resources/doc/locking.md](Resources/doc/locking.md)

**Logging**The logging system has the ability to use several handlers. More handlers will be added soon, you're also welcome to add your own and send us a PR. Each handler has the potential of being enabled/disabled. Handlers are all enabled by default at this stage. Handlers generally have line formatting. The `line_format` entry states how this format looks like, and can be overwritten in the config.yml file. The file logger has a file extension, specified by `file_extension` and is defaulted, but can again be overwritten in config.yml.

Full documentation for the logging functionality can be found at [Resources/doc/logging.md](Resources/doc/logging.md)

Basic Usage
-----------

[](#basic-usage)

Instead of extending `ContainerAwareCommand` like this:

```
class MyCoolCommand extends ContainerAwareCommand
{
    // your stuff here
}
```

... you simply extend our `BaseCommand` like this:

```
use Afrihost\BaseCommandBundle\Command\BaseCommand;

// ...

class MyCoolCommand extends BaseCommand
{
    // your stuff here
}
```

Don't worry, BaseCommand still extends ContainerAwareCommand, so all the goodies you are used to having at your disposal from ContainerAwareCommand are still there. BaseCommand merely adds a few extra boilerplate and tools for you to use, such as:

**Log Handler Initialisation** - you can immediately start logging out of the box with [Monolog](https://github.com/Seldaek/monolog):

```
 $this->getLogger()->error('Hello World!')
```

**Runtime Log Level** - Change the log-level from the command line without having to change the code. Just provide the `--log-level` parameter with any of the RFC 5424 [severity names](https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md#log-levels) supported by Monolog:

```
$ php app/console my:cool:command --log-level=DEBUG
```

**Log to Console** - Toggle whether you want the log entries to be sent to STDOUT as well as the logfile

Output Icons
------------

[](#output-icons)

```
 echo $this->getIcon()->tick()->white()->bgGreen()->bold()->render() . PHP_EOL;
```

IconsColoursOptionsIconMethod✔tick✘error❗exclamation❰lt❱gt➀one➁two➂three➃four➄five➅six➆seven➇eight➈nine➉ten✉envelope☠dead⛔noEntry⏰alarmClock←leftArrow↑upArrow→rightArrow↓downArrow↔leftRightArrow↕upDownArrow💩smileyPoo🍻beers🐔chicken💣bomb💤snooze🔒lock🙏prayForeground Colour MethodsdefaultblackwhiteredgreenblueyellowcyanmagentaBackground Colour MethodsbgDefaultbgBlackbgWhitebgRedbgGreenbgBluebgYellowbgCyanbgMagentaMethodboldunderscorereverseTODO
----

[](#todo)

The following are features we would like to add. When this list is done (or reasonably short) we will release our first Major Version:

- **Strategies for Logfile Names**: Currently the logfile name can either be specified manually or will be generated from the name of the file in which the commend is defined. We would like to make other options available via a Strategy Pattern (Log filename can be specified in a parameter as an interim solution)
- **Configurable Logfile Extension**: For historical reasons logfile names all end in `.log.txt`. This extension should be a configuration option
- **Unhandled Exception Listener**: Have unhandled exceptions be automatically logged to the logger instantiated for the command. This is already available in our production version. It just needs to be made more reusable
- **Bundle Config for**:
    - Default Log Level
    - Log to Console
    - Log to File
    - PHP Error Reporting
    - PHP memory\_limit
    - PHP maximum execution time
    - Specify lock-handler lockfile location
- **User Specified LineFormatters**: Our default format (%datetime% \[%level\_name%\]: %message%) is hardcoded. This isn't ideal if you wish to parse the logs with a specific tool.
- **Locking**: Integrate mechanism to ensure that only one process is executing a command at a time
- **Config for Monolog's AllowLineBreaks Option**: because sometimes you want a new line in the middle of a log entry
- **PHPUnit**: config and basic code coverage. The goal is to have some form of Github integrated CI
- **Output Icons**: create a helper to prefix output with unicode icons (such as a checkmark)
- **Documentation**:
    - Changelog (listing major changes on Github releases)
    - Seed `Resources/doc/` ( [Symfony Best Practice](http://symfony.com/doc/current/cookbook/bundles/best_practices.html#directory-structure) )
    - Contributor Guide

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance11

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 65.8% 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 ~130 days

Recently: every ~326 days

Total

13

Last Release

2238d ago

Major Versions

v0.6.2 → v1.0.02018-10-16

v0.6.3 → v1.1.02020-04-01

PHP version history (3 changes)v0.1.0PHP &gt;=5.3.3

v1.0.0PHP ~7.0

v1.1.1PHP ~7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2071493?v=4)[Sarel van der Walt](/maintainers/sarelvdwalt)[@sarelvdwalt](https://github.com/sarelvdwalt)

![](https://avatars.githubusercontent.com/u/15737303?v=4)[Afrihost](/maintainers/afrihost)[@afrihost](https://github.com/afrihost)

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

---

Top Contributors

[![mostertb](https://avatars.githubusercontent.com/u/2180195?v=4)](https://github.com/mostertb "mostertb (177 commits)")[![sarelvdwalt](https://avatars.githubusercontent.com/u/2071493?v=4)](https://github.com/sarelvdwalt "sarelvdwalt (86 commits)")[![pierredup](https://avatars.githubusercontent.com/u/144858?v=4)](https://github.com/pierredup "pierredup (4 commits)")[![johanmeiring](https://avatars.githubusercontent.com/u/1214876?v=4)](https://github.com/johanmeiring "johanmeiring (1 commits)")[![Syb3r1us](https://avatars.githubusercontent.com/u/32634688?v=4)](https://github.com/Syb3r1us "Syb3r1us (1 commits)")

---

Tags

logginglockingmonologsymfony command

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/afrihost-base-command-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/afrihost-base-command-bundle/health.svg)](https://phpackages.com/packages/afrihost-base-command-bundle)
```

###  Alternatives

[inpsyde/wonolog

Monolog-based logging package for WordPress.

183617.9k7](/packages/inpsyde-wonolog)[logtail/monolog-logtail

Logtail handler for Monolog

233.2M3](/packages/logtail-monolog-logtail)[kdyby/monolog

Integration of Monolog into Nette Framework

33684.0k10](/packages/kdyby-monolog)[inpsyde/logzio-monolog

Logz.io integration for Monolog

191.2M1](/packages/inpsyde-logzio-monolog)[mero/yii2-monolog

The Monolog integration for the Yii framework.

42186.1k](/packages/mero-yii2-monolog)[mead-steve/mono-snag

Bugsnag integration for monolog. An abstract handler that sends messages to Bugsnag

20533.2k1](/packages/mead-steve-mono-snag)

PHPackages © 2026

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