You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Thorsten Schöning <ts...@am-soft.de> on 2010/10/12 18:24:29 UTC

exception std::out_of_range in StringHelper::startsWith

Hello,

I get an out_of_range exception everytime I use a logger which name is
longer than the name of the root logger and wonder if anyone else ran
into this problem, too. We use a pretty old Borland Builder 5, may it
be an implementation issue of the stl? Reading how
basic_string::compare works for other implementations the current
startWith should work, in my opinion.

http://www.sgi.com/tech/stl/basic_string.html

I had to make the following changes:

Index: stringhelper.cpp
===================================================================
--- stringhelper.cpp    (Revision 1652)
+++ stringhelper.cpp    (Arbeitskopie)
@@ -79,6 +79,11 @@
 
 bool StringHelper::startsWith(const LogString& s, const LogString& prefix)
 {
+    if (s.length() < prefix.length())
+    {
+      return false;
+    }
+
     return s.compare(0, prefix.length(), prefix) == 0;
 }

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig
 
Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoening@am-soft.de
Web:     http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow


Re: exception std::out_of_range in StringHelper::startsWith

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Jacob L. Anawalt,
am Freitag, 15. Oktober 2010 um 23:30 schrieben Sie:

> I'm not sure what this named root logger you're referring too. In xml
> config it's just <root> and in property format it's log4j.rootLogger.

Hello,

I mean the logger which gets configured with "root".

> PQ
> PQ.Worker
> PQ.TX
> PQ.TX.Lookup

> I've been building with the GCC on Debian for a few years now without 
> any out_of_range errors to do with log4cxx loggers.

My configuration is similiar, I have the root logger and one main
logger of my own configured. The error occurs in startsWith with
variable s set to "root" and prefix set to "Dokliste". Regarding the
stack trace the problem seems to be while configuration, but I didn't
get it to reproduce with a more simple test program. The test program
works well, but this application, where I started, does always fail if
I uncomment my changes to startsWith.

I attached a screenshot of the Debugger if anyone is interested,
underneath is an extract my configuration. The screenshot shows the
contents of the two variables and the stack trace. Log4cxx is
configured using the following code:

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmdLine, int)
{
        try
        {
                log4cxx::xml::DOMConfigurator::configure((ExtractFileDir(Application->ExeName) + "\\log4cxx.xml").c_str());
                static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(L"Dokliste.Main");
                LOG4CXX_INFO(logger, L"Programmstart");
[...]

My test program, where the problem didn't occur, configures log4cxx
the same way. The logger Dokliste.Main existed in some of my test,
too, with may other loggers, but two loggers are enought to produce
the problem in the on application where it does occur.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>

<log4j:configuration xmlns:log4j="http://logging.apache.org/" debug="false" threshold="null">

        <appender       name="userSpecificLogFile"
                                class="org.apache.log4j.rolling.RollingFileAppender">
[...]
        </appender>

        <root>
                <level  value="TRACE"
                />

                <appender-ref   ref="userSpecificLogFile"
                />
        </root>

        <logger name="Dokliste"
                        additivity="false">
                <level  value="TRACE"
                />

                <appender-ref   ref="userSpecificLogFile"
                />
        </logger>

</log4j:configuration>

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig
 
Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoening@am-soft.de
Web:     http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow

Re: exception std::out_of_range in StringHelper::startsWith

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
On 10/12/2010 10:24 AM, Thorsten Schöning wrote:
> I get an out_of_range exception everytime I use a logger which name is
> longer than the name of the root logger

I'm not sure what this named root logger you're referring too. In xml 
config it's just <root> and in property format it's log4j.rootLogger.

I have logging hierarchies where the child logger's name is longer 
than the parent's in a java like way only I sometimes use 
abbreviations of my classes and sometimes use names/levels for 
non-class things. Eg, for a postgresql accessing class:

PQ
PQ.Worker
PQ.TX
PQ.TX.Lookup

I've been building with the GCC on Debian for a few years now without 
any out_of_range errors to do with log4cxx loggers.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026