log4php Use and Configuration

Source: Internet
Author: User

1, add log4php package in the project

2. Configuration

<Configurationxmlns= "http://logging.apache.org/log4php/">    <Appendername= "Default"class= "Loggerappenderconsole" />    <Appendername= "Basic_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "Logs/basic.%s.log" />        <paramname= "Datepattern"value= "y-m-d" />    </Appender>    <Root>        < Levelvalue= "Debug" />        <Appender_refref= "Basic_file_appender" />    </Root>        <Appendername= "Route_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date%p [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "Logs/route.%s.log" />        <paramname= "threshold"value= "Error"/>        <paramname= "Append"value= "true" />        <paramname= "Datepattern"value= "y-m-d" />    </Appender>    <Loggername= "Route">        < Levelvalue= "Debug" />        <Appender_refref= "Route_file_appender" />    </Logger>         <Appendername= "Session_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "Logs/session.%s.log" />        <paramname= "Datepattern"value= "y-m-d" />    </Appender>    <Loggername= "Session">        < Levelvalue= "Debug" />        <Appender_refref= "Session_file_appender" />    </Logger>         <Appendername= "Inventorytransaction_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "Logs/inventorytransaction.%s.log" />        <paramname= "Datepattern"value= "y-m-d" />    </Appender>    <Loggername= "Inventorytransaction">        < Levelvalue= "Debug"/>        <Appender_refref= "Inventorytransaction_file_appender" />    </Logger>        <Appendername= "Reserve_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "/data0/wmsinventoryapi/reserve.%s.log" />        <paramname= "Datepattern"value= "Y-m-d.h" />    </Appender>    <Loggername= "Reserve">        < Levelvalue= "Debug"/>        <Appender_refref= "Reserve_file_appender" />    </Logger>         <Appendername= "Exception_file_appender"class= "Loggerappenderdailyfile">        <Layoutclass= "Loggerlayoutpattern">            <paramname= "Conversionpattern"value= "%date [%logger]%message%newline" />        </Layout>        <paramname= "File"value= "Logs/exception.%s.log" />        <paramname= "Datepattern"value= "y-m-d" />    </Appender>    <Loggername= "Exception">        < Levelvalue= "Error"/>        <Appender_refref= "Exception_file_appender" />    </Logger>    </Configuration>

The format meaning of the Conversionpattern parameter
Format name meaning
The full name of the class to which the%c output log information belongs
%d the date or time of the output log time, the default format is ISO8601, or the format can be specified later, for example:%d{yyy-mm-dd HH:mm:ss}, output similar to: 2002-10-18-22:10:28
%f the class name of the class to which the output log information belongs
%l the occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m the information specified in the output code, such as a message in log (message)
%n output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fatal. Debug if the debug () output is called, and so on
%r the number of milliseconds that the output from the application starts to output this log information
%t output The name of the thread that generated the log event

3. Print logs using log4php

Logger::getlogger ("Route")->error (Flight::request ());

4. Output results

log4php Use and Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.