I try to include the log4javascript JS library within my project and therefore followed a quick example to configure a simple named logger object with a PopUpAppender and I'm seeing the same message over and over again:

Uncaught TypeError: Cannot read property 'focusPopUp' of undefined

which points to the follwing line within the PopUpAppender function:

function PopUpAppender(lazyInit, initiallyMinimized, useDocumentWrite,
                               width, height) {
            this.create(false, null, lazyInit, initiallyMinimized,
                    useDocumentWrite, width, height, this.defaults.focusPopUp); // this is were the error seems to happen...
        }

So, I created a simple HTML project with just a index.html plain html site and including log4javascript.js and log4javascript_uncompressed.js alternately to test if the behaviour is different in any of the files. But everytime I try to initialize the logger object in the described way, I see the same error.

If I step back and try to initialize the logger in the simplest way possible, like:

var log = log4javascript.getDefaultLogger();

everything works fine and I see the logger output popping up and write out my first log message.

Am I doing something wrong within my try on initializing a logger object? I can't see any stumbling block as I'm basically doing the same as the log4javascript.getDefaultLogger() method does:

log4javascript.getDefaultLogger = function() {
        if (!defaultLogger) {
            defaultLogger = log4javascript.getLogger(defaultLoggerName);
            var a = new log4javascript.PopUpAppender();
            defaultLogger.addAppender(a);
        }
        return defaultLogger;
    };

Any hints on this?


EDIT:

I initialize my logger this way

var log = log4javascript.getLogger("main");
var appender = log4javascript.PopUpAppender();
log.addAppender(appender);
log.debug("Logging is enabled!");

EDIT 2:

So, I started a new plain HTML project with only the index.html page and the js folder, which is the extracted folder from the log4javascript *.zip package.

This is my whole HTML page:

<html>
<head>
    <title> Log4Javascript Tryout Page!</title>
    <script type="text/javascript" src="js/log4javascript.js"></script>
</head>
<body>
    <script type="text/javascript">
        var logger = log4javascript.getLogger('main');
        var appender = log4javascript.PopUpAppender();
        logger.addAppender(appender);
        logger.debug('Logging enabled!');
    </script>
</body>
</html>

and still I keep getting the same error...?

有帮助吗?

解决方案

The problem is that you need to use new:

var appender = new log4javascript.PopUpAppender();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top