Integration between Tracy and Nette/IMailer

Notice: This thread is very old.
2bfree
Member | 248
+
0
-

The server we are run our application on does not support native php mail() function.
We are using the Nette\SmtpMailer instead.

Current version of Tracy does not support using mail.mailer service.

Is there any way to force Tracy to send email via this service?

Jan Tvrdík
Nette guru | 2595
+
+1
-

You can set Tracy\Debugger()::getLogger()->mailer to callback of your choice. No built-in integration between Tracy and Nette\Mail is AFAIK currently available.

2bfree
Member | 248
+
+3
-

Current hotfix solution we used is

Tracy\Mailer.php

services:
    tracyMailer:
        class: Tracy\Mailer

    tracy.logger:
        create: Tracy\Debugger::getLogger()
        setup:
            - $mailer([@tracyMailer, 'send'])

thanks for help.

Last edited by 2bfree (2017-01-04 10:13)

Jan Tvrdík
Nette guru | 2595
+
0
-

cc @DavidGrudl How do you feel about adding this bridge to Tracy?


@2bfree Does it work without the factory: line?

2bfree
Member | 248
+
0
-

The factory line is copy of the native tracy.logger service definition from the native DI extension.

As I understand the Neon DI definition, there is no way to overwrite definition of the service by just adding the setup. I thing that you can overwrite all or nothing and there is no way to define the service without class, factory or implement definition? Or am I wrong?

Jan Tvrdík
Nette guru | 2595
+
+1
-

@2bfree So, have you actually tried it without the factory: line? Or do you just believe that it will not work?

If it does not work, we should look into making it work. The first thing you can try is to remove the condition on lines 91 and 93 in TracyExtension, so the code look like this.

$logger = $builder->getDefinition($this->prefix('logger'));
$initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger]));
2bfree
Member | 248
+
0
-

Actually colleague tried it without factory and It works! :) Interesting :)

David Grudl
Nette Core | 8218
+
0
-

Jan Tvrdík wrote:

cc @DavidGrudl How do you feel about adding this bridge to Tracy?

How should it look like?

Jan Tvrdík
Nette guru | 2595
+
0
-

@DavidGrudl Sth like https://gist.github.com/…e2c43e2c9ce5, but with less code duplication, i.e. class accepting IMailer in constructor and providing (with method or __invoke) the callback required by Tracy.

David Grudl
Nette Core | 8218
+
+3
-

That could be useful.

drobec
Member | 1
+
0
-

@DavidGrudl
Hello, I try to setup

services:
    tracyMailer:
        class: App\CoreModule\Mail\Tracy\Mailer(Nette\Mail\IMailer, '%tracy.fromEmail%')

    tracy.logger:
        create: Tracy\Debugger::getLogger()
        setup:
            - $mailer([@tracyMailer, 'send'])

but it is not working. I test it like

public function actionDefault() {
    \Tracy\Debugger::log('test', \Tracy\Debugger::ERROR);
}
public function actionDefault() {
		whatever
	}

always dump form \Tracy\Logger::sendEmai()

	protected function sendEmail($message)
	{
		$snooze = is_numeric($this->emailSnooze)
			? $this->emailSnooze
			: @strtotime($this->emailSnooze) - time(); // @ timezone may not be set

		if ($this->email && $this->mailer
//			&& @filemtime($this->directory . '/email-sent') + $snooze < time() // @ file may not exist
			&& @file_put_contents($this->directory . '/email-sent', 'sent') // @ file may not be writable
		) {
            dump($this->mailer);
			call_user_func($this->mailer, $message, implode(', ', (array) $this->email));
		}
	}

is

array (2)
0 => Tracy\Logger #7505
directory => "/var/www/app/../log" (19)
email => "martin@balaz.me" (15)
fromEmail => null
emailSnooze => "2 days" (6)
mailer => array (2)
0 => Tracy\Logger #7505 { RECURSION }
1 => "defaultMailer" (13)
blueScreen private => Tracy\BlueScreen #5428
info => array (3) [ ... ]
collapsePaths => array (1) [ ... ]
maxDepth => 3
maxLength => 150
panels private => array (5) [ ... ]
1 => "defaultMailer" (13)

How can I force smtp mailer? Thanks

Last edited by drobec (2017-08-18 19:25)