Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:49:32+00:00 2026-06-12T21:49:32+00:00

I am using log4php to log messages in php . I have the following

  • 0

I am using log4php to log messages in php. I have the following xml configuration

<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="myAppender" class="LoggerAppenderFile">
        <layout class="LoggerLayoutPattern">
            <param name="conversionPattern" value="%d{Y-m-d H:i:s} %c %-5p %F %L %m%n" />
        </layout>
        <param name="file" value="myLog.log" />
    </appender>

    <root>
        <level value="TRACE" />
        <appender_ref ref="myAppender" />
    </root>
</configuration>

The concerned part is

<param name="conversionPattern" value="%d{Y-m-d H:i:s} %c %-5p %F %L %m%n" />

The %F is the specifier for getting the file-name. This is logging the message’s into the log file. Here is a sample logged message:

2012-09-23 22:15:04 myLog FATAL /media/study/code/live/public_html/log.php 18 My message.

Problem

I want to display only the filename(log.php in this case) and not the complete path (/media/study/code/live/public_html/log.php) of the file here. Have searched the Apache docs and SO but couldn’t find anything in this reference.

Any hints how to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:49:34+00:00Added an answer on June 12, 2026 at 9:49 pm

    This task can be completed with a little help of code that you add.

    Not surprisingly the pattern layout is configured in layouts/LoggerLayoutPattern.php and has a lengthy array protected static $defaultConverterMap that defines all patterns understood in the conversion pattern. As you can see, the letter “F” is linked with the LoggerPatternConverterFile class in patterns/LoggerPatternConverterFile.php. A quick look reveals:

    public function convert(LoggerLoggingEvent $event) {
        return $event->getLocationInformation()->getFileName();
    }
    

    That’s what is causing the full filepath. Adding a call to the basename() function would return the wished result, but beware this will not survive updates of Log4PHP. You can add it, though, and are done.

    If you want a persistant change, you’ll have to extend the two mentioned classes and add them to your own autoloading or including:

    First extend the LoggerPatternConverterFile. This brings you the basename of the relevant file:

    class LoggerPatternConverterFileBasename extends LoggerPatternConverterFile
    {
        public function convert(LoggerLoggingEvent $event) {
          return basename(parent::convert($event));
        }
    }
    

    Second extend the LoggerLayoutPattern class

    class YourLoggerLayoutPattern extends LoggerLayoutPattern {
      public function __construct() {
        parent::__construct();
        $this->converterMap['f'] = 'LoggerPatternConverterFileBasename';
      }
    }
    

    That way, you just defined that for “small letter f” you will only see the basename of the file.

    In your configuration you just reference this new YourLoggerLayoutPattern class with the changed conversion string.

    This change should survive updates to log4php.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Java,I have to fetch multiple sets of values from an XML file to
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
I would like to log errors/informational and warning messages from within my web application
Using Code First Entity Framework with .NET MVC 4 I have created a new
Using regex in C# I should replace one word if it doesn't have specific
Using the imagettftext function from the PHP GD library, one can only draw text
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq;
I have a PHP application containing multiple modules and various settings within each module.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.