配置日志级别和文件
Node.js 驱动程序支持通过两种类型的记录器来跟踪活动:
- 浏览器记录器,可将日志存储在浏览器的内存缓冲区中。
- Node logger, which by default, stores logs in a
snowflake.logfile and displays them in the console.
您可以使用以下代码从浏览器记录器切换到节点记录器。此示例切换到了节点记录器,并向控制台发送消息。
支持的日志级别
Node.js 驱动程序日志级别:
- OFF
- ERROR
- WARNING
- INFO
- DEBUG
- TRACE
配置默认日志记录行为
You can configure standard logging by calling snowflake.configure, similar to the following:
其中:
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.
调试代码时使用 Easy Logging 功能¶
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).
通常只有在调试应用程序时才会更改日志级别。
This configuration file uses JSON to define the log_level and log_path logging parameters, as follows:
其中:
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.
驱动程序会按以下顺序查找配置文件的位置:
-
clientConfigFileconnection parameter, containing the full path to the configuration file, such as the following: -
SF_CLIENT_CONFIG_FILEenvironment variable, containing the full path to the configuration file (for example,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).
为尽量减少搜索配置文件的次数,驱动程序:
- 仅为第一次连接读取配置文件。
- for the first connection using the
clientConfigFileparameter.