Laravel 5 - change default log location, move log file outside the app - laravel

How can I change default log file location <project-name>/storage/logs/laravel.log to something like /var/logs/<project-name>/laravel.log?

I resolved this case by using errorlog logging model and configuring webserver.
1. Configure Laravel:
In config/app.php configuration file:
'log' => 'errorlog'
Read more about Laravel log configuration: http://laravel.com/docs/5.1/errors#configuration
2. Configure webserver (in my case Nginx):
error_log /var/log/nginx/<project_name>-error.log;

For those who don't want to use errorlog and just really want to replace the file to log to, you can do this:
\Log::useFiles(env('APP_LOG_FILE'), config('app.log_level', 'debug'));
$handlers = \Log::getMonolog()->getHandlers();
$handler = array_shift($handlers);
$handler->setBubble(false);
on App\Providers\AppServiceProvider.php or any Provider for that matter. This will log to the value of APP_LOG_FILE instead of the default laravel.log. Set bubbling to true and the application will log on both files.

For anyone still coming across this post in hopes of changing their log file location, I believe this is now easier in newer versions of Laravel. I am currently using 8.x
In your /config/logging.php you can define the path for your single and daily logs. Just update whichever one your are looking to change. Just make sure you also include the name of the log file, not just the path to where you'd like it saved.
'single' => [
'driver' => 'single',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
]

Related

Laravel's UploadedFile store method's behavior doesn't correspond with Storage::url behavior

So I am having an UploadedFile I want to upload to specific disk 'local'.
// $storedFilePath == "kml/uploadedfile.xml";
$storedFilePath = $request->file->store("kml", "local");
The file is actually uploaded into storage/app/kml/uploadedfile.xml - that is CORRECT, following the config for local disk:
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
On the other hand, I need to get the full URL path (relative from project root) to this file. I tried
Storage::disk("local")->url($storedFilePath);
But this gets me /storage/kml/uploadedfile.xml - note the path does miss app/ folder.
One line in Laravel's FilesystemAdapter.php that determines the path is here (function getLocalUrl):
$path = '/storage/'.$path;
Given the fact that $path is starting with kml/ it perfectly makes sense that it doesn't work. My question is, why. Why are these not corresponding and how do I get the full internal (so not public) path?
Ok so it was actually quite simple, yet I believe the documentation about this in Laravel is quite confusing. Laravel is just expecting everyone to have a symlink from public/storage into storage/app/public
They somehow even think that everyone using local disk and method url wants to know the public url, which is quite always true only for public disk.
config/filesystems.php
added 'url'
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'url' => storage_path('app')
],
Works correctly now

spatie/laravel-backup notifications not posting

Using Laravel 5.3 and v4 from spatie/laravel-backup package.
I am using this package from Spatie which allows me to take backups using a simple terminal command. It is pretty straight forward to set up and when I run the command the backup runs as intended.
But there is also an option in the config file to set notifications (send mail, post to slack, ...) after a backup. This does not seem to do anything for me. I neither receive mails (and I have set my mailaddress) or see posts to my dedicated slack channel (and i have added the webhook).
I have already included the following composer packages since researching this problem:
Guzzlehttp/guzzle
maknz/slack-laravel
maknz/slack
This is the simple notifications section in the config file:
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class => ['mail'],
],
/*
* Here you can specify the notifiable to which the notifications should be sent. The default
* notifiable will use the variables specified in this config file.
*/
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
'mail' => [
'to' => 'nicolas#******.***',
],
'slack' => [
'webhook_url' => 'https://hooks.slack.com/services/*****/*****/*************',
],
],
Not really sure if I am forgetting something? Thanks for the help
The output I get in terminal after running the commands: gist.github
Extra:
This is a talk at Laracon EU 2016, where the creator (Freek) shows off his package.

Yii2 Themes Advanced Template

OK, i know this question has been asked many times, however not one of the answers seems to work, i can only assume Yii2 has been updated since then.
Here goes:
I am trying to change the frontend theme of my Yii2 Advance Application.
I chose a theme from http://yii2.themefactory.net/
I downloaded the theme and completed the following steps that i have found on various sites on the web.
Created a folder myApp/frontend/themes
Placed the files from the download into this folder
Changed the myApp/frontend/config/main.php to include the following
'view' => [
'theme' => [
'pathMap' => [
'#app/views' => '#app/themes/interior'
],
'baseUrl' => '#web/themes/interior',
],
],
I have tried various ways of the baseUrl. and it doesn't seem to find the CSS file, as i have read the theme files shouldn't be placed in the web folder.
However i cannot see anyway of reading these CSS files without them being placed in the web folder.
So do i have to split the theme and place the views in the theme folder and then the CSS in another folder under the web folder.
Sorry if this makes no sense, but i have read so many posts across so many sites that all contradict each other.
Let me know any thoughts
Thanks.
Further information.
The issue seems to be that the themes folder myApp/frontend/themes contains all the theme files including the CSS. When the website is run it cannot link to these CSS files.
So is the answer that i need to split the themes folder, keep the layouts in the myApp/frontend/themes and then put the CSS in a similar folder in myApp/frontend/web/themes ??
** OK Solution - However i am not sue this is the correct way **
In the theme folder i downloaded there was two folders layouts and files
I created two folders myApp/frontend/themes and myApp/frontend/web/themes
I put the layouts folder into the mayApp/frontend/themes/THEME_NAME folder and the files folder into myApp/frontend/themes/web/THEME_NAME/ folder
I then setup the main.php confgi file like this
'view' => [
'theme' => [
'pathMap' => ['#app/views' => '#app/themes/houses-on-water'],
'baseUrl' => '#web/themes/houses-on-water',
],
],
I am not sure this is the correct way but it is working
Regards
Liam
Copy content in:
MYAPP/frontend/web/themes/MYTHEME
Change your MYAPP/frontend/config/main.php
'view' => [
'theme' => [
'pathMap' => [
//Only for change layout/main.php location
'#app/views' => '#webroot/themes/MYTHEME'
],
'baseUrl' => '#web/themes/MYTHEME',
'basePath' => '#webroot/themes/MYTHEME',
],
],
Reference:
https://www.yiiframework.com/wiki/667/yii-2-list-of-path-aliases-available-with-default-basic-and-advanced-app
https://www.yiiframework.com/doc/guide/2.0/en/output-theming
Enjoy
For frontend try changing this way:
'view' => [ 'theme' => [
'pathMap' => [ '#frontend/views' => '#frontend/themes/interior' ],
'baseUrl' => '#web/themes/interior'],
],
Just use theme under web/themes folder, and change your code to this :
'view' => [
'theme' => [
'pathMap' => ['#app/views' => '#app/web/themes/houses-on-water'],
'baseUrl' => '#web/themes/houses-on-water',
],
],
It's work to me.

Using Yii2's default messages

I can't figure out, how to use Yii's default messages, without overwriting them with the message command.
I have 2 translation categories: app, data.
I'd like to use the default messages, like "Are you sure you want to delete this item?" and "(not set)" from the Yii2 core, but if I use Yii::t('yii', 'Are you sure you want to delete this item?') and then run the yii message command, it creates a yii.php file in the messages folder with this token.
Part of my config:
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
],
'data*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
],
],
],
How should I set up my config to use the built in texts and not to overwrite them?
You don't have to do anything. The yii-category is automatically defined as soon as you use translation and it points to the messages in the framework.
That it creates an empty file is for 'yii' is normal, because you actually use that category in your code. This is unrelated to where the messages will be loaded from during normal execution.
Just make sure that you configure your apps' language and sourceLanguage correctly if not already done.

laravel rename lara_admin bundle name in url

I am using lara_admin bundle for my admin panel which is accessible under msmohan.com/lara_admin path.
I don't want to show the lara_admin in the url. So can anyone tell me is there any option for renaming the url link?
When you install a module and register it, you set it up like with this configuration:
'lara_admin' => array(
'handles' => 'lara_admin',
'auto' => true,
),
When the bundle registers routes, it uses that handles key as the basis for the route. So in the bundle's routes.php file, you can see:
Route::get('(:bundle)/login', 'lara_admin::sessions#index');
See that (:bundle)? That tells Laravel to look up the handles key. So if you change your registration for the lara_admin bundle to:
'lara_admin' => array(
'handles' => 'admin',
'auto' => true,
),
It will now be at /admin/login, for example.

Resources