如何修改lumen storage path/log path

赞赏 2016-07-12

最近接触lumen ,用来做api. 发现他的logs放在 项目里 /storage/logs/lumen.log, 放在项目里有好多弊端,发布代码回冲掉,想把他转移到机器 /var/logs目录。发现Lumen框架没有配置项


代码如下:

  • 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);
    }
  • vendor/laravel/lumen-framework/src/helpers.php
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(). 修改如下:

  • bootstrap/app.php
/**
 * 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 配置

  • 亲测试通过,有问题点击追问按钮留言交流!
登陆后阅读全文
阅读 2977 赞赏 2 有用 32 没用 0 收藏 1 分享

   


作者声明:本篇文章系本人原创,欢迎分享,但未经许可,谢绝转载。

0 条留言

有经验的老司机的头像

有经验的老司机

年轻人,走!我带你。

有料推荐

这世界欠我一个这样的老公!

高校学生模仿“世界名画”摆拍,可以说是戏精本精了

iPhone X 跌破发行价,苏宁200亿入股恒大 | 财经日日评

果然是高手!这次在日本,特朗普竹杠敲得不是一般狠

资深黄牛现身说法:iPhone X价格秒变不停,就像炒股一样

长一样的双胞胎也能识别?蚂蚁金服发布「眼纹识别」技术

苏联是怎么被阿富汗拖垮的?

美团或入局「分时租赁」共享汽车,王兴要大笔投入「泛出行」领域了? | 36氪独家

你或许被“一盘番茄炒蛋”刷屏了,但有人辛酸,有人质疑

iPhone X发售前夜,黄牛与苹果公司的不安

他的文章

电脑无线连接安卓手机 进入android命令行模式(完胜adb shell数据线连接方式)

iTerm2配置clone session功能

如何科学上网(翻墙)

php5.6-和php5.6 CURL 上传文件的一个坑

如何修改lumen storage path/log path

php.ini 设置了 error_log 为什么不生效?

IP查询二分法的运用

iframe 的高度自适应 iframe 内容页面的高度解决方案

手机扫一扫
分享文章