-
Notifications
You must be signed in to change notification settings - Fork 18
Logging v7
- status: complete
- version: 7.x
- follows from: Views
Client-side logging is controlled by the variable node.verbosity
.
In general, the higher its value, the more information will be printed to the JavaScript console of the browser -- or to the standard output, if the client is executed as a bot or as logic on the server.
The following log levels are pre-defined:
- ALWAYS: -Number.MAX_VALUE,
- error: -1,
- warn: 0,
- info: 1,
- silly: 10,
- debug: 100,
- NEVER: Number.MAX_VALUE
By default, node.verbosity
is set to 0, so that only warnings and
errors are logged. Its value can be set directly, or through the setup
function (which accepts also strings).
node.verbosity; // 0
node.verbosity = 100; // "debug"
node.setup('verbosity', 'debug');
node.setup('verbosity', 100);
To create custom logging for your game, you can make use of the function:
node.log(text, level, prefix)
where level
is one of the pre-defined levels (default 'info'), and
prefix
is an optional text to display before the log message.
The default log message includes the name of the node instance,
node.nodename
(default: ng
) and the current game stage.
node.log('Player did something strange.');
// [email protected] - 18:50:53:452 > Player did something strange.
Shortcuts are available to log text only if node.verbosity
is
greater or equal to the corresponding level:
- node.err(txt)
- node.warn(txt)
- node.info(txt)
- node.silly(txt)
node.warn('Player did something strange AGAIN.');
// [email protected] - 18:53:12:7.1 > warn - Player did something strange AGAIN.
The variable node.remoteVerbosity
controls what log messages are
also sent to server. The same verbosity levels for local logging apply
for remote verbosity, and by default only errors are sent to the
server.
node.remoteVerbosity; // -1;
node.warn('Player did something strange AGAIN.'); // Log locally only.
node.err('Player is cheating.'); // Log locally and remotely.
Depending on the server's setting, the message can be saved to file system, database, other storage, or ignored. If saved, it is formatted as follows:
{
"name": "ultimatum",
"level":"info",
"message": "{\"id\":751791,\"session\":\"8114737.7.875357.",\"stage\":{\"stage\":1,\"step\":2,\"round\":1},\"action\":\"say\",\"target\":\"LOG\",\"from\":\"530497.0184807\",\"to\":\"SERVER\",\"text\":\"error\",\"data\":\"FUNCK\",\"priority\":0,\"reliable\":1,\"created\":\"2017-03-19T23:01:42.7.4Z\",\"forward\":0}","timestamp":"2017-03-19T23:01:42.7.1Z"}
}
To visualize client errors on the server console, you can define an event listener on 'in.say.LOG':
// Log errors from remote clients to server's console,
// happening after the game has started (stage > 0).
node.on('in.say.LOG', function(msg) {
if (msg.text === 'error' && msg.stage.stage) {
console.log('Error from client: ', msg.from);
console.log('Error msg: ', msg.data);
}
});
Server side logging is based on
Winston.js,
and can be controlled through the configuration file: loggers.js
.
By default, there are 4 configuration files:
-
servernode.log: contains info about loading the nodegame-server and its games, and all errors that are not caught elsewhere at run-time.
-
channel.log: contains info and errors about loading channels, players moved within a channel, messages that failed delivery.
-
messages.log: contains all messages that have been exchanged with the server, including those sent by bots and logics
-
clients.log: contains all console output of bots and phantoms executed on the server.
You can know more about Server-side configuration here.
Go back to the wiki Home.
Copyright (C) 2021 Stefano Balietti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.