Constructor
new Logger(prefixopt, levelopt)
Prints messages to browser console. Each logging method perfoms toString() calls and default formatting of arguments only after it checks logging level. Therefore disabled level logging method call with plain arguments doesn't involves much overhead. But if one prefer custom formatting or some calculation for logging methods arguments he should check logging level before doing this to avoid unnecessary operations: if(logger.isLevelEnabled(LogLevel.DEBUG)) { logger.debug("", someCall(x, y), x + "," + y); }
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
prefix |
string |
<optional> |
"" | All log messages will be prefixed with that. |
level |
Photon.LogLevel |
<optional> |
LogLevel.INFO | Initial logging level. |
Methods
debug(mess, …optionalParams)
Logs message if logging level = DEBUG, INFO, WARN, ERROR
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | Message to log. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of log message after space character. |
error(mess, …optionalParams)
Logs message if logging level = ERROR
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | Message to log. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of log message after space character. |
exception(mess, …optionalParams)
Throws an Error or executes exception handler if set.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | Message passed to Error or exception handler. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of log message after space character. |
format(mess, …optionalParams) → {string}
Applies default logger formatting to arguments
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | String to start formatting with. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of formatted string after space character. |
Returns:
- Type
- string
format(mess, optionalParams) → {string}
Applies default logger formatting to array of objects.
Parameters:
Name | Type | Description |
---|---|---|
mess |
string | String to start formatting with. |
optionalParams |
Array.<any> | For every additional parameter toString() applies and result added to the end of formatted string after space character. |
Returns:
- Type
- string
getLevel() → {Photon.LogLevel}
Returns current logging level.
Returns:
- Type
- Photon.LogLevel
getPrefix() → {string}
Gets logger prefix.
Returns:
- Type
- string
info(mess, …optionalParams)
Logs message if logging level = INFO, WARN, ERROR
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | Message to log. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of log message after space character. |
isLevelEnabled(level) → {boolean}
Checks if logging level active.
Parameters:
Name | Type | Description |
---|---|---|
level |
Photon.LogLevel | Level to check. |
Returns:
- Type
- boolean
setExceptionHandler(handler)
Sets global method to be called on logger.exception call.
Parameters:
Name | Type | Description |
---|---|---|
handler |
'(number, string) => boolean' | Exception handler. Return true to cancel throwing. |
setLevel(level)
Changes current logging level.
Parameters:
Name | Type | Description |
---|---|---|
level |
Photon.LogLevel | New logging level. |
setPrefix(prefix)
Sets logger prefix.
Parameters:
Name | Type | Description |
---|---|---|
prefix |
stirng | New prefix. |
warn(mess, …optionalParams)
Logs message if logging level = WARN, ERROR
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
mess |
string | Message to log. | |
optionalParams |
any |
<repeatable> |
For every additional parameter toString() applies and result added to the end of log message after space character. |