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

change delimiter in output format #121

Open
Viv1k opened this issue Jan 19, 2018 · 0 comments
Open

change delimiter in output format #121

Viv1k opened this issue Jan 19, 2018 · 0 comments

Comments

@Viv1k
Copy link

Viv1k commented Jan 19, 2018

Many people may have requirement of customized output delimiter (like output should be comma or some-delimiter separated)
It make parsing of logs easier and they can be simply analyzed by using basic linux command (without using any third party software to write in a specific format and then using a log parser or analyzer library to see those logs).

Can we have a feature in go-logging library for customized output by changing output delimiter.

Is it currently possible?

Yes, but not through standard fmt.Fprintf function
In function (r *Record) Message() string https://github.com/op/go-logging/blob/master/logger.go#L69, go-logging uses fmt.Fprintf (which utilizes custom input format) and fmt.Fprintln (where delimiter is hard-coded to ' ' inside golang source code
https://github.com/golang/go/blob/4555ed2e5ef029cafb8040710537f0ebffd41ad6/src/fmt/print.go#L1141)

So, fmt package won't help us here.

How is possible?

By making a customized function and initial configuration

so we can have an initializer function like

(l *Logger) SetDelimiter(delimiter string) {
   // and change here Record structure to contain delimiter field storing provided delimiter value
}

and while writing to file
we can use the following function as suggested here

var formatMap = map[int]string{
    0: "",
    1: "%v",
}

func doPrintWithDelim(v ...interface{}) {
    l := len(v)
    if s, isOk := formatMap[l]; !isOk {
        for i := 0; i < len(v); i++ {
            s += "%v"
        }
        formatMap[l] = s
    }
    s := formatMap[l] + "\n"
    fmt.Printf(s, v...)
}

This would be very helpful if implemented in the library
If you want I can make pull request and make the changes for you.

Please let me know.

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

1 participant