Reputation: 136
I am developing an application using plain html (5) + css (3) + js (not using any framework). I run into the problem, JavaScript debugging. Searching led me to log4javascript. My Q is :
From demo's its clear how to use in a given html page.
So if my page gets transitioned to another page, how can I get the same old logger handler so that I can keep on logging to the same log file?
In case of multiple users using the app, how does it exactly work? (Please forgive me for my lack of knowledge :-) ).
If any has a sample code on how to obtain the handler for the logger that is initialized in page 1 in another page, it would really help me in narrowing down my efforts.
Thanks in advance, Ravi.
Upvotes: 1
Views: 1080
Reputation: 459
Since log4javascript runs on the client, all logs will be generated by the Browser used by individual clients. "Multiple Users" of your site can mean either of the following:
Now, log4javascript has a concept of "appenders", which you might have read about, and has the following available appenders:
For case (1) above, not sure if you can log "to the same file" - since none of these appenders allow you to log to files. For case (2) - logging to the same file is irrelevant since the logs are generated on different machines for different clients.
To answer your question, I'm pretty sure if you use the PopUpAppender, then a window will pop up for the first page then the next page will continue logging to the same PopUpAppender Window without having to worry about any handles. Same goes for the BrowserConsoleAppender.
If you are looking to collect logs generated by multiple clients at your server, then the best way would be to use the AjaxAppender. In this case, appending the logs to the "same file" or "same stream" (or whatever) for the same client/user depends on how you implement the server-side handler for the AjaxAppender. One of the approaches that comes to mind is that the URL used by each client for the AjaxAppender would contain the user ID or any unique client identifier which would help the server recognize the user/client from which the logs are coming and then save all logs at one place on the server.
Upvotes: 1