0x20h / monoconf
log4j like logging configuration for the monolog framework
Installs: 24 601
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/0x20h/monoconf
Requires
- php: >=5.3.0
- monolog/monolog: >=1.5.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-07-02 06:35:37 UTC
README
Monoconf
log4j like configuration for the monolog logging framework.
Usage
- Create a config JSON file:
{
"rules": {
"*": {
"error": {
"handler": ["error-handler"]
}
},
"MyApp\\Controller*": {
"debug": {
"handler": ["debug-handler"],
"processor": ["pid"]
},
"error": {
"handler": ["error-handler"]
}
}
},
"handler": {
"error-handler": {
"type": "Monolog\\Handler\\StreamHandler",
"args": [
"/my/app/error.log"
],
"formatter": "line"
},
"debug-handler": {
"type": "Monolog\\Handler\\StreamHandler",
"args": [
"/my/app/application.log"
],
"formatter": "line"
}
},
"formatter": {
"line": {
"type": "Monolog\\Formatter\\LineFormatter",
"args": [
"%datetime% %pid% %channel%@%level_name% %message% %context%\n"
]
}
},
"processor": {
"pid": {
"type": "Monolog\\Processor\\ProcessIdProcessor",
"args": [
]
}
}
}
- In your application:
require 'vendor/autoload.php'; use Monoconf\Monoconf; // initialize monoconf Monoconf::config(json_decode(file_get_contents('monoconf.json'), true));
namespace MyApp\Controller; class SomeController { protected $Log; public function __construct() { self::$Log = \Monoconf\Monoconf::getLogger(__CLASS__); } public function someAction() { self::$Log->debug(__METHOD__.' called'); } }
Using this setup every class in the MyApp\Controller namespace will get a
logger that logs every message up to debug to /my/app/error.log and every
other class will get a logger that logs messages up to error to
/my/app/error.log.
Tests
phpunit --bootstrap tests/bootstrap.php tests/