go-ozzo / ozzo-log

A Go (golang) package providing high-performance asynchronous logging, message filtering by severity and category, and multiple message targets.
MIT License
122 stars 31 forks source link

Logger is not working #2

Closed kolkov closed 8 years ago

kolkov commented 8 years ago

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.

qiangxue commented 8 years ago

Did you call logger.Open()?

kolkov commented 8 years ago

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()
}
kolkov commented 8 years ago

I tried to run app in liteIde instead IDEA and console is working, but file not. (

kolkov commented 8 years ago

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.

qiangxue commented 8 years ago

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.

kolkov commented 8 years ago

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. (

qiangxue commented 8 years ago

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.

kolkov commented 8 years ago

Thanks! Are you using IDEA on Linux or on Windows? And how you debuging your code?

qiangxue commented 8 years ago

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.

kolkov commented 8 years ago

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! )

qiangxue commented 8 years ago

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.