4

I'm using log4javascript version 1.4.3.
In my app it works fine for all log levels except trace. To simplify things and make sure that the problem is not within my app I made an example using the authors sample code as an example and added a setThreshold(log4javascript.TRACE), then added a line to generate a trace entry (I also deleted the lines from his example that are relevant only to an ajaxAppender leaving just the popUpAppender).

When I run the code the error and debug messages appear in a log4javascript popUp window but no trace message.

Evidently I don't correctly understand the use of the trace level or the configuration for trace messages. If someone could point out the error of my ways then I can fix my app logging.

Sample code that fails below.

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>log4javascript example from  manual</title>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <meta name="author" content="Tim Down - tim@log4javascript.org" />
        <meta name="description" content="log4javascript, a logging framework for JavaScript based on log4j" />
        <meta name="robots" content="all" />
        <script type="text/javascript" src="/tracker/libraries/log4javascript.js"></script>
        <script type="text/javascript">
            //<![CDATA[
            var log = log4javascript.getLogger();
            var popUpAppender = new log4javascript.PopUpAppender();
            var popUpLayout = new log4javascript.PatternLayout("%d{HH:mm:ss} %-5p - %m%n");
            popUpAppender.setLayout(popUpLayout);

            // new line below
            popUpAppender.setThreshold(log4javascript.Level.TRACE);

            log.addAppender(popUpAppender);

            log.debug("Debugging message (appears in pop-up)");
            log.error("Error message (appears in pop-up and in server log)");

            // new line below
            log.trace("Trace message");

            //]]>
        </script>
    </head>
    <body>
        <h1>log4javascript example from  manual</h1>

        <script type="text/javascript">
            var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
            document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
        </script>
        <script type="text/javascript">
            var pageTracker = _gat._getTracker("UA-448786-3");
            pageTracker._initData();
            pageTracker._trackPageview();
        </script>

    </body>
</html>
Tim Down
  • 318,141
  • 75
  • 454
  • 536
RoyHB
  • 1,715
  • 1
  • 22
  • 38

1 Answers1

7

The problem is that the logger has a threshold level as well, which is set to DEBUG by default. Add the following line before calling log.trace():

log.setLevel(log4javascript.Level.TRACE);
Tim Down
  • 318,141
  • 75
  • 454
  • 536
  • Thanks Tim - I figured it was something simple I had missed. Is their a sample in the doco that demonstrates this? – RoyHB Oct 02 '12 at 22:22
  • One more question, Tim - does log4javascript_lite support the trace level? – RoyHB Oct 03 '12 at 06:12
  • @RoyHB: I don't think there's a sample in the documentation about enabling trace. I may add one. Re. log4javascript_lite, yes, that supports the trace level. The same trick should get it working, and there's no messing about with appenders to do. – Tim Down Oct 03 '12 at 09:44
  • Thanks, I ran into the exact same issue, trying to set my `Logger.browserConsoleAppender.setThreshold(log4javascript.Level.TRACE);` but didn't work, I don't really get why the `Appender` threshold doesn't override the `log.level`, but okay :) – Vadorequest Apr 08 '15 at 10:21
  • this is log4javascript.Levels.TRACE. Levels with a S. – mik3fly-4steri5k Sep 02 '18 at 13:08
  • @mik3fly-4steri5k: There is no `log4javascript.levels` or `log4javascript.Levels`. – Tim Down Sep 03 '18 at 09:10