Setting the url to send logs to
By default, the jsnlog.js library sends all log requests to the URL
Change the URL
- Working demo code: JSNLogDemo_Core_DefaultAjaxUrl
An AjaxAppender goes through these steps to work out what url to send log requests to:
If has its own url, it will use that -
set the url
attribute of the
Note that the default appender does not have its own url, so it will always default to step 2.
- If it doesn't have its own url, it will use the default Ajax url - set the defaultAjaxUrl attribute of the JSNLog configuration element.
If you didn't set the default Ajax url, it finally falls back to
Use server side configuration to set the URL
The previous sections suggests you use server side configuration to set the URL. This way:
- At the client side, log requests will be sent to your url.
At the server side, JSNLog will look for log requests sent to your url.
Specifically, it will look for requests sent to:
- The urls set on individual appenders; and
- The default Ajax url, or if that is not given, /jsnlog.logger.
In principle, you could use client side configuration as well to set the url. However, at the server side, JSNLog would not know about your url, and so would not process requests to your url as log requests.
Cross domain requests
You may want to send your log requests to a site with a domain that is different from the site where they originate. For example, you have multiple sites with their own domains, and you want all log messages to go to a single common URL.
To make cross domain requests possible, JSNLog implements the CORS protocol.
For security reasons, you have to explicitly nominate the domains that JSNLog should accept requests from. All other domains will still be blocked.
For example, this jsnlog element allows requests from my-abc-domain.com, my-xyz-domain.com and all their sub domains, both over http and https:
<jsnlog corsAllowedOriginsRegex="^https?:\/\/([a-z0-9]+[.])*(my-abc-domain[.]com|my-xyz-domain[.]com)$" > </jsnlog>
JSNLog does not support CORS on IE8/9
IE8 and IE9 require additional code to support CORS. Because of their very low market share, JSNLog does not support CORS on these browsers. If you use CORS, then jsnlog.js running on these browsers will not send log messages to the server.