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

how to set config directly rather than string or file #30

Closed
ydcool opened this issue Apr 1, 2021 · 2 comments
Closed

how to set config directly rather than string or file #30

ydcool opened this issue Apr 1, 2021 · 2 comments

Comments

@ydcool
Copy link
Contributor

ydcool commented Apr 1, 2021

I found it is impossible to merge more than one configString like this (last config string will override previous one):

const defaultConfig = `
{
        formatter.name = "text"
        formatter.options  {
                            force-colors      = false
                            full-timestamp    = false
                            timestamp-format  = "01/02 15:04:05.000"
        }
}
`

opts := make([]logrus_mate.Option, 0)
opts = append(opts, logrus_mate.ConfigString(defaultConfig))

if (someCondition){
    opts = append(opts, logrus_mate.ConfigString(fmt.Sprintf(`{ level = "%s" }`, myLevel)))
}
if (anotherCondition){
   opts = append(opts, logrus_mate.ConfigString(`hook { file { filename = "my.log" } }`)
}
logrus_mate.Hijack(logrus.StandardLogger(),opts...)

so, is there any approach to set up configuration (in struct or sth else) directly rather than using string or a file?

@xujinzheng
Copy link
Member

You can implement a configProvider https://github.com/gogap/config/blob/master/providers.go 😃

@ydcool
Copy link
Contributor Author

ydcool commented Apr 6, 2021

got it, THX

@ydcool ydcool closed this as completed Apr 6, 2021
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

No branches or pull requests

2 participants