Log prints a message to the debug log (if debug is enabled).
(f string, args ...interface{})
| 162 | |
| 163 | // Log prints a message to the debug log (if debug is enabled). |
| 164 | func Log(f string, args ...interface{}) { |
| 165 | if !opts.isEnabled { |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | fn, dir, file, line := getPosition() |
| 170 | goroutine := goroutineNum() |
| 171 | |
| 172 | if len(f) == 0 || f[len(f)-1] != '\n' { |
| 173 | f += "\n" |
| 174 | } |
| 175 | |
| 176 | type Shortener interface { |
| 177 | Str() string |
| 178 | } |
| 179 | |
| 180 | for i, item := range args { |
| 181 | if shortener, ok := item.(Shortener); ok { |
| 182 | args[i] = shortener.Str() |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | pos := fmt.Sprintf("%s/%s:%d", dir, file, line) |
| 187 | |
| 188 | formatString := fmt.Sprintf("%s\t%s\t%d\t%s", pos, fn, goroutine, f) |
| 189 | |
| 190 | dbgprint := func() { |
| 191 | fmt.Fprintf(os.Stderr, formatString, args...) |
| 192 | } |
| 193 | |
| 194 | if opts.logger != nil { |
| 195 | opts.logger.Printf(formatString, args...) |
| 196 | } |
| 197 | |
| 198 | filename := fmt.Sprintf("%s/%s:%d", dir, file, line) |
| 199 | if checkFilter(opts.files, filename) { |
| 200 | dbgprint() |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | if checkFilter(opts.funcs, fn) { |
| 205 | dbgprint() |
| 206 | } |
| 207 | } |