Laravel5.1 将终端执行的日志输出到其他文件

目前由于在我们的测试环境的项目里面,为了方便,laravel的schedule命令是由root用户运行的,这就会导致较早运行的命令生成的日志文件的owner是root,但是http请求是由apache用户接管的,导致http请求生成的日志无法写到日志文件中

我做了如下的修改,让schedule或者手动执行的命令产生的日志转到指定的日志文件中,http请求的日志还是在原来的日志文件中,两处来的日志互不干扰。

增加文件app/Console/Bootstrap/ConfigureConsoleLogging.php:

<?php

/**
 * This file is part of project alg-shopping.
 *
 * Author: Jake
 * Create: 2019-03-15 10:51:21
 */

namespace App\Console\Bootstrap;

use Illuminate\Log\Writer;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\ConfigureLogging;

class ConfigureConsoleLogging extends ConfigureLogging
{
    /**
     * Configure the Monolog handlers for the application.
     *
     * @param  \Illuminate\Contracts\Foundation\Application|\Illuminate\Foundation\Application  $app
     * @param  \Illuminate\Log\Writer  $log
     * @return void
     */
    protected function configureDailyHandler(Application $app, Writer $log)
    {
        $log->useDailyFiles(
            $app->storagePath().'/logs/console.log',
            $app->make('config')->get('app.log_max_files', 10)
        );
    }
}

app/Console/Kernel.php中增加如下方法:

   public function bootstrap()
    {
        $this->app->bind(
            'Illuminate\Foundation\Bootstrap\ConfigureLogging',
            'App\Console\Bootstrap\ConfigureConsoleLogging'
        );

        parent::bootstrap();
    }

这样终端下产生的日志会写入到storage/logs/console-xxxx-xx-xx.log中,而原来的api请求的日志则还是写入到原来的storage/logs/laravel-xxxx-xx-xx.log中,互不干扰。

编译安装php7.4

以前在我的centos7服务器上编译安装了php7.3,这一次先打算在自己的mac上试一试php7.4。

# 下载源码
wget https://www.php.net/distributions/php-7.4.1.tar.bz2

# 解压&切换到目录下
tar -jxvf php-7.4.1.tar.bz2 && cd php-7.4.1

# 执行configure
./configure --prefix=/usr/local/opt/php@7.4 --with-config-file-path=/usr/local/etc/php/7.4 --enable-fpm --with-fpm-user=_www --with-fpm-group=_www --enable-intl --enable-mbstring --enable-pcntl --enable-mysqlnd

报错:

checking for icu-uc >= 50.1 icu-io icu-i18n... no
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ICU_CFLAGS
and ICU_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

# 执行
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

# 再次configurre
./configure --prefix=/usr/local/opt/php@7.4 --with-config-file-path=/usr/local/etc/php/7.4 --enable-fpm --with-fpm-user=_www --with-fpm-group=_www --enable-intl --enable-mbstring --enable-pcntl --enable-mysqlnd

报错:

configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

# 安装oniguruma

> 参考:http://macappstore.org/oniguruma/

brew install oniguruma

# 再次configurre
./configure --prefix=/usr/local/opt/php@7.4 --with-config-file-path=/usr/local/etc/php/7.4 --enable-fpm --with-fpm-user=_www --with-fpm-group=_www --enable-intl --enable-mbstring --enable-pcntl --enable-mysqlnd

## 最后
make && make install

homebrew查看源配置

homebrew的配置分成三个目录,分别是brew(brew --repo)、homebrew/core(brew --repo homebrew/core),homebrew/cask(brew --repo homebrew/cask),在目录中可以通过git remote get-url origin来查看当前的源的URL,可以通过以下三个命令设置为默认值,最后不要忘记了更新哦~

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

mac iterm2/zsh 复制长文本时等待太长时间

有时候需要粘贴一些比较长的curl命令到终端执行,但是需要等待非常长的时间,于是找到了下面的修改办法。

修改文件~/oh-my-zsh/lib/misc.zsh,将以下代码(大概就在前几行)注释掉后,重新开启终端即可:

if [[ $ZSH_VERSION != 5.1.1 ]]; then
  for d in $fpath; do
    if [[ -e "$d/url-quote-magic" ]]; then
           if is-at-least 5.1; then
               autoload -Uz bracketed-paste-magic
               zle -N bracketed-paste bracketed-paste-magic
           fi
           autoload -Uz url-quote-magic
           zle -N self-insert url-quote-magic
      break
    fi
  done
fi

相关讨论:

  1. https://github.com/zeit/hyper/issues/1276
  2. https://apple.stackexchange.com/questions/312795/zsh-paste-from-the-clipboard-a-command-takes-a-few-second-to-be-write-in-the-ter