theorchard / monolog-cascade Goto Github PK
View Code? Open in Web Editor NEWConfigure multiple loggers and handlers in the blink of an eye
License: MIT License
Configure multiple loggers and handlers in the blink of an eye
License: MIT License
hi
i would like to have "dist" config and "local" configs, so most of the things, like declaring formatters, processors, handlers are done in "dist" file and loggers from "local" file
from current code reading i see Cascade::fileConfig would just overwrite self::$config
, so no merging there.
I believe Monolog handlers do support the $filePermission argument. However, I can't get it configured from the JSON configuration settings for a handler.
How do I pass the argument correctly so the handler will create the log file with the correct permissions?
Given the only thing symonfy/serializer appears to be used for is to convert snake_case names to camelCase, it seems a bit unnecessary to require the entire serializer component for this one task. Surely a smaller, dedicated library would be more suited to the task? There are plenty of examples here: https://packagist.org/search/?q=camel
Monolog is currently at 3.5, but monolog-cascade only supports ^2.0, are then any plans to support more recent versions of monolog?
Illegal string offset 'disable_existing_loggers' in vendor/theorchard/monolog-cascade/src/Config.php:99
$this->options seems to be a string having the path of the config file
$path = APPLICATION_PATH . '/configs/monolog/cascade/testcontroller.yaml';
//echo $path."\n";
Cascade::fileConfig($path);
Cascade::getLogger('myApp')->info('Well, that works!');
Cascade::getLogger('myApp')->error('Maybe not...');
formatters:
dashed:
class: Monolog\Formatter\LineFormatter
format: "%datetime%-%channel%.%level_name% - %message%\n"
handlers:
console:
class: Monolog\Handler\StreamHandler
level: DEBUG
formatter: dashed
stream: php://stdout
info_file_handler:
class: Monolog\Handler\StreamHandler
level: INFO
formatter: dashed
stream: /tmp/example_info.log
processors:
introspection_processor:
class: Monolog\Processor\IntrospectionProcessor
loggers:
myApp:
handlers: [console, info_file_handler]
processors: [introspection_processor]
I think this is a great library making life easy in setting up logs. Although, I am trying to configure SwiftMailerHandler as one of the handlers to send alerts for errors. I am having issues in doing so. Do you have samples or documentation on how to set it up ?
Given that this package supports configuration in JSON and PHP arrays as well as YAML, not everyone is going to want symfony/yaml. Therefore, it should be an optional dependency.
Create a default logger (handlers and processors)
Monolog-Cascade does not create the log folder nor the log files while I configured and installed as described in the documentation. it seems to me that Handlers and Streams do not work using the conf.yaml file
Exmple with Monlog-cascade:
object(Monolog\Logger)#22 (5) {
["name":protected]=>
string(16) "import"
["handlers":protected]=>
array(0) {
}
["processors":protected]=>
array(0) {
}
["microsecondTimestamps":protected]=>
bool(true)
["exceptionHandler":protected]=>
NULL
}
Exemple without Monolog-cascade ( using Monolog pushHandler and streamHandler )
object(Monolog\Logger)#22 (5) {
["name":protected]=>
string(16) "import"
["handlers":protected]=>
array(1) {
[0]=>
object(Monolog\Handler\StreamHandler)#49 (10) {
["stream":protected]=>
NULL
["url":protected]=>
string(36) "../../../../log/import.log"
["errorMessage":"Monolog\Handler\StreamHandler":private]=>
NULL
["filePermission":protected]=>
NULL
["useLocking":protected]=>
bool(false)
["dirCreated":"Monolog\Handler\StreamHandler":private]=>
NULL
["level":protected]=>
int(100)
["bubble":protected]=>
bool(true)
["formatter":protected]=>
NULL
["processors":protected]=>
array(0) {
}
}
}
["processors":protected]=>
array(0) {
}
["microsecondTimestamps":protected]=>
bool(true)
["exceptionHandler":protected]=>
NULL
}
My conf.yaml:
formatters:
dashed:
class: Monolog\Formatter\LineFormatter
format: "%datetime%-%channel%.%level_name% - %message%\n"
handlers:
default:
class: Monolog\Handler\StreamHandler
level: DEBUG
formatter: dashed
stream: D:\TheProject\log\default.log
import:
class: Monolog\Handler\StreamHandler
level: DEBUG
formatter: dashed
stream: D:\TheProject\log\import.log
loggers:
myLogger:
handlers: [default,import]
Did I miss something ?
This is part of my yaml file.
...
handlers:
phpmailer_handler:
class: MonologPHPMailer\PHPMailerHandler
mailer:
class: PHPMailer\PHPMailer\PHPMailer
exceptions: true
SMTPAuth: true
Username: 'user'
Password: 'password'
isHTML: true
isSMTP:
...
Setting Username, Password, SMTPAuth properties in following YAML ends with error:
Fatal error: Uncaught Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException: The options "password", "sMTPAuth", "username" do not exist. Defined options are: "isHTML", "isSMTP". in .....
How can i set public properties or call methods starting with uppercase letter?
In the PHP DocBlock for the method \Cascade\Cascade::fileConfig() "array" is missing as a valid type for $resource, as the param descriptions states.
/**
* Load configuration options from a file or a string
*
* @param string $resource Path to config file or string or array
*/
public static function fileConfig($resource)
{
self::$config = new Config($resource, new ConfigLoader());
self::$config->load();
self::$config->configure();
}
Maybe there should be another method which only expects an array, which is called something like "setConfig"(?)
Does it support rotating file? If so, what is the configuration structure enable and set $maxFiles?
Update to PHPUnit9.X to resolve PHP8 dev-dependency chain
See #102
EDIT: my bad, I presumed you were waiting to update until the entire project could run in PHP8. I didn't see properly the dev-master package and repo are >=7.X so next release is good-to-go.
Hi,
I would like to have a function to find out if Cascade already has a logger with a given name or not. Basically just forwarding the function of Registry::hasLogger()
through Cascade::hasLogger()
.
If you would like that, I can open a PR, I already forked the project to provide this functionality for myself but would happily provide it to the upstream.
Cheers,
DBX12
0.5.3 is missing from https://packagist.org/packages/theorchard/monolog-cascade
It looks like the webhooks need updating https://packagist.org/about#how-to-update-packages
NOTICE: PHP message: PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in vendor/theorchard/monolog-cascade/src/Config/Loader/FileLoader/Json.php on line 54
when using classname without namespace
monolog cascade should use Monolog\Handler
e.g.
class: StreamHandler
should be the same as
class: Monolog\Handler\StreamHandler
There is a typo at Json.php#L59
Hi,
i see from the code that you can setup up processors,
how would you add that sort of processor with yaml configuration?
$logger = new Logger('my_logger');
$logger->pushHandler(new StreamHandler('./api.log', Logger::INFO));
$logger->pushProcessor(function ($record) {
$record['extra']['dummy'] = 'Hello world!';
return $record;
});
Thanks.
this link adds a getter for the streamhandler url.
I am having issues figuring out, after my $log = Cascade::getLogger('config');
, how to access the name of the file I am logging to, as a result of my (snippet) config:
'info_file_handler' => array(
'class' => 'Monolog\Handler\StreamHandler',
'level' => 'INFO',
'formatter' => 'full',
'stream' => $logfile
//'stream' => '/tmp/htmApp.log'
),
'error_file_handler' => array(
'class' => 'Monolog\Handler\StreamHandler',
'level' => 'ERROR',
'stream' => $errlogfile,
'formatter' => 'spaced'
)
Logging is working. When I dump the object I see the URL. How do I get it after making my logger object?
Example config:
handlers:
mongodb:
class: Monolog\Handler\MongoDBHandler
mongo:
class: MongoClient
server: mongodb://example.com:27017
database: doctrine
collection: logs
loggers:
doctrine:
handlers: [mongodb]
Which results in the following error:
ReflectionException: Cannot determine default value for internal functions in /path/to/vendor/theorchard/monolog-cascade/src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php on line 105
I managed to get it working alrght:
I'm not sure if this is the most appropriate fix, let me know if you'd like a PR.
Has it been tested on monolog latest version? If yes can you please update the composer.json accordingly?
Hello,
it is possible to use monolog-cascade to configure the rollbar handler, I would like to configure all handlers using the yml config file, but I don't know if it's possible, even using the dependency config example, now, I'm using the Rollbar handler as follows:
Cascade::fileConfig(__DIR__ . '/config/dev/log.yml');
Rollbar::init([
'access_token' => 'supercecretaccesstoken',
'environment' => 'development'
]);
Cascade::getLogger('daemon')->pushHandler(
new RollbarHandler(Rollbar::logger(), \Monolog\Logger::ERROR)
);
and my config file looks like that:
formatters:
dashed:
class: Monolog\Formatter\LineFormatter
format: "%datetime% - [%level_name%][%extra.process_id%] - %message%\n"
handlers:
logfile:
class: Monolog\Handler\StreamHandler
level: INFO
formatter: dashed
processors: [memory_processor,pid_processor]
stream: /tmp/daemon.log
processors:
memory_processor:
class: Monolog\Processor\MemoryUsageProcessor
pid_processor:
class: Monolog\Processor\ProcessIdProcessor
loggers:
daemon:
handlers: [logfile]
Hope you can help me.
Thanks in advance.
Diego.
Cascade appears to be ignoring the config file.
I'm using the example code with a change in log level for testing (see code below). However, none of the expected behaviors are happening:
dashed
format./example_info.log
isn't writtenIf I intentionally set a bad path to config file, I get the expected Illegal string offset
errors.
Here is my config file:
formatters:
dashed:
class: Monolog\Formatter\LineFormatter
format: "%datetime%-%channel%.%level_name% - %message%\n"
handlers:
console:
class: Monolog\Handler\StreamHandler
level: ERROR
formatter: dashed
processors: [memory_processor]
stream: php://stdout
info_file_handler:
class: Monolog\Handler\StreamHandler
level: INFO
formatter: dashed
stream: ./example_info.log
processors:
web_processor:
class: Monolog\Processor\WebProcessor
memory_processor:
class: Monolog\Processor\MemoryUsageProcessor
loggers:
myLogger:
handlers: [console, info_file_handler]
processors: [web_processor]
and my PHP:
<?php
include 'vendor/autoload.php';
use Cascade\Cascade;
// configure your loggers
Cascade::fileConfig('config.yaml');
Cascade::getLogger('myApp')->info('Well, that works!');
Cascade::getLogger('myApp')->error('Maybe not...');
and composer.json
:
{
"require": {
"theorchard/monolog-cascade": "^0.5.0"
}
}
It should be possible to extend loggers.
A extended logger should be created by the withName method from monolog.
configured handlers and processors should be added but not replacing existing stuff.
I added this comment onto the end of a closed PR which was probably, with hindsight, rather silly: #103 (comment).
Is anybody able to use the tag successfully? I'm having issues because of the branch alias at https://github.com/theorchard/monolog-cascade/blob/master/composer.json#L43
This stops anything like dev-master#0.6.0-pre from working. I can't use 0.6.0@pre because pre isn't in the composer list of stabilities.
@andymc or @mymac80 could we please have a new tag called 0.6.0-beta1
? That should then allow composer to pull it in as "theorchard/monolog-cascade": "^0.6.0@beta"
.
Alternatively, if it's all working correctly, could it just be 0.6.0
?
I might be missing something here, but I don't seem to be able to use the closure system on constructor arguments, only on setters.
This seems to indicate that for something like the RavenHandler where I need to pass a Raven_Client I am pretty stuck.
It looks like the RedisHandler would have the same problem.
Hi, guys.
I think it would be nice to have a possibility to define namespace/class loggers. So I wrote monolog-cascade-namespaced library. It allows developers to have loggers for specific classes or loggers which will log all the messages from the classes which are in some namespace etc. You know, log4j style. If you need specific logger configuration in the place where you've instantiated it - just set up needed handlers/processors for a needed logger in a config file. Otherwise, you will be given a default logger.
Just want to know your opinion on this. Do you have any plans to implement something like this directly in monolog-cascade? If yes I would get it done. The reason why I haven't made a pull-request to monolog-cascade initially is I just thought it's not more than a wrapper for configuring monolog loggers. But then I thought over and decided to suggest merging)
Hi,
Is it possible to have 'web-2016-05-27.log' instead of just 'web.log'? Or would that be tedious?
Kind regards,
Aschwin Wesselius
Hi,
is it in your roadmap a version of the library compatible with php8?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.