Logging
This library provides different logging APIs that propagate logging info to the Node.js subengine. In local development (not running with Node.js subengine core), the console is used for logging.
Logging Levels
Logging levels use the npm severity ordering: ascending from most important to least important.
{
ERROR: 0,
WARN: 1,
INFO: 2,
DEBUG: 3,
}
Setting logging levels
By default, the logging level is set to INFO. This can be
changed as
below:
const operator: Operator = Operator.getInstance(); operator.logger.logLevel = "ERROR"; // case insensitive
Usage of the logging API
The logging APIs are directly accessible from the operator instance.
const operator: Operator = Operator.getInstance();
// if not running in subengine, log is outputted to console
operator.logger.info("message", ...); // log level INFO
// DEBUG level
operator.logger.debug("message", ...);
// WARNING level
operator.logger.warn("message", ...);
// ERROR level
operator.logger.error("message", ...);
You can also create an own logger instance in your operators.
import { Logger } from "@sap/vflow-sub-node-sdk";
const logger: Logger = new Logger("LOG_LEVEL");
logger.info("message");Message formatting
Log message can take zero or more placeholder tokens. Each placeholder is replaced
with the converted value from the corresponding argument. The log message is then a
print-f like format string. For supported placeholders, please see nodejs.org
.
.operator.logger.debug("debug message %j", { foo: "bar" });
// 2018-11-22T13:03:01.088Z - debug: Operator "sampleiotdevicegeneratingdata1" (pid: 11912)|debug message { "foo": "bar" }