오늘 약간의 문제로 여전히 오류가 발생합니다. 단지 콘솔 출력을 사용bunyan 로깅 기능을 ES6의 클래스 기능에 바인딩하려면 어떻게합니까?
const tools = new Tools(
config.region,
config.ssl,
logger.debug,
logger.error
);
로거 : 나는에 번연 로거의 기능을 보내 다른 곳에서 수업 시간에
constructor(region, sslEnabled = true,
logger =() => {}, errorLogger =() => {}) {
if (region === undefined || !region)
throw new Error("Initialization error: region is required");
this.log =() => {}; // these two lines might be unnecessary
this.logError =() => {}; //
this.log = logger.bind(this);
this.logError = errorLogger.bind(this);
this.region = region;
this.sslEnabled = sslEnabled;
}
: Docs here. 가장 가까운을 내가 가진이있다. 이것은 내가 console.log
및 console.error
를 전달하면 작동하지만 내가 번연 로거를 통과하면 실패
bunyan usage error: /usr/src/app/src/healthcheck.js:47:
attempt to log with an unbound log method: `this` is: TTools {
log: [Function: bound ],
logError: [Function: bound ],
region: 'us-west-2',
sslEnabled: false }
이것에 대해 github의 문제가 있지만 정말 명확한 해결 방법을하는하지 않았다. logger.error
과 같은 번난 로거 기능을 다른 객체에 전달하려면 어떻게해야합니까? 이것이 가능한가?