Simple client logger
Members
# static categories
Message accepted categories. Default to "none" (meaning no message is logged).
The logger will only log the messages of the accepted categories. The category of the message is its first word, and can be anything. It's up to you to decide your logging strategy. Check init() method for examples.
# static data
Defines if the logger logs data too. false: only messages. true: messages and data
# static maxLength
Maximum length of the history (used to limit memory consumption)
# static types
Message types:
- "*" means all accepted (default behavior)
- 0: messages
- 1: informations
- 2: acknowledges
- 3: warnings
- 4: errors
Methods
# static init(config)
Initialize the logger
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
config |
object
|
||
data |
boolean
|
<optional> |
false: only messages. true: messages and data (default) |
types |
array
|
<optional> |
Log only the messages of these types, for example: [3,4]. Default to ["*"] (meaning everything is logged). |
categories |
Array.<string>
|
<optional> |
Log only the messages of these types, for example: ["db", "socket"]. Default to ["*"] (meaning everything is logged). |
maxLength |
number
|
<optional> |
Maximum number of messages kept into logger's history |
Example
// Will log the messages starting with the word "database" or the word "socket", like "db - find()", or "socket connected!"
kiss.logger.init({
types: [0, 3, 4],
categories: ["database", "socket"],
maxLength: 20
})
// The category of this message is "database", and it will be logged.
// The error will be display too.
log("database access denied", 4, err)
// The category of this message is "database", but it will not be logged because of type 2:
log("database successfuly updated", 2)
// The type of this message is 0 (default), but it will not be logged because its category is "view":
log("view - Sent to cache")
# static log(msg, typeopt, dataopt)
console.log wrapper
Sends a colored message in the console, and keeps the history in kiss.logger.history.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
string
|
The msg to log |
|
type |
integer
|
<optional> |
(default) 0=message (black), 1=info (blue), 2=acknowledge (green), 3=warning (orange), 4=error (red) |
data |
*
|
<optional> |
Optional data to show in the console |
Example
// Simple log
log("database - Trying to update...")
// Write the message in green (type 2) and also show the data:
const update = {lastName: "Wilson"}
log("database updated successfuly", 2, update)
# static replay(count)
Replay the log history
Parameters:
| Name | Type | Description |
|---|---|---|
count |
integer
|
Number of messages to replay |
# static show()
Show the history of all logged messages