Question

I am using Log4js Library to print the log message in a file. In that I am getting 2 issues. Such as:

  1. 12:00:40 PM ERROR Log4js - TypeError: netscape.security.PrivilegeManager is undefined in Non-IE Browser. Please tell me how to fix this exception. While Using IE , It's working fine.
  2. How to get the CATALINA_HOME in the JavaScript part. I am using Tomcat. To get this CATALINA_HOME in Log4j, we need to write as follow log4j.appender.FILE.File=${catalina.base}/logs/MyLogs.log. If I'll write the catalina.base, not working in the JavaScript.

Here is my code please have a look on my code and detect the error causing line to have the solution:

<script type="text/javascript">
    function myFunction(name) {
        var date = new Date();
        var log = Log4js.getLogger("fileAppender");
        log.setLevel(Log4js.Level.ALL);
        var toAppend=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
        var fileAppender = new Log4js.FileAppender("${catalina.base}\\logs\\JSLogging."+toAppend+".log");
        log.addAppender(fileAppender);
        log.debug("My Debugging");
        log.info("My Information");
    }
</script>
Was it helpful?

Solution

try adding <script type="text/javascript" src="log4javascript.js"></script> in the code seems it is not able to get the reference of the main script. see if this can help you

<script type="text/javascript">
    // Create the logger
    var log = log4javascript.getLogger();

    // Create a PopUpAppender with default options
    var popUpAppender = new log4javascript.PopUpAppender();

    // Change the desired configuration options
    popUpAppender.setFocusPopUp(true);
    popUpAppender.setNewestMessageAtTop(true);

    // Add the appender to the logger
    log.addAppender(popUpAppender);

    // Test the logger
    log.debug("Hello world!");
</script> 

enter code here

use this link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top