Logger
The internal logger used by the SmartFoxServer 2X client API. This is a singleton class.
Properties
new Logger()
Developers never istantiate the Logger class: this is done internally by the SmartFoxServer 2X API; get a reference to it using the SmartFox.logger property.
Accessing the logger instance allows to control the client-side logging level by means of the level property.
- Extends
- EventDispatcher
- See also
- LoggerEvent
- SmartFox#logger
Properties
enableConsoleOutput boolean
Indicates whether or not the output of logged messages to the browser's console is enabled.
This property has no effect if the "console" object is undefined in the current environment.
- See also
- Logger#enableEventDispatching
enableEventDispatching boolean
Indicates whether dispatching of log events is enabled or not.
- See also
- LoggerEvent
- Logger#enableConsoleOutput
level number
Gets and sets the current logging level.
Debugging messages with a level lower than this value are not logged.
The available log levels are contained in the LogLevel class. The default value is LogLevel.INFO.
- See also
- LogLevel
Methods
addEventListener(evtType, callback, scope)
Registers an event listener function that will receive notification of an event.
If you no longer need an event listener, remove it by calling the removeEventListener() method, or memory issues could arise. In fact event listeners are not automatically removed from memory.
Example
This example shows how to add a number of common event listeners to the SmartFox instance, usually during initialization:
function init()
{
sfs = new SFS2X.SmartFox();
// Add LoggerEvent listeners
sfs.logger.addEventListener(SFS2X.LoggerEvent.DEBUG, onDebugMessage, this);
sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);
sfs.logger.addEventListener(SFS2X.LoggerEvent.WARNING, onWarningMessage, this);
sfs.logger.addEventListener(SFS2X.LoggerEvent.ERROR, onErrorMessage, this);
// Add SFSEvent listeners
sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);
sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
sfs.addEventListener(SFS2X.SFSEvent.LOGOUT, onLogout, this);
sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoin, this);
}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
evtType |
|
|
The type of event to listen to, among those available in the SFSEvent, SFSBuddyEvent and LoggerEvent classes. |
callback |
|
|
The listener function that processes the event. This function should accept an object as its only parameter, which in turn contains the event parameters. |
scope |
|
|
The object that acts as a context for the event listener: it is the object that acts as a "parent scope" for the callback function, thus providing context (i.e. access to variables and other mehtods) to the function itself. |
- Inherited from
- EventDispatcher#addEventListener
- See also
- SFSEvent
- SFSBuddyEvent
- LoggerEvent
- Logger#removeEventListener
removeEventListener(evtType, callback)
Removes an event listener.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
evtType |
|
|
The type of event to remove, among those available in the SFSevent, SFSBuddyEvent and LoggerEvent classes. |
callback |
|
|
The listener function to be removed. |
- Inherited from
- EventDispatcher#removeEventListener
- See also
- SFSEvent
- SFSBuddyEvent
- Logger#addEventListener