原文网址:https://www.youyong.top/article/1158dfb6eb40
最近接触lumen ,用来做api. 发现他的logs放在 项目里 /storage/logs/lumen.log, 放在项目里有好多弊端,发布代码回冲掉,想把他转移到机器 /var/logs目录。发现Lumen框架没有配置项
原文网址:https://www.youyong.top/article/1158dfb6eb40
最近接触lumen ,用来做api. 发现他的logs放在 项目里 /storage/logs/lumen.log, 放在项目里有好多弊端,发布代码回冲掉,想把他转移到机器 /var/logs目录。发现Lumen框架没有配置项
原文网址:https://www.youyong.top/article/1158dfb6eb40
代码如下:
vendor/laravel/lumen-framework/src/Application.php
/**
* Get the Monolog handler for the application.
*
* @return \Monolog\Handler\AbstractHandler
*/
protected function getMonologHandler()
{
return (new StreamHandler(storage_path('logs/lumen.log'), Logger::DEBUG))
->setFormatter(new LineFormatter(null, null, true, true));
}
/**
* Get the storage path for the application.
*
* @param string|null $path
* @return string
*/
public function storagePath($path = null)
{
return $this->basePath().'/storage'.($path ? '/'.$path : $path);
}
if (! function_exists('storage_path')) {
/**
* Get the path to the storage folder.
*
* @param string $path
* @return string
*/
function storage_path($path = '')
{
return app()->storagePath($path);
}
}
storagePath()
不是最优解,对框架造成了污染。最优方案继承 vendor/laravel/lumen-framework/src/Application.php
覆盖 storagePath()
. 修改如下:
/**
* Class Lapp 新增子类
*/
class Lapp extends Laravel\Lumen\Application {
public function __construct($basePath = null)
{
parent::__construct($basePath = null);
}
/**
* overwrite lumen application storagepath for storagepath configable;
* @param null $path
* @return string
*/
public function storagePath($path = null)
{
return (env('STORAGE_PATH') ? env('STORAGE_PATH') : $this->basePath()) . '/storage' . ($path ? '/'.$path : $path);
}
}
//这里注释掉
//$app = new Laravel\Lumen\Application(
// realpath(__DIR__.'/../')
//);
注意在项目.env 增加 STORAGE_PATH=yourstorgepath 配置
作者声明:本篇文章系本人原创,欢迎分享,但未经许可,谢绝转载。
共 0 条留言