Skip to content

Instantly share code, notes, and snippets.

@goodjack
Forked from technoknol/log4php-for-laravel.php
Last active August 11, 2017 09:45
Show Gist options
  • Save goodjack/a6ba7d75e1406de64f51089b9853f2db to your computer and use it in GitHub Desktop.
Save goodjack/a6ba7d75e1406de64f51089b9853f2db to your computer and use it in GitHub Desktop.
Working log4php in Laravel (5.4)
<?php
// Middleware:
// app\Http\Middleware\Log4php.php
namespace App\Http\Middleware;
use Closure;
class Log4php
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$logger_config = \Config::get('log4php.main_logger');
\Logger::configure($logger_config);
// $logger = \Logger::getLogger('html');
// $log = [];
// $log['url'] = $request->getUri();
// $log['method'] = $request->getMethod();
// $log['client_ip'] = $request->getClientIp();
// $log['request'] = $request->all();
// if(isset($request->header()['authorization'])) {
// $log['headers'] = $request->header()['authorization'] ;
// }
// $logger->info(json_encode($log));
return $next($request);
}
}
// Kernel.php
// Location : \app\Http\Kernel.php
// Add following
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\CORS::class,
\App\Http\Middleware\Log4php::class // This is added, Adjust other elements according to you.
];
// Config file
// Location : config\log4php.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Constants
|--------------------------------------------------------------------------
|
| Added By: Shyam Makwana
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, SparkPost and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
'main_logger' => array(
'rootLogger' => array(
'appenders' => ['facebook-instantarticles-transformer']
),
'appenders' => array(
'facebook-instantarticles-transformer' => [
'class' => 'LoggerAppenderConsole',
'threshold' => 'OFF',
]
)
)
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment