I am trying to create a logrus log (mylog) within the main package, and add log items to mylog by function calls within object methods in libraries.
(我试图在主程序包中创建日志日志(mylog),并通过库中对象方法内的函数调用将日志项添加到mylog中。)
In the main package, I created a logrus log called mylog I have a structure called "LogItemList" in a package called logutil and I want to write a method for the LogItemList which will automatically populate mylog with attributes within the object LogItemList.
(在主程序包中,我创建了一个名为mylog的日志日志,在名为logutil的程序包中有一个名为“ LogItemList”的结构,我想为LogItemList编写一个方法,该方法将使用对象LogItemList中的属性自动填充mylog。)
Here is the code for the LogItemList method:
(这是LogItemList方法的代码:)
func (self LogItemList) WriteToLog(inputlog *logrus.Logger) {
inputlog.WithFields(log.Fields{
"Event": "Event Description",
}).Info("Computing")
}
How should I call the method from the main package?
(我应该如何从主程序包中调用该方法?)
This code is not accepted by the compiler: (编译器不接受以下代码:)
loglist := logutil.NewLogItemList("Info", "main", "test")
loglist.WriteToLog(log.Logger)
The second line of the code (loglist.WriteToLog(log.Logger)) is not accepted by the compiler.
(编译器不接受第二行代码(loglist.WriteToLog(log.Logger))。)
I should pass a parameter to WriteToLog but I do not know which one. (我应该将一个参数传递给WriteToLog,但我不知道哪个。)
ask by Emanolo78 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…