Configuring log levels and files¶
The Node.js driver supports two types of loggers to track activity:
Browser logger, which stores logs in an in-memory buffer within the browser.
Node logger, which by default, stores logs in a
snowflake.logfile and displays them in the console.
You can use the following code to switch from the browser logger to the node logger. This example switches to the node logger and sends messages to the console.
Logger.setInstance(new NodeLogger({ logFilePath: 'STDOUT'}));
Supported log levels¶
The Node.js driver supports the following log levels:
OFF
ERROR
WARNING
INFO
DEBUG
TRACE
Configure the default logging behavior¶
You can configure standard logging by calling snowflake.configure, similar to the following:
const snowflake = require('snowflake-sdk');
snowflake.configure({
logLevel: "INFO",
logFilePath: "/some/path/log_file.log",
additionalLogToConsole: false
});
where:
logLevelis the desired logging level.logFilePathis the location of the log file orSTDOUTfor console output.additionalLogToConsoleis a Boolean value that indicates whether to send log messages also to the console when alogFilePathis specified. Default:true.
Use easy logging while debugging your code¶
When debugging an application, increasing the log level can provide more granular information about what the application is doing.
The Easy Logging feature simplifies debugging by letting you change the log level and the log file destination using a configuration file (default: sf_client_config.json).
You typically change log levels only when debugging your application.
This configuration file uses JSON to define the log_level and log_path logging parameters, as follows:
{
"common": {
"log_level": "INFO",
"log_path": "/some-path/some-directory"
}
}
where:
log_levelis the desired logging level.log_pathis the location to store the log files. The driver automatically creates anodejssub-directory in the specifiedlog_path. For example, if you setlog_pathto/Users/me/logs, the drivers creates the/Users/me/logs/nodejsdirectory and stores the logs there.
The driver looks for the location of the configuration file in the following order:
clientConfigFileconnection parameter, containing the full path to the configuration file, such as the following:const snowflake = require('snowflake-sdk'); var connection = snowflake.createConnection({ account: account, username: user, password: password, application: application, clientConfigFile: '/some/path/client_config.json' });
SF_CLIENT_CONFIG_FILEenvironment variable, containing the full path to the configuration file (e.g.export SF_CLIENT_CONFIG_FILE=/some_path/some-directory/client_config.json).Node.js driver installation directory, where the file must be named
sf_client_config.json.User’s home directory, where the file must be named
sf_client_config.json.
Note
To enhance security, the driver requires the logging configuration file on Unix-style systems to limit file permissions to allow only the file owner to modify the files (such as chmod 0600 or chmod 0644).
To minimize the number of searches for a configuration file, the driver reads the configuration file only:
for the first connection.
for the first connection using the
clientConfigFileparameter.