0
0

More than 3 years have passed since last update.

Laravelで暗号化したログをコマンドで復号してみた

Last updated at Posted at 2019-08-02

暗号化

フォームの入力値を暗号化してログに出力している。

use Log;

$params = フォームで入力された値
$encryptParams = encrypt($params);
Log::info($encryptParams);

Logでてくるか処理を流して確かめてみる。
storage/logs/laravel-××××-××-××.log
(Laravelデフォルトだとログファイル名が違う。詳しくは下記のおまけ見てください。)

[2019-08-01 17:29:52] local.INFO: eyJpdiI6InFGbkpudVRpVjlMUjlhbnRFdTRRRGc9PSIs・・・ 以下省略  

コマンドクラス作成

php artisan make:command decryptCommand

app/Console/Commands/decryptCommand.phpが生成される。

protected $signature = 'Log:decrypt';//artisanコマンド名
protected $description = 'ログの復号コマンド';//コマンドの説明
public function __construct()
    {
        parent::__construct();
    }
public function handle()
    {
        $params = $this->ask('Please enter a log command');//コマンド実行時の問いかけをask()に書く
        $decryptParams = decrypt($params);//入力値を復号処理
        print_r($decryptParams);//ターミナル画面に復号したデータを出力
    }

artisanコマンドを追加登録

app/Console/kernel.php

protected $commands = [
        decryptCommand::class,
    ];

追加したらコマンド一覧に「Log:decrypt」が追加されていることを確認する

php artisan 

複合方法

php artisan Log:decrypt

すると

 Please enter a log command:
 > eyJpdiI6InFGbkpudVRpVjlMUjlhbnRFdTRRRGc9PSIs・・・ 以下省略

Please enter a log command: と言われるのでログに吐かれてる暗号化コードをコピペ

複合される。

おまけ

ログファイルを保存する日数を変更する

ログファイル出力設定のデフォルトは以下のようになっている


    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 14,//保存する日数
        ],
     以下省略

'daily' の 'days' を変更すればOK

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0