Skip to content
stritti edited this page Oct 6, 2018 · 3 revisions

General

How can I use Log4js?

Have a look at the examples. You have only to add log4js.js as script to your HTML pages and create a logging object which you are using then in your code for logging.

For more details about the API, have a look at the users guide and the API documentation.

Under which license is Log4js available?

Log4js is licenced under the Apache License Version 2.0.

Why I have to set an Appender? What is an Appender?

Appenders are special implementations for different logging behaviours. In some cases you probably want to log to a popup window, in other situations you want to sent the client logs to the server to store them there.

log4js has a very flexible for these circumstances and allows own implementations for this. These are the appenders.

There are some useful appenders available within log4js. Have also a look at the API documentation:

  • AjaxAppender: Sends the logging content via XmlHttpRequest to the server to log data on the server.
  • ConsoleAppender: Creates a HTML console (inline or separate window) to show the logs.
  • JSAlertAppender: For some circumstances useful: Show alert boxes for each log.
  • MetatagAppender: Adds the logs as meta tags.
  • FileAppender: Creates a local file to write the logs in. Works with Mozilla and Internet Explorer.
  • WindowsEventAppender: Sends the logs to the Windows System Events. Works only with Internet Explorer.
  • MozJSConsoleAppender: Sends the logs to the Mozilla JavaScript console
  • SafariJSConsoleAppender: Sends the logs to the Safari JavaScript console
  • OperaJSConsoleAppender: Sends the logs to the Opera JavaScript console

Probably you have also an appender, to share with the community?

How do I use Layouts?

The Layouts give you the possibility to format the logs in a specific way. For example, it is possible to format as HTML or XML. Some appenders require a specific layout to work correctly.

Following layouts are available:

  • JSONLayout: formats the log entrys as JSON object, which can be read by different programming languages. Often it is more useful than XML because of the smaller footprints.
  • XMLLayout: formats the log entries as XML structure. The structure is very simmilar to the XML structure of Apaches log4j
  • HTMLLayout: formats the log entry as HTML div-element

Can I log the data from the client on the server?

Logging is useful during development. Then the log output is useful within ConsoleAppender for example. But logging is much more useful within production systems, where your application is out in the wild area. There you can not debug and the users just report errors. Having no logs it is difficult to understand what happend in complex environments.

For this circumstances we designed the AJAXAppender! The AJAXAppender sned all the logs collected on the client to a specific url on the server. There you can process them using log4j, log4php or by your own. To improve the performance a threshold could be defined. The log entries are send then in blocks.