-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftMailerHandler configuration #59
Comments
Hello, You can look into setting up handlers that take objects as arguments in their constructor: It should look something like: handlers:
swift:
class: Monolog\Handler\SwiftMailerHandler
mailer:
class: Swift_Mailer
transport:
class: Swift_SmtpTransport
# Below is optional cause Cascade should pick up
# default values for you
#host: '127.0.0.1'
#port: 25
message:
class: Swift_Message
subject: 'Hello'
body: 'How are you?'
level: DEBUG
loggers:
mylogger:
handlers: [swift] This has not been tested I just put it together by looking at different params of the constructors From the ReadMe:
Param names in your config just have to match the param names from the constructor. I hope this helps. |
Thank you for the timely reply on the question. I tried to set up Swift Handler before sending you this question with the usage examples for RavenClient and Redis but I could not get that to work. With your help I did set up my config for SwiftHandler correctly as previously I missed to provide the object for message instead I was just passing a string as a message. Although we are providing all the required objects now, I am still getting the same error at the time of instantiation.
I think this is because we are not recursively instantiating the objects before calling the SwiftHandler. I logged the constructor arguments that Cascade is passing to SwiftHandler and they are passed in as arrays instead of instances of the respective classes. Can you please look into this when possible and confirm ? `Array
)` |
So, I tried 2 things:
public function testLoadDependency()
{
$options = array(
'class' => 'Cascade\Tests\Fixtures\DependentClass',
'something_else' => 'Hello',
'dependency' => array(
'class' => 'Cascade\Tests\Fixtures\DependentClass',
'something_else' => 'Hi',
'dependency' => array(
'class' => 'Cascade\Tests\Fixtures\SampleClass',
'mandatory' => 'someValue',
)
)
);
$loader = new ClassLoader($options);
$instance = $loader->load();
$expectedInstance = new DependentClass(
new DependentClass(
new SampleClass('someValue'),
'Hi'
),
'Hello'
);
$this->assertEquals($expectedInstance, $instance);
} That test passed. That piece of code was local I haven't committed it.
<?php
$yaml = <<<EOD
handlers:
swift:
class: Monolog\Handler\SwiftMailerHandler
mailer:
class: Swift_Mailer
transport:
class: Swift_SmtpTransport
host: '192.168.0.1'
port: 96
message:
class: Swift_Message
subject: 'Hello'
body: 'How are you?'
level: DEBUG
loggers:
mylogger:
handlers: [swift]
EOD;
require_once(realpath(__DIR__.'/vendor/autoload.php'));
use Cascade\Cascade;
Cascade::fileConfig($yaml);
print_r(Cascade::logger('mylogger')->getHandlers()); It worked as well. So, I am not sure what's wrong here... I assume there must be something wrong in your Yaml. Check your indentation. Another thing to verify is the version you are using. Object dependency support for options was introduced in 0.2.0. |
The same question |
$transport->setUsername(); |
You might try
Cascade allows you to call functions with params upon class instantiation. So here, it should call:
See complete config below. I haven't tested it.
|
Unfortunately your configuration can't work because setUsername and setPassword are not Swift_SmtpTransport methods nor they are in any inherited class. They are injected in magic method __call instead, so they can't be recognized by reflection. |
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 ?
The text was updated successfully, but these errors were encountered: