laravel 5.2 custom log file for different tasks

后端 未结 10 1117
再見小時候
再見小時候 2021-01-30 00:36

Can we create a custom log file for different purposes in laravel 5.2 like for order related log entries that should be in order.log and for payment related stuff the entry shou

10条回答
  •  星月不相逢
    2021-01-30 01:06

    I managed my own log function which can be put in helper.php file in app dir.

    if ( ! function_exists( 'write_log' ) ) {
        /**
         * Write log to log file
         *
         * @param string|array|object $log
         */
        function write_log( $log ) {
            if ( env('APP_LOG_LEVEL', 'debug') == 'debug' ) {
                if ( is_array( $log ) || is_object( $log ) ) {
                    file_put_contents(laravelInstallDir().'../debug.log', print_r( $log, true ), FILE_APPEND);
                } else {
                    file_put_contents(laravelInstallDir().'../debug.log', $log, FILE_APPEND);
                }
            }
        }
    }
    

    Please adjust the path laravelInstallDir().'../debug.log' as need

提交回复
热议问题