Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up to level #60

Closed
wants to merge 5 commits into from
Closed

Set up to level #60

wants to merge 5 commits into from

Conversation

franciscocpg
Copy link

level.SetUpToLevel creates the possibility to set a log level that is enabled up to the desired level.
This way, one can create different formatters for low levels and high levels.
For example:

    format1 := MustStringFormatter("%{color}%{time:15:04:05.000} %{level:.4s} %{id:03x} %{message}%{color:reset}")
    backend1 := NewLogBackend(os.Stderr, "", 0)
    backendFormatter1 := NewBackendFormatter(backend1, format1)
    backendLeveled1 := AddModuleLevel(backendFormatter1)
    backendLeveled1.SetUpToLevel(INFO, "")

    format2 := MustStringFormatter("%{color}%{time:15:04:05.000} %{longfile}:%{shortpkg}.%{longfunc} ▶ %{level:.4s} %{id:03x} %{message}%{color:reset}")
    backend2 := NewLogBackend(os.Stderr, "", 0)
    backendFormatter2 := NewBackendFormatter(backend2, format2)
    backendLeveled2 := AddModuleLevel(backendFormatter2)
    backendLeveled2.SetLevel(ERROR, "")
    SetBackend(backendLeveled1, backendLeveled2)
    log := MustGetLogger("testing")
    log.Debug("debug")
    log.Info("info")
    log.Error("error")

will result in a format for levels up to INFO and another for ERROR or CRITICAL.

@op
Copy link
Owner

op commented Jun 23, 2015

Wouldn't it make more sense to add a SetMaxLevel function and track these levels separately? Please add tests.

@op
Copy link
Owner

op commented Jun 23, 2015

I also can't guarantee that I will merge this. It feels like there has to be a cleaner approach.

@op
Copy link
Owner

op commented Nov 24, 2015

Sorry for the delay. Wouldn't it be nicer if you created a new backend which adds this functionality? Closing for now. Please open a new PR where you haven't disabled tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants