I have installed the Rollbar 7.0 into Laravel 8.0. PHP version is 7.4
I am trying to send a test exception message using a simple Console command but that sends me nothing.
My configs are the following:
config/app.php:
return [
'providers' => [
Rollbar\Laravel\RollbarServiceProvider::class
...
]
config/logging.php:
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['other', 'rollbar'],
'ignore_exceptions' => false,
],
'rollbar' => [
'driver' => 'monolog',
'handler' => MonologHandler::class,
'access_token' => env('ROLLBAR_TOKEN'),
'level' => env('ROLLBAR_LEVEL'),
'enabled' => true,
'environment' => env('ROLLBAR_ENVIRONMENT'),
]
....
config/services.php (but seems to be that it doesn't work)
'rollbar' => [
'access_token' => env('ROLLBAR_TOKEN'),
'environment' => env('ROLLBAR_ENVIRONMENT'),
'level' => env('ROLLBAR_LEVEL')
],
app.env:
ROLLBAR_TOKEN=real_token
ROLLBAR_LEVEL=debug
ROLLBAR_ENVIRONMENT=backend_test
And the console command itself has the following view:
public function handle()
{
// Rollbar::init([
// 'driver' => 'monolog',
// 'handler' => MonologHandler::class,
// 'access_token' => env('ROLLBAR_TOKEN'),
// 'level' => env('ROLLBAR_LEVEL'),
// 'enabled' => true,
// 'environment' => env('ROLLBAR_ENVIRONMENT'),
// ]);
try{
$x = 4/0;
} catch(\Exception $exception) {
Rollbar::error('caught demo exception', ["details" => $exception->getMessage()]));
Rollbar::flush();
exit(1);
}
}
So when it is like this, the rollbar stays silent. But if I uncomment the initialisation, that works well, sending a debug message to the rollbar.
That doesn't work all over the project too.
Could you please advice me, what could I do here in order to make it work globally with initialising in every file?
upd: I've also cleared config cache and tried to make a rollbar as a default
Laravel in app/logging.php has a default channel configuration. Normally "default" should mean that there are some other working channel too but here, somehow it the meaning is like "the only used channel". Or I just do not fully understand how should it work. So my rollbar channel seems to be overriden by the another "default" one, that is why the system doesn't use it. So the solution is to switch the default channel:
'default' => env('LOG_CHANNEL', 'stack'),
when the rollbar is included to stack channel or just
'default' => env('LOG_CHANNEL', 'rollbar'),
when it is not.
Related
I need to send a few mails with my laravel application, and they are not really personalized. I've used the markdown mail system in laravel, and everything was smooth for the tests. I had mailtrap setup to catch all the mails, no problems.
Now I have to use mailjet to send mails - not to create emails and everything, just to have an adress to send them and a way to know where they did go. I've installed the laravel-mailjet package, I've done everything in the doc (except the last part, my mails already work), but no luck, nothing works. I don't have any error in the logs, I don't have any error when the mail is supposed to be thrown, it just kinda don't try to send the mail at all. I've tried on local and prod (I was thinking that maybe it was because of the dns), everything is perfectly setup between my dns and mailjet, but I can't launch any mail and google is no help on this one.
.env
MAIL_MAILER=mailjet
MAIL_HOST=in-v3.mailjet.com
MAIL_PORT=587
MAIL_USERNAME={api key}
MAIL_PASSWORD={api secret}
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS={mail}
MAIL_FROM_NAME="${APP_NAME}"
MAILJET_APIKEY={api key}
MAILJET_APISECRET={api secret}
app.php
'providers' => [
...
Mailjet\LaravelMailjet\MailjetServiceProvider::class,
Mailjet\LaravelMailjet\MailjetMailServiceProvider::class,
],
'aliases' => [
...
'Mailjet' => Mailjet\LaravelMailjet\Facades\Mailjet::class,
],
mail.php
'mailers' => [
....
'mailjet' => [
'transport' => 'mailjet',
],
],
services.php
'mailjet' => [
'key' => env('MAILJET_APIKEY'),
'secret' => env('MAILJET_APISECRET'),
'transactional' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v3.1',
'call' => true,
'secured' => true
]
],
'common' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v3',
'call' => true,
'secured' => true
]
],
'v4' => [
'call' => true,
'options' => [
'url' => 'api.mailjet.com',
'version' => 'v4',
'call' => true,
'secured' => true
]
],
]
I've tried to erase all my modifications and just let the .env, with no luck too. What am I missing?
Ok, found my problem. The whole setup was good, it was in the Mailable class that I was missing something; the mail used to send the confirmation wasn't register in Mailjet. Just a modification in the ->from(email) in the class and everything works now.
It's just weird that I couldn't get any error message that could give me clue on what was going on, no error in logs and no error on Mailjet.
I have a Laravel 5.6 project and I want to configure it such that high level errors are emailed to me.
I have added an email channel to logging.php config file and specified Monolog's Swiftmailer as the handler but since it needs a mailer instance and message in its constructor I don't know what values should be supplied.
Any help is much appreciated.
PS: I do know there are packages for this purpose but think this should be simple enough to do manually.
'email' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\SwiftMailerHandler::class,
'handler_with' => [
'mailer' => ?,
'message' => ?,
],
],
With Lavarel 7.x you can solve it like this
'smtp-sys' => [
'driver' => 'monolog',
'level' => 'info',
'handler' => SwiftMailerHandler::class,
'handler_with' => [
'mailer' => new Swift_Mailer( (new Swift_SmtpTransport(env('MAIL_HOST_SYS'), env('MAIL_PORT_SYS'), env('MAIL_ENCRYPTION', 'tls')))->setUsername(env('MAIL_USERNAME_SYS'))->setPassword(env('MAIL_PASSWORD_SYS'))),
'message' => (new Swift_Message('[LOG] Exception'))
->setFrom([env('MAIL_USERNAME_SYS') => 'Dev'])
->setTo([env('MAIL_USERNAME_SYS') => 'Dev'])
],
],
It might be a little late but from Symfony SwiftMailer documentation you should use something like this:
...
'email' => [
'driver' => 'monolog',
'level' => 'critical',
'handler' => SwiftMailerHandler::class,
'handler_with' => [
'mailer' => (new Swift_SmtpTransport(env('MAIL_HOST'), env('MAIL_PORT'), env('MAIL_ENCRYPTION')))
->setUsername(env('MAIL_USERNAME'))
->setPassword(env('MAIL_PASSWORD')),
'message' => (new Swift_Message('[LOG] Exception'))
->setFrom([env('LOG_MAIL_FROM_ADDRESS') => env('LOG_MAIL_FROM_NAME')])
->setTo([env('LOG_MAIL_TO_ADDRESS') => 'Dev'])
->setBody('Here is the message itself')
],
'formatter' => HtmlFormatter::class,
],
...
How do laravel print out some string on console when running php artisan serve?
I tried Log::info but it isn't working.
It's very simple.
You can call it from anywhere in APP.
$out = new \Symfony\Component\Console\Output\ConsoleOutput();
$out->writeln("Hello from Terminal");
Try with
error_log('message here.');
Read More
If You ant add LOG
Log::info('message');
If LOG with an array
Log::info(json_encode($array));
Import Illuminate\Support\Facades\Log;
Laravel 5.6 simplified this because you now have a logging.php config file you could leverage.
The key thing to know is that you want to output to stdout and php has a stream wrapper built-in called php://stdout. Given that, you could add channel for that wrapper. You would add the stdout "channel" to your channels that you will be logging to.
Here's how the config will basically look:
<?php
return [
'default' => env('LOG_CHANNEL', 'stack'),
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single','stdout'],
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
],
'stdout' => [
'driver' => 'monolog',
'handler' => StreamHandler::class,
'with' => [
'stream' => 'php://stdout',
],
],
];
I have more information here - Laravel 5.6 - Write to the Console
You've to config where laravel to store the logs. Default Log::info() put the log in the log file not the console. you can use tail -f logpath to see the log.
You can call info() method
$this->info("Your Message");
I am trying to use EAuth extension in Yii2 advanced application. I installed it through composer and it installed it under vendor directory and configured as mentioned here (did the config in common/config/main). So, following is the directory structure for that:
root
vendor
nodege
lightopenid
provider
*files go here*
yii2-eauth
src
*files go here*
EAuth.php is under src folder. In controller I have done this in use:
use nodge\eauth\EAuth;
and when I do this:
$eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
I get the following error:
Class nodge\eauth\EAuth does not exist
What am I doing wrong? Any help?
Update:
This is my config:
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'eauth' => [
'class' => 'nodge\eauth\EAuth',
'popup' => true, // Use the popup window instead of redirecting.
'cache' => false, // Cache component name or false to disable cache. Defaults to 'cache' on production environments.
'cacheExpire' => 0, // Cache lifetime. Defaults to 0 - means unlimited.
'httpClient' => [
// uncomment this to use streams in safe_mode
//'useStreamsFallback' => true,
],
'services' => [// You can change the providers and their classes.
'google' => [
// register your app here: https://code.google.com/apis/console/
'class' => 'nodge\eauth\services\GoogleOAuth2Service',
'clientId' => '...',
'clientSecret' => '...',
'title' => 'Google',
],
'facebook' => [
// register your app here: https://developers.facebook.com/apps/
'class' => 'nodge\eauth\services\FacebookOAuth2Service',
'clientId' => '---',
'clientSecret' => '---',
],
'yahoo' => [
'class' => 'nodge\eauth\services\YahooOpenIDService',
//'realm' => '*.example.org', // your domain, can be with wildcard to authenticate on subdomains.
],
],
],
],
I followed the instructions to enable query logging in cakephp v3.
http://book.cakephp.org/3.0/en/orm/database-basics.html#query-logging
// Turn query logging on.
$conn->logQueries(true);
// Turn query logging off
$conn->logQueries(false);
use Cake\Log\Log;
// Console logging
Log::config('queries', [
'className' => 'Console',
'stream' => 'php://stderr',
'scopes' => ['queriesLog']
]);
// File logging
Log::config('queries', [
'className' => 'File',
'path' => LOGS,
'file' => 'queries.log',
'scopes' => ['queriesLog']
]);
After enabling query logging, I am not able to find the log file. I looked under the logs folder. I don't see any queries.log. Where can the log file be found?
I've created a test project. Created a simple model so I can parse the data.
In the controller, I added these namespaces:
use App\Model\Table\User; // <---My model
use Cake\ORM\TableRegistry;
use Cake\Log\Log;
use Cake\Datasource\ConnectionManager;
Here's the basic data parse in a controller:
$conn = ConnectionManager::get('default');
Log::config('queries', [
'className' => 'File',
'path' => LOGS,
'file' => 'queries.log',
'scopes' => ['queriesLog']
]);
$users = TableRegistry::get('User');
$conn->logQueries(true);
$q = $users->find('all');
$results = $q->all();
$conn->logQueries(false);
All of this works just great.
Log also should be enabled in datasources config by specify 'log' => true:
'Datasources' => [
'default' => [
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'host' => 'localhost',
...
'log' => true,
...
'url' => env('DATABASE_URL', null),
],