我正在尝试在基于Webpack的应用程序中设置bunyan。
我有以下webpack配置:
// these shims are needed for bunyan
alias: {
'dtrace-provider': path.resolve('empty-shim.js'),
"fs": path.resolve('empty-shim.js'),
'safe-json-stringify': path.resolve('empty-shim.js'),
"mv": path.resolve('empty-shim.js'),
'source-map-support': path.resolve('empty-shim.js')
}
其中,空垫片是一个空文件
在我的记录器中定义了以下流:
{
level: "trace",
path: "/logs/trace.log"
// Logging from external libraries used by your app or very detailed application logging.
},
{
level: "debug",
path: "/logs/debug.log"
// Anything else, i.e. too verbose to be included in "info" level.
},
{
level: "info",
path: "/logs/info.log"
// Detail on regular operation.
},
{
level: "warn",
path: "/logs/warn.log"
// A note on something that should probably be looked at by an operator eventually.
},
{
level: "error",
stream: process.stderr // we pipe error also to stdout
// Fatal for a particular request, but the service/app continues
// servicing other requests. An operator should look at this soon(ish).
},
{
level: "error",
path: "/logs/error.log"
// Fatal for a particular request, but the service/app continues
// servicing other requests. An operator should look at this soon(ish).
},
{
level: "fatal",
path: "/logs/fatal.log"
// The service/app is going to stop or become unusable now.
// An operator should definitely look into this soon.
}
当我尝试访问记录器时,出现此错误:
Uncaught TypeError: fs.createWriteStream is not a function
at Logger.addStream (http://localhost:8080/bundle.js:81080:28)
at http://localhost:8080/bundle.js:80958:19
at Array.forEach (native)
at new Logger (http://localhost:8080/bundle.js:80957:26)
at Function.createLogger (http://localhost:8080/bundle.js:82060:13)
at BunyanLogger.getLogger (http://localhost:8080/bundle.js:80479:18)
我认为这是因为fs已被填充为空文件。
我该如何工作?
最佳答案
我通过将bunyan-sfdx-no-dtrace
用作bunyan
的别名来解决此烦恼。这是一个删除dtrace东西的叉子。
这只是我webpack.config.js
的相关部分
module.exports = {
resolve: {
alias: {
bunyan: "bunyan-sfdx-no-dtrace"
}
}
};
免责声明AFAICT既不积极也不适当地维护bunyan本身或bunyan-sfdx-no-dtrace,因此买家要当心。我不得不处理这个问题,因为bunyan是我需要的模块的子依赖项。