Closed kolkov closed 8 years ago
Did you call logger.Open()?
Yes! My code is:
package main
import (
"github.com/go-ozzo/ozzo-log"
)
func main() {
// creates the root logger
logger := log.NewLogger()
// adds a console targe and a file target
t1 := log.NewConsoleTarget()
t2 := log.NewFileTarget()
t2.FileName = "app.log"
t2.MaxLevel = log.LevelError
logger.Targets = append(logger.Targets, t1, t2)
// opens the logger
logger.Open()
// calls log methods to log various log messages
logger.Warning("some warning first")
logger.Error("plain text error")
logger.Warning("some warning second")
logger.Error("error with format: %v", true)
logger.Debug("some debug info")
// customizes log category
l := logger.GetLogger("app.services")
l.Info("some info")
l.Warning("some warning")
logger.Close()
}
I tried to run app in liteIde instead IDEA and console is working, but file not. (
I do some debug experements. And I have some results. If I stop on breakpoints, sometimes data register in the file. ((
2015-12-20T04:11:17+03:00 [Error][app] plain text error
I think the main problem is in goroutine.
You are right. It's because the main goroutine quits before the file target has the chance to flush the logs to the file. If it is used in a server, this problem will not occur. Will think of a way to solve this problem.
Qiang, what tool did you use to write and debug Golang code? I use IDEA with plugin for Go on Windows, but debug is not working now yet. In the LiteIDE debug is working, but not perfect. (
I'm using the plugin too: https://github.com/go-lang-plugin-org/go-lang-idea-plugin Yes, it's not perfect yet. I have hard time making it work for unit tests.
Thanks! Are you using IDEA on Linux or on Windows? And how you debuging your code?
I'm on Mac. I only used go debugger in IDEA (PHPStorm to be exact) a few times. It's not perfect, but still usable. I'm mainly using Go to develop REST APIs for now. So most problems are easy to solve without debugging.
Thanks! Are you using the Delve debugger or GDB? https://github.com/derekparker/delve Its for OS X. Yes! I need support for REST APIs now to! )
I think go-lang-idea-plugin is based on Delve. For REST APIs, I often use println to print things I want to inspect. To make it easier, I create some gulp tasks to watch go file changes and automatically rebuild/re-launch the server. This gives almost the same experience as writing in scripting language like PHP.
Hi! I try to use Logger as shown in example. The application builds without errors. The file is created, but it is always empty ( And In console nothing to.