Logging going to the wrong file

Poster Content
nk4um Administrator
Posts: 607
January 7, 2013 21:57

Hi Keith,

you question is hard to answer with the information you've provided but it's likely that your request scopes dictate that the log gets used that is not what you are expecting. If you email me a visualizer trace of your request that includes the endpoint that does the logging, the endpoint name that does the logging and the modules which contain the log configs then I'll be able to see the request scope and determine which log will get used and if that agrees with your expectation.

Please send to tab AT 1060.org

Cheers, Tony

Like · Post Reply
nk4um User
Posts: 24
January 7, 2013 21:46

That confirms my original suspicion but it doesn't answer my initial question on why my log entries are going to the wrong file?

Like · Post Reply
nk4um Administrator
Posts: 607
January 7, 2013 20:41

I think the Formatter must be located in the bootloader classloader so that the JDK logging classes can locate it.

As for resolving the right logger this is done using the request scope of the request to the endpoint that does the logging. It doesn't use regular request resolution as the logging happens at a lower level. It will however traverse up the classloaders for each space in the scope attempting to locate the logging config to determine which log to use.

The actual code to resolve the log is found in this method: org.netkernel.logging.LogManager.getLog(IRequestScopeLevel aScope, String aResource)

Cheers, Tony

Like · Post Reply
nk4um User
Posts: 24
January 7, 2013 19:40

No luck. I'm getting class not found exceptions with that approach. I checked with the classloader trace tool and I see the module with the logging class but when I import it to the module the logger isn't able to get at that class. I suspect that the logger isn't using the module's classloader. Can you verify that or provide a sample module.xml that shows how to import the module containing the custom logger?

Like · Post Reply
nk4um Moderator
Posts: 901
January 7, 2013 17:10

hi Keith,

The logging relies upon the module classloader for its context I think. I'm not sure but possibly the context is getting lost by putting you formatter in the global classloader and may be causing the problem.

Can you try putting your formatter into class-library module - basically an empty module (just an empty roostpace with no endpoints) but which has your classes in its lib/ and then shares them via a classpath export in the <system> like this...

<system>
  <classloader>
    <exports>
      <match>com.path.to.formatter.*</match>
    </exports>
  </classloader>
</system>

Then import this module to each of your modules so that they get the handler through their local contextual classpath.

P.

Like · Post Reply
nk4um User
Posts: 24
January 7, 2013 16:50Logging going to the wrong file

So this is an odd one. I have multiple modules, each with their own LogConfig.xml that looks something like this...

<log>
  <id>DataAccessLog</id>
  <name>Data Access Log</name>
  <handlers>
    <handler>
      <instance>
        <class>org.netkernel.layer0.logging.LogFileHandler</class>
        <string>%b/log/MyModule-%g.log</string>
        <int>50000000</int>
        <int>3</int>
        <boolean>true</boolean>
      </instance>
      <formatterClass>com.mycorp.nk.logging.MyCorpFormatter</formatterClass>
    </handler>
    <handler>
      <instance>
        <class>java.util.logging.ConsoleHandler</class>
      </instance>
      <formatterClass>com.mycorp.nk.logging.MyCorpFormatter</formatterClass>
    </handler>
  </handlers>
</log>

To get the formatter to work I loaded the jar with the formatter implementation via bootloader.conf. Each module has it's own log file. The odd part however is that the logging data is going to the wrong file. Logging data from Module A is ending up in the log file for Module B. The log formatter has some thread local variables for keeping track of identifiers but no local class level variables. I'm at a loss as to why this may be happening.

Like · Post Reply