Log messages
paella-core incorporates a message logging system that allows you to write messages that will be displayed depending on the verbosity level set.
You can access to the logging system through the player instance:
const log = myPlayerInstance.log;...To write messages to the console, you can call the following five functions, depending on the verbosity level you want to use:
...log.error("This is an error message");log.warn("This is a warning message");log.info("This is an information message");log.debug("This is a debug message");log.verbose("This is a more verbose debug message");In addition to the message text, an optional second parameter can be specified to indicate the context in which the message occurs. By default the context is paella-core. It can be used to indicate the origin of the message. For example, if we want to display a message from a plugin we are implementing, we could use the myPlugin context:
log.warn("This is a warning message","myPlugin");The default verbosity level, if it is not set in the config.json file, is INFO. However, befor the player configuration is completed, the initial verbosity level is VERBOSE. If you want to explicitly modify the verbosity level before the configuration is load, you must do so after creating the paella player instance.
import { Paella, LOG_LEVEL } from '@asicupv/paella-core';
const initParams = { ... };
const playerInstance = new Paella('playerContainer', initParams);playerInstance.log.setLevel(LOG_LEVEL.WARN);
playerInstance.loadManifest() .then(() => { // Done }) .catch((e) => { playerInstance.log.error(e.message); })If you want to override the config.json settings and set your own verbosity level using the JavaScript API, you must do so AFTER loading the configuration, for example, in the then callback or inside a plugin:
playerInstance.loadManifest() .then(() => { // Done playerInstance.log.setLevel(LOG_LEVEL.DEBUG); }) .catch((e) => { playerInstance.log.error(e.message); })To set the verbosity level you can use the LOG_LEVEL object, the numeric value of the verbosity level or the verbosity level string:
export const LOG_LEVEL = { DISABLED: 0, ERROR: 1, WARN: 2, INFO: 3, DEBUG: 4, VERBOSE: 5};import { Paella, LOG_LEVEL } from '@asicupv/paella-core`;...playerInstance.log.setLevel(LOG_LEVEL.DEBUG);playerInstance.log.setLevel(0); // DISABLEDplayerInstance.log.setLevel("INFO");It is also possible to set the verbosity level by adding the logLevel parameter in the URL. As a value it is possible to set any of the elements of the LOG_LEVEL object:
https://my-paella.com/?id=video_id&logLevel=VERBOSE
The logLevel parameter is case insensitive, so you can also use:
https://my-paella.com/?id=video_id&logLevel=Verbosehttps://my-paella.com/?id=video_id&loglevel=Verbosehttps://my-paella.com/?id=video_id&LOGLEVEL=VERBOSEhttps://my-paella.com/?id=video_id&loglevel=verbose