-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
40993: util/log: refactor and bug fixes r=knz a=knz Fixes #40983. Fixes #40973. Fixes #40974. Fixes #41231. I might also want to add code to clean up #40972, #40982 and #40990 provided I receive some guidance from @tbg or someone familiar with the log package. 41654: parser: fix telemetry link for materialized views r=jordanlewis a=jordanlewis This commit fixes the error message that you get if you try to create a materialized view to point at the right GitHub issue. Release note: None Co-authored-by: Raphael 'kena' Poss <[email protected]> Co-authored-by: Jordan Lewis <[email protected]>
- Loading branch information
Showing
29 changed files
with
1,763 additions
and
1,417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// traceLocation represents the setting of the -log_backtrace_at flag. | ||
// When a log entry is written that was produced at that location, | ||
// a backtrace is also emitted to the log. | ||
// | ||
// TODO(knz): this seems to be dead code. | ||
// See: https://github.com/cockroachdb/cockroach/issues/40990 | ||
type traceLocation struct { | ||
file string | ||
line int | ||
} | ||
|
||
// isSet reports whether the trace location has been specified. | ||
// mainLog.mu is held. | ||
func (t *traceLocation) isSet() bool { | ||
return t.line > 0 | ||
} | ||
|
||
// match reports whether the specified file and line matches the trace location. | ||
// The argument file name is the full path, not the basename specified in the flag. | ||
// mainLog.mu is held. | ||
func (t *traceLocation) match(file string, line int) bool { | ||
if t.line != line { | ||
return false | ||
} | ||
if i := strings.LastIndexByte(file, '/'); i >= 0 { | ||
file = file[i+1:] | ||
} | ||
return t.file == file | ||
} | ||
|
||
func (t *traceLocation) String() string { | ||
// Lock because the type is not atomic. TODO: clean this up. | ||
logging.mu.Lock() | ||
defer logging.mu.Unlock() | ||
return fmt.Sprintf("%s:%d", t.file, t.line) | ||
} | ||
|
||
var errTraceSyntax = errors.New("syntax error: expect file.go:234") | ||
|
||
// Syntax: -log_backtrace_at=gopherflakes.go:234 | ||
// Note that unlike vmodule the file extension is included here. | ||
func (t *traceLocation) Set(value string) error { | ||
if value == "" { | ||
// Unset. | ||
logging.mu.Lock() | ||
defer logging.mu.Unlock() | ||
t.line = 0 | ||
t.file = "" | ||
return nil | ||
} | ||
fields := strings.Split(value, ":") | ||
if len(fields) != 2 { | ||
return errTraceSyntax | ||
} | ||
file, line := fields[0], fields[1] | ||
if !strings.Contains(file, ".") { | ||
return errTraceSyntax | ||
} | ||
v, err := strconv.Atoi(line) | ||
if err != nil { | ||
return errTraceSyntax | ||
} | ||
if v <= 0 { | ||
return errors.New("negative or zero value for level") | ||
} | ||
logging.mu.Lock() | ||
defer logging.mu.Unlock() | ||
t.line = v | ||
t.file = file | ||
return nil | ||
} |
Oops, something went wrong.