aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/log/log.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/log/log.go')
-rw-r--r--libgo/go/log/log.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/libgo/go/log/log.go b/libgo/go/log/log.go
index 58b8788be4a..587904b11c4 100644
--- a/libgo/go/log/log.go
+++ b/libgo/go/log/log.go
@@ -72,7 +72,7 @@ func (l *Logger) SetOutput(w io.Writer) {
var std = New(os.Stderr, "", LstdFlags)
-// Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
+// Cheap integer to fixed-width decimal ASCII. Give a negative width to avoid zero-padding.
func itoa(buf *[]byte, i int, wid int) {
// Assemble decimal in reverse order.
var b [20]byte
@@ -89,12 +89,16 @@ func itoa(buf *[]byte, i int, wid int) {
*buf = append(*buf, b[bp:]...)
}
+// formatHeader writes log header to buf in following order:
+// * l.prefix (if it's not blank),
+// * date and/or time (if corresponding flags are provided),
+// * file and line number (if corresponding flags are provided).
func (l *Logger) formatHeader(buf *[]byte, t time.Time, file string, line int) {
*buf = append(*buf, l.prefix...)
- if l.flag&LUTC != 0 {
- t = t.UTC()
- }
if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
+ if l.flag&LUTC != 0 {
+ t = t.UTC()
+ }
if l.flag&Ldate != 0 {
year, month, day := t.Date()
itoa(buf, year, 4)
@@ -143,13 +147,17 @@ func (l *Logger) formatHeader(buf *[]byte, t time.Time, file string, line int) {
// provided for generality, although at the moment on all pre-defined
// paths it will be 2.
func (l *Logger) Output(calldepth int, s string) error {
- now := time.Now() // get this early.
+ // Get time early if we need it.
+ var now time.Time
+ if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
+ now = time.Now()
+ }
var file string
var line int
l.mu.Lock()
defer l.mu.Unlock()
if l.flag&(Lshortfile|Llongfile) != 0 {
- // release lock while getting caller info - it's expensive.
+ // Release lock while getting caller info - it's expensive.
l.mu.Unlock()
var ok bool
_, file, line, ok = runtime.Caller(calldepth)