Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Basename-pattern includes path in some logs #415

Copy link
Copy link
Closed
@JanPlitzkow

Description

@JanPlitzkow
Issue body actions

Hi together,

I'm happily using log4cplus for some years but now I just noticed, that loggers including %b in their pattern produce inconsistent output.

I'm for example using the pattern %n%p | %c | %b:%L%n%m%n and this creates the following exemplary log-file:

WARN | Misc.Hjson | Hjson.h:180
Creating new / missing configuration value 'Active'.

WARN | Misc.Hjson | d:\my\example\path\to\project\misc\hjson.h:180
Creating new / missing configuration value 'Freq'.

Obviously the path is included only in the second call, despite the fact that it's exactly the same template-function that is called from different places here.

Digging a little futher into this issue I found the function get_basename (const log4cplus::tstring& filename) in patternlayout.cxx combined with usage of different directory seperators in include-paths is the root cause. Changing the function to something like the following solves the issue for me:

static log4cplus::tstring
get_basename (const log4cplus::tstring& filename)
{
	log4cplus::tstring::size_type pos = filename.find_last_of(LOG4CPLUS_TEXT("\\/"));
    if (pos != log4cplus::tstring::npos)
        return filename.substr(pos+1);
    else
        return filename;
}

Obviously / is default seperator on unix-systems, while \\ is on Windows. Another solution would be to use the correct seperators in all #include-instructions. However I think log4cplus should not enforce this, especially since one can be using same headers for Windows and Unix targets...

Would my could snippet be a valid solution for integration into the library?

Best regards
Jan

Additional information on my system if needed:

  • version: 2.0
  • operating system, CPU, bitness: Win7
  • compiler and its version: VisualStudio 2015

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.