如何将 Bokeh Server(或任何子进程)的记录器重定向到 Node 中的文件?
How to redirect the logger of Bokeh Server (or any child process) to a file within Node?
我想 运行 散景服务器作为 Node.js 的子进程。我想使用 python_shell
包并实时重定向输出,而不是在执行结束时。
Bokeh 没有我可以写入记录器文件路径的配置文件或参数。所以我需要使用 command redirection operators 来重新路由记录器:
'>> `${debug_path}` 2>&1'
所以我尝试了一些东西:
process.chdir(`${path}`); // path where I should run bokeh
var options = {
mode: 'json',
pythonPath: `${python_path}`,
pythonOptions: [
'-m', 'bokeh', 'serve',
],
args: [
'>>', `${debug_path}`, '2>&1', // this is not working, in pythonOptions neither
]
};
python_shell.run('', options, function (err, results) {
if (err) {
logger.error(`${err}`);
}
// results is an array consisting of messages collected during execution
if (typeof(results) !== 'undefined') {
logger.info(results); // this is run at the end of the execution if it was an script
}
});
然后我想知道是否有一种方法可以使用 python_shell
重定向记录器
注意:我目前使用的是exec
。但是它也有一些缺点,如果node进程被强制杀掉,python进程就会变成僵尸进程。所以这不是一个好的解决方案:
// command is a string with the whole paths and arguments concatenating '>> `${debug_path}` 2>&1' at the end
shell = child_process.exec(command, (error, stdout, stderr) => {
if (error) {
logger.error(`${error}`);
}
logger.info(`stdout: ${stdout}`);
logger.info(`stderr: ${stderr}`);
});
Bokeh 开发者添加了直接重定向输出记录器的选项
> bokeh serve --help
[...]
--log-level LOG-LEVEL
One of: trace, debug, info, warning, error or critical
--log-format LOG-FORMAT
A standard Python logging format string (default:
'%(asctime)s %(message)s')
--log-file LOG-FILE A filename to write logs to, or None to write to the
standard stream (default: None)
我想 运行 散景服务器作为 Node.js 的子进程。我想使用 python_shell
包并实时重定向输出,而不是在执行结束时。
Bokeh 没有我可以写入记录器文件路径的配置文件或参数。所以我需要使用 command redirection operators 来重新路由记录器:
'>> `${debug_path}` 2>&1'
所以我尝试了一些东西:
process.chdir(`${path}`); // path where I should run bokeh
var options = {
mode: 'json',
pythonPath: `${python_path}`,
pythonOptions: [
'-m', 'bokeh', 'serve',
],
args: [
'>>', `${debug_path}`, '2>&1', // this is not working, in pythonOptions neither
]
};
python_shell.run('', options, function (err, results) {
if (err) {
logger.error(`${err}`);
}
// results is an array consisting of messages collected during execution
if (typeof(results) !== 'undefined') {
logger.info(results); // this is run at the end of the execution if it was an script
}
});
然后我想知道是否有一种方法可以使用 python_shell
注意:我目前使用的是exec
。但是它也有一些缺点,如果node进程被强制杀掉,python进程就会变成僵尸进程。所以这不是一个好的解决方案:
// command is a string with the whole paths and arguments concatenating '>> `${debug_path}` 2>&1' at the end
shell = child_process.exec(command, (error, stdout, stderr) => {
if (error) {
logger.error(`${error}`);
}
logger.info(`stdout: ${stdout}`);
logger.info(`stderr: ${stderr}`);
});
Bokeh 开发者添加了直接重定向输出记录器的选项
> bokeh serve --help
[...]
--log-level LOG-LEVEL
One of: trace, debug, info, warning, error or critical
--log-format LOG-FORMAT
A standard Python logging format string (default:
'%(asctime)s %(message)s')
--log-file LOG-FILE A filename to write logs to, or None to write to the
standard stream (default: None)