Skip to content

change delimiter in output format #121

Open
@Viv1k

Description

@Viv1k

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions