'How to configure log4php in Laravel 8
How to configure log4php in laravel.
First, create composer.json file in your project root and include the following content:
{
"require": {
"apache/log4php": "2.3.0"
}
}
composer install
This code used i'm installed the log4php.
Let's start by creating config.xml file in your project directory.
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="<http://logging.apache.org/log4php/>">
<!--Appender logs message to a file-->
<appender name="default-appender" class="LoggerAppenderFile">
<!--Layout of the message-->
<layout class="LoggerLayoutPattern">
<param name="conversionPattern" value="%date %logger %-5level %msg%n" />
</layout>
<param name="file" value="app.log" /> <!-- This is the log file-->
<param name="append" value="true" />
</appender>
<!--Logger used for logging-->
<logger name="main-logger">
<level value="info" /> <!--Severity level-->
<appender_ref ref="default-appender" /> <!--Reference to the Appender-->
</logger>
</configuration>
The php the following code is used
require __DIR__ . '/vendor/autoload.php';
Logger::configure("config.xml");
$logger = Logger::getLogger('main-logger');
$logger->info("Message to be logged");
Then how to integrate this code in Laravel8?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
