Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2258)

Issue 2419042: code review 2419042: log: new interface (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 6 months ago by r
Modified:
13 years, 6 months ago
Reviewers:
CC:
rsc, golang-dev
Visibility:
Public.

Description

log: new interface New logging interface simplifies and generalizes. 1) Loggers now have only one output. 2) log.Stdout, Stderr, Crash and friends are gone. Logging is now always to standard error by default. 3) log.Panic* replaces log.Crash*. 4) Exiting and panicking are not part of the logger's state; instead the functions Exit* and Panic* simply call Exit or panic after printing. 5) There is now one 'standard logger'. Instead of calling Stderr, use Print etc. There are now triples, by analogy with fmt: Print, Println, Printf What was log.Stderr is now best represented by log.Println, since there are now separate Print and Println functions (and methods). 6) New functions SetOutput, SetFlags, and SetPrefix allow global editing of the standard logger's properties. This is new functionality. For instance, one can call log.SetFlags(log.Lshortfile|log.Ltime|log.Lmicroseconds) to get all logging output to show file name, line number, and time stamp. In short, for most purposes log.Stderr -> log.Println or log.Print log.Stderrf -> log.Printf log.Crash -> log.Panicln or log.Panic log.Crashf -> log.Panicf log.Exit -> log.Exitln or log.Exit log.Exitf -> log.Exitf (no change) This has a slight breakage: since loggers now write only to one output, existing calls to log.New() need to delete the second argument. Also, custom loggers with exit or panic properties will need to be reworked. All package code updated to new interface. The test has been reworked somewhat. The old interface will be removed after the new release. For now, its elements are marked 'deprecated' in their comments. Fixes issue 1184.

Patch Set 1 #

Patch Set 2 : code review 2419042: log: new interface #

Patch Set 3 : code review 2419042: log: new interface #

Patch Set 4 : code review 2419042: log: new interface #

Patch Set 5 : code review 2419042: log: new interface #

Total comments: 4

Patch Set 6 : code review 2419042: log: new interface #

Unified diffs Side-by-side diffs Delta from patch set Stats (+359 lines, -304 lines) Patch
M src/cmd/godoc/codewalk.go View 3 chunks +3 lines, -3 lines 0 comments Download
M src/cmd/godoc/godoc.go View 13 chunks +17 lines, -17 lines 0 comments Download
M src/cmd/godoc/main.go View 6 chunks +14 lines, -14 lines 0 comments Download
M src/cmd/goinstall/parse.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/crypto/tls/generate_cert.go View 1 chunk +3 lines, -3 lines 0 comments Download
M src/pkg/exp/draw/x11/conn.go View 4 chunks +4 lines, -4 lines 0 comments Download
M src/pkg/exp/eval/bridge.go View 3 chunks +5 lines, -5 lines 0 comments Download
M src/pkg/exp/eval/eval_test.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/exp/eval/expr.go View 24 chunks +25 lines, -25 lines 0 comments Download
M src/pkg/exp/eval/expr1.go View 50 chunks +52 lines, -52 lines 0 comments Download
M src/pkg/exp/eval/gen.go View 9 chunks +9 lines, -9 lines 0 comments Download
M src/pkg/exp/eval/scope.go View 4 chunks +6 lines, -6 lines 0 comments Download
M src/pkg/exp/eval/stmt.go View 14 chunks +17 lines, -17 lines 0 comments Download
M src/pkg/exp/eval/type.go View 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/exp/eval/typec.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/exp/nacl/av/av.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/exp/nacl/av/event.go View 2 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/exp/nacl/srpc/client.go View 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/exp/nacl/srpc/server.go View 2 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/exp/ogle/process.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/exp/ogle/rtype.go View 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/exp/ogle/vars.go View 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/expvar/expvar.go View 1 chunk +2 lines, -2 lines 0 comments Download
M src/pkg/gob/debug.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/http/server.go View 3 chunks +4 lines, -4 lines 0 comments Download
M src/pkg/http/triv.go View 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/log/log.go View 1 2 3 4 5 5 chunks +120 lines, -57 lines 0 comments Download
M src/pkg/log/log_test.go View 4 chunks +25 lines, -33 lines 0 comments Download
M src/pkg/netchan/export.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/netchan/import.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/rpc/client.go View 2 chunks +2 lines, -2 lines 0 comments Download
M src/pkg/rpc/server.go View 7 chunks +14 lines, -14 lines 0 comments Download
M src/pkg/rpc/server_test.go View 1 chunk +3 lines, -3 lines 0 comments Download
M src/pkg/syslog/syslog.go View 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/testing/iotest/logger.go View 2 chunks +6 lines, -6 lines 0 comments Download
M src/pkg/websocket/websocket_test.go View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 3
r
Hello rsc (cc: golang-dev@googlegroups.com), I'd like you to review this change.
13 years, 6 months ago (2010-10-12 19:26:37 UTC) #1
rsc1
LGTM http://codereview.appspot.com/2419042/diff/12001/src/pkg/log/log.go File src/pkg/log/log.go (right): http://codereview.appspot.com/2419042/diff/12001/src/pkg/log/log.go#newcode12 src/pkg/log/log.go:12: // Exit exits when written to. The Exit ...
13 years, 6 months ago (2010-10-12 19:46:36 UTC) #2
r
13 years, 6 months ago (2010-10-12 19:59:23 UTC) #3
*** Submitted as http://code.google.com/p/go/source/detail?r=d8a3c7563d5f ***

log: new interface

New logging interface simplifies and generalizes.

1) Loggers now have only one output.
2) log.Stdout, Stderr, Crash and friends are gone.
	Logging is now always to standard error by default.
3) log.Panic* replaces log.Crash*.
4) Exiting and panicking are not part of the logger's state; instead
	the functions Exit* and Panic* simply call Exit or panic after
	printing.
5) There is now one 'standard logger'.  Instead of calling Stderr,
	use Print etc.  There are now triples, by analogy with fmt:
		Print, Println, Printf
	What was log.Stderr is now best represented by log.Println,
	since there are now separate Print and Println functions
	(and methods).
6) New functions SetOutput, SetFlags, and SetPrefix allow global
	editing of the standard logger's properties.   This is new
	functionality. For instance, one can call
		log.SetFlags(log.Lshortfile|log.Ltime|log.Lmicroseconds)
	to get all logging output to show file name, line number, and
	time stamp.

In short, for most purposes
	log.Stderr -> log.Println or log.Print
	log.Stderrf -> log.Printf
	log.Crash -> log.Panicln or log.Panic
	log.Crashf -> log.Panicf
	log.Exit -> log.Exitln or log.Exit
	log.Exitf -> log.Exitf (no change)

This has a slight breakage: since loggers now write only to one
output, existing calls to log.New() need to delete the second argument.
Also, custom loggers with exit or panic properties will need to be
reworked.

All package code updated to new interface.

The test has been reworked somewhat.

The old interface will be removed after the new release.
For now, its elements are marked 'deprecated' in their comments.

Fixes issue 1184.

R=rsc
CC=golang-dev
http://codereview.appspot.com/2419042
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b