// a codewalk description.
cw, err := loadCodewalk(abspath + ".xml")
if err != nil {
- log.Stderr(err)
+ log.Print(err)
serveError(w, r, relpath, err)
return
}
dir, err := ioutil.ReadDir(abspath)
if err != nil {
- log.Stderr(err)
+ log.Print(err)
serveError(w, r, relpath, err)
return
}
abspath := absolutePath(f, *goroot)
data, err := ioutil.ReadFile(abspath)
if err != nil {
- log.Stderr(err)
+ log.Print(err)
serveError(w, r, f, err)
return
}
// update filter file
if err := writeFileAtomically(*filter, buf.Bytes()); err != nil {
- log.Stderrf("writeFileAtomically(%s): %s", *filter, err)
+ log.Printf("writeFileAtomically(%s): %s", *filter, err)
filterDelay.backoff(24 * 60) // back off exponentially, but try at least once a day
} else {
filterDelay.set(*filterMin) // revert to regular filter update schedule
if *filter != "" {
list, err := readDirList(*filter)
if err != nil {
- log.Stderrf("%s", err)
+ log.Printf("%s", err)
} else if len(list) == 0 {
- log.Stderrf("no directory paths in file %s", *filter)
+ log.Printf("no directory paths in file %s", *filter)
}
setPathFilter(list)
}
go func() {
for {
if *verbose {
- log.Stderrf("start update of %s", *filter)
+ log.Printf("start update of %s", *filter)
}
updateFilterFile()
delay, _ := filterDelay.get()
if *verbose {
- log.Stderrf("next filter update in %dmin", delay.(int))
+ log.Printf("next filter update in %dmin", delay.(int))
}
time.Sleep(int64(delay.(int)) * 60e9)
}
default:
// we should never reach here, but be resilient
// and assume the url-pkg format instead
- log.Stderrf("INTERNAL ERROR: urlFmt(%s)", format)
+ log.Printf("INTERNAL ERROR: urlFmt(%s)", format)
fallthrough
case "url-pkg":
// because of the irregular mapping under goroot
}
if err := godocHTML.Execute(&d, w); err != nil {
- log.Stderrf("godocHTML.Execute: %s", err)
+ log.Printf("godocHTML.Execute: %s", err)
}
}
// get HTML body contents
src, err := ioutil.ReadFile(abspath)
if err != nil {
- log.Stderrf("ioutil.ReadFile: %s", err)
+ log.Printf("ioutil.ReadFile: %s", err)
serveError(w, r, relpath, err)
return
}
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
var buf bytes.Buffer
if err := t.Execute(data, &buf); err != nil {
- log.Stderrf("%s.Execute: %s", name, err)
+ log.Printf("%s.Execute: %s", name, err)
}
return buf.Bytes()
}
func serveGoSource(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
file, err := parser.ParseFile(abspath, nil, parser.ParseComments)
if err != nil {
- log.Stderrf("parser.ParseFile: %s", err)
+ log.Printf("parser.ParseFile: %s", err)
serveError(w, r, relpath, err)
return
}
func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
src, err := ioutil.ReadFile(abspath)
if err != nil {
- log.Stderrf("ioutil.ReadFile: %s", err)
+ log.Printf("ioutil.ReadFile: %s", err)
serveError(w, r, relpath, err)
return
}
list, err := ioutil.ReadDir(abspath)
if err != nil {
- log.Stderrf("ioutil.ReadDir: %s", err)
+ log.Printf("ioutil.ReadDir: %s", err)
serveError(w, r, relpath, err)
return
}
dir, err := os.Lstat(abspath)
if err != nil {
- log.Stderr(err)
+ log.Print(err)
serveError(w, r, relpath, err)
return
}
}
info := h.getPageInfo(abspath, relpath, r.FormValue("p"), mode)
if info.Err != nil {
- log.Stderr(info.Err)
+ log.Print(info.Err)
serveError(w, r, relpath, info.Err)
return
}
if *verbose {
secs := float64((stop-start)/1e6) / 1e3
nwords, nspots := index.Size()
- log.Stderrf("index updated (%gs, %d unique words, %d spots)", secs, nwords, nspots)
+ log.Printf("index updated (%gs, %d unique words, %d spots)", secs, nwords, nspots)
}
- log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.HeapAlloc, runtime.MemStats.Sys)
+ log.Printf("bytes=%d footprint=%d\n", runtime.MemStats.HeapAlloc, runtime.MemStats.Sys)
runtime.GC()
- log.Stderrf("bytes=%d footprint=%d\n", runtime.MemStats.HeapAlloc, runtime.MemStats.Sys)
+ log.Printf("bytes=%d footprint=%d\n", runtime.MemStats.HeapAlloc, runtime.MemStats.Sys)
}
time.Sleep(1 * 60e9) // try once a minute
}
func exec(rw http.ResponseWriter, args []string) (status int) {
r, w, err := os.Pipe()
if err != nil {
- log.Stderrf("os.Pipe(): %v\n", err)
+ log.Printf("os.Pipe(): %v\n", err)
return 2
}
bin := args[0]
fds := []*os.File{nil, w, w}
if *verbose {
- log.Stderrf("executing %v", args)
+ log.Printf("executing %v", args)
}
pid, err := os.ForkExec(bin, args, os.Environ(), *goroot, fds)
defer r.Close()
w.Close()
if err != nil {
- log.Stderrf("os.ForkExec(%q): %v\n", bin, err)
+ log.Printf("os.ForkExec(%q): %v\n", bin, err)
return 2
}
wait, err := os.Wait(pid, 0)
if err != nil {
os.Stderr.Write(buf.Bytes())
- log.Stderrf("os.Wait(%d, 0): %v\n", pid, err)
+ log.Printf("os.Wait(%d, 0): %v\n", pid, err)
return 2
}
status = wait.ExitStatus()
if !wait.Exited() || status > 1 {
os.Stderr.Write(buf.Bytes())
- log.Stderrf("executing %v failed (exit status = %d)", args, status)
+ log.Printf("executing %v failed (exit status = %d)", args, status)
return
}
func loggingHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- log.Stderrf("%s\t%s", w.RemoteAddr(), req.URL)
+ log.Printf("%s\t%s", w.RemoteAddr(), req.URL)
h.ServeHTTP(w, req)
})
}
// HTTP server mode.
var handler http.Handler = http.DefaultServeMux
if *verbose {
- log.Stderrf("Go Documentation Server\n")
- log.Stderrf("version = %s\n", runtime.Version())
- log.Stderrf("address = %s\n", *httpAddr)
- log.Stderrf("goroot = %s\n", *goroot)
- log.Stderrf("tabwidth = %d\n", *tabwidth)
+ log.Printf("Go Documentation Server\n")
+ log.Printf("version = %s\n", runtime.Version())
+ log.Printf("address = %s\n", *httpAddr)
+ log.Printf("goroot = %s\n", *goroot)
+ log.Printf("tabwidth = %d\n", *tabwidth)
if !fsMap.IsEmpty() {
- log.Stderr("user-defined mapping:")
+ log.Print("user-defined mapping:")
fsMap.Fprint(os.Stderr)
}
handler = loggingHandler(handler)
dosync(nil, nil)
delay, _ := syncDelay.get()
if *verbose {
- log.Stderrf("next sync in %dmin", delay.(int))
+ log.Printf("next sync in %dmin", delay.(int))
}
time.Sleep(int64(delay.(int)) * 60e9)
}
}
if err := packageText.Execute(info, os.Stdout); err != nil {
- log.Stderrf("packageText.Execute: %s", err)
+ log.Printf("packageText.Execute: %s", err)
}
}
quoted := string(spec.(*ast.ImportSpec).Path.Value)
unquoted, err := strconv.Unquote(quoted)
if err != nil {
- log.Crashf("%s: parser returned invalid quoted string: <%s>", filename, quoted)
+ log.Panicf("%s: parser returned invalid quoted string: <%s>", filename, quoted)
}
imports[unquoted] = filename
}
}
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
certOut.Close()
- log.Stdoutf("written cert.pem\n")
+ log.Print("written cert.pem\n")
keyOut, err := os.Open("key.pem", os.O_WRONLY|os.O_CREAT, 0600)
if err != nil {
- log.Exitf("failed to open key.pem for writing: %s", err)
+ log.Print("failed to open key.pem for writing:", err)
return
}
pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
keyOut.Close()
- log.Stdoutf("written key.pem\n")
+ log.Print("written key.pem\n")
}
// TODO(nigeltao): See what XCB's xcb_put_image does in this situation.
units := 6 + b.Dx()
if units > 0xffff || b.Dy() > 0xffff {
- log.Stderr("x11: window is too large for PutImage")
+ log.Print("x11: window is too large for PutImage")
return
}
setU32LE(c.flushBuf0[16:20], uint32(y<<16))
if _, err := c.w.Write(c.flushBuf0[0:24]); err != nil {
if err != os.EOF {
- log.Stderr("x11: " + err.String())
+ log.Println("x11:", err.String())
}
return
}
x += nx
if _, err := c.w.Write(c.flushBuf1[0 : 4*nx]); err != nil {
if err != os.EOF {
- log.Stderr("x11: " + err.String())
+ log.Println("x11:", err.String())
}
return
}
}
if err := c.w.Flush(); err != nil {
if err != os.EOF {
- log.Stderr("x11: " + err.String())
+ log.Println("x11:", err.String())
}
return
}
case *reflect.ArrayType:
et = NewArrayType(int64(t.Len()), TypeFromNative(t.Elem()))
case *reflect.ChanType:
- log.Crashf("%T not implemented", t)
+ log.Panicf("%T not implemented", t)
case *reflect.FuncType:
nin := t.NumIn()
// Variadic functions have DotDotDotType at the end
}
et = NewFuncType(in, variadic, out)
case *reflect.InterfaceType:
- log.Crashf("%T not implemented", t)
+ log.Panicf("%T not implemented", t)
case *reflect.MapType:
- log.Crashf("%T not implemented", t)
+ log.Panicf("%T not implemented", t)
case *reflect.PtrType:
et = NewPtrType(TypeFromNative(t.Elem()))
case *reflect.SliceType:
}
et = NewStructType(fields)
case *reflect.UnsafePointerType:
- log.Crashf("%T not implemented", t)
+ log.Panicf("%T not implemented", t)
default:
- log.Crashf("unexpected reflect.Type: %T", t)
+ log.Panicf("unexpected reflect.Type: %T", t)
}
if nt != nil {
case Func:
return &funcV{val}
}
- log.Crashf("toValue(%T) not implemented", val)
+ log.Panicf("toValue(%T) not implemented", val)
panic("unreachable")
}
// TODO(austin) Rename to resolveIdeal or something?
func (a *expr) convertTo(t Type) *expr {
if !a.t.isIdeal() {
- log.Crashf("attempted to convert from %v, expected ideal", a.t)
+ log.Panicf("attempted to convert from %v, expected ideal", a.t)
}
var rat *big.Rat
i := a.asIdealInt()()
rat = new(big.Rat).SetInt(i)
default:
- log.Crashf("unexpected ideal type %v", a.t)
+ log.Panicf("unexpected ideal type %v", a.t)
}
// Check bounds
case *idealFloatType:
res.eval = func() *big.Rat { return rat }
default:
- log.Crashf("cannot convert to type %T", t)
+ log.Panicf("cannot convert to type %T", t)
}
return res
if _, ok := pt.Elem.lit().(*ArrayType); ok {
deref := a.compileStarExpr(a)
if deref == nil {
- log.Crashf("failed to dereference *array")
+ log.Panicf("failed to dereference *array")
}
return deref
}
a.rs = make([]*expr, len(a.rmt.Elems))
for i, t := range a.rmt.Elems {
if t.isIdeal() {
- log.Crashf("Right side of unpack contains ideal: %s", rmt)
+ log.Panicf("Right side of unpack contains ideal: %s", rmt)
}
a.rs[i] = orig.newExpr(t, orig.desc)
index := i
case token.STRING:
return ei.compileStringLit(string(x.Value))
default:
- log.Crashf("unexpected basic literal type %v", x.Kind)
+ log.Panicf("unexpected basic literal type %v", x.Kind)
}
case *ast.CompositeLit:
}
return ei.compileUnaryExpr(x.Op, v)
}
- log.Crashf("unexpected ast node type %T", x)
+ log.Panicf("unexpected ast node type %T", x)
panic("unreachable")
typeexpr:
a.diag("type %v used as expression", name)
return nil
}
- log.Crashf("name %s has unknown type %T", name, def)
+ log.Panicf("name %s has unknown type %T", name, def)
panic("unreachable")
}
func (a *exprInfo) compileFloatLit(lit string) *expr {
f, ok := new(big.Rat).SetString(lit)
if !ok {
- log.Crashf("malformed float literal %s at %v passed parser", lit, a.pos)
+ log.Panicf("malformed float literal %s at %v passed parser", lit, a.pos)
}
expr := a.newExpr(IdealFloatType, "float literal")
expr.eval = func() *big.Rat { return f }
ambig = true
default:
- log.Crashf("Marked field at depth %d, but already found one at depth %d", depth, bestDepth)
+ log.Panicf("Marked field at depth %d, but already found one at depth %d", depth, bestDepth)
}
amberr += "\n\t" + pathName[1:]
}
_, ok := ti.methods[name]
if ok {
mark(depth, pathName+"."+name)
- log.Crash("Methods not implemented")
+ log.Panic("Methods not implemented")
}
t = ti.Def
}
}
default:
- log.Crashf("unexpected left operand type %T", arr.t.lit())
+ log.Panicf("unexpected left operand type %T", arr.t.lit())
}
return expr
}
default:
- log.Crashf("unexpected left operand type %T", l.t.lit())
+ log.Panicf("unexpected left operand type %T", l.t.lit())
}
return expr
return expr
}
- log.Crashf("unexpected built-in function '%s'", ft.builtin)
+ log.Panicf("unexpected built-in function '%s'", ft.builtin)
panic("unreachable")
}
t = NewPtrType(v.t)
case token.ARROW:
- log.Crashf("Unary op %v not implemented", op)
+ log.Panicf("Unary op %v not implemented", op)
default:
- log.Crashf("unknown unary operator %v", op)
+ log.Panicf("unknown unary operator %v", op)
}
desc, ok := unaryOpDescs[op]
expr.eval = func(t *Thread) Value { return vf(t) }
default:
- log.Crashf("Compilation of unary op %v not implemented", op)
+ log.Panicf("Compilation of unary op %v not implemented", op)
}
return expr
if l.t.isIdeal() && !r.t.isInteger() {
r = r.convertTo(IdealIntType)
if r == nil {
- log.Crashf("conversion to uintType succeeded, but conversion to idealIntType failed")
+ log.Panicf("conversion to uintType succeeded, but conversion to idealIntType failed")
}
}
} else if _, ok := r.t.lit().(*uintType); !ok {
// The operands in channel sends differ in type: one
// is always a channel and the other is a variable or
// value of the channel's element type.
- log.Crash("Binary op <- not implemented")
+ log.Panic("Binary op <- not implemented")
t = BoolType
case token.LSS, token.GTR, token.LEQ, token.GEQ:
t = BoolType
default:
- log.Crashf("unknown binary operator %v", op)
+ log.Panicf("unknown binary operator %v", op)
}
desc, ok := binOpDescs[op]
expr.genBinOpLogOr(l, r)
default:
- log.Crashf("Compilation of binary op %v not implemented", op)
+ log.Panicf("Compilation of binary op %v not implemented", op)
}
return expr
case *uintType:
return int64(lenExpr.asUint()(nil)), true
}
- log.Crashf("unexpected integer type %T", lenExpr.t)
+ log.Panicf("unexpected integer type %T", lenExpr.t)
return 0, false
}
nerr := a.numError()
e := ec.compile(expr, false)
if e == nil && nerr == a.numError() {
- log.Crashf("expression compilation failed without reporting errors")
+ log.Panicf("expression compilation failed without reporting errors")
}
return e
}
case tempType.isFloat():
tempType = FloatType
default:
- log.Crashf("unexpected ideal type %v", tempType)
+ log.Panicf("unexpected ideal type %v", tempType)
}
}
temp := b.DefineTemp(tempType)
// Create "temp := rhs"
assign := ac.compile(b, tempType)
if assign == nil {
- log.Crashf("compileAssign type check failed")
+ log.Panicf("compileAssign type check failed")
}
effect := func(t *Thread) {
case func(t *Thread) Map:
return func(t *Thread) interface{} { return sf(t) }
default:
- log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos)
+ log.Panicf("unexpected expression node type %T at %v", a.eval, a.pos)
}
panic("fail")
}
case *MapType:
a.eval = func(t *Thread) Map { return v.(MapValue).Get(t) }
default:
- log.Crashf("unexpected constant type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected constant type %v at %v", a.t, a.pos)
}
}
case *MapType:
a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get(t) }
default:
- log.Crashf("unexpected identifier type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected identifier type %v at %v", a.t, a.pos)
}
}
case *MultiType:
a.eval = func(t *Thread) []Value { return call(t) }
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
case *MapType:
a.eval = func(t *Thread) Map { return vf(t).(MapValue).Get(t) }
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
val.Neg(val)
a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
vf := v.asBool()
a.eval = func(t *Thread) bool { v := vf(t); return !v }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
val.Not(val)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
return l + r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
val := l.Sub(l, r)
a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
val := l.Mul(l, r)
a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
val := l.Quo(l, r)
a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
val := l.Rem(l, r)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
val := l.And(l, r)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
val := l.Or(l, r)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
val := l.Xor(l, r)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
val := l.AndNot(l, r)
a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l < r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l > r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l <= r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l >= r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l == r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
return l != r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
rf := r.asMap()
return func(lv Value, t *Thread) { lv.(MapValue).Set(t, rf(t)) }
default:
- log.Crashf("unexpected left operand type %v at %v", lt, r.pos)
+ log.Panicf("unexpected left operand type %v at %v", lt, r.pos)
}
panic("fail")
}
«.end»
«.end»
default:
- log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos)
+ log.Panicf("unexpected expression node type %T at %v", a.eval, a.pos)
}
panic("fail")
}
«.end»
«.end»
default:
- log.Crashf("unexpected constant type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected constant type %v at %v", a.t, a.pos)
}
}
«.end»
«.end»
default:
- log.Crashf("unexpected identifier type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected identifier type %v at %v", a.t, a.pos)
}
}
case *MultiType:
a.eval = func(t *Thread) []Value { return call(t) }
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
«.end»
«.end»
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
«.end»
«.end»
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
}
«.end»
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
«.or»
a.eval = func(t *Thread) «Native» {
«.end»
«.end»
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
«.end»
«.end»
default:
- log.Crashf("unexpected left operand type %v at %v", lt, r.pos)
+ log.Panicf("unexpected left operand type %v at %v", lt, r.pos)
}
panic("fail")
}
func (b *block) enterChild() *block {
if b.inner != nil && b.inner.scope == b.scope {
- log.Crash("Failed to exit child block before entering another child")
+ log.Panic("Failed to exit child block before entering another child")
}
sub := &block{
outer: b,
func (b *block) exit() {
if b.outer == nil {
- log.Crash("Cannot exit top-level block")
+ log.Panic("Cannot exit top-level block")
}
if b.outer.scope == b.scope {
if b.outer.inner != b {
- log.Crash("Already exited block")
+ log.Panic("Already exited block")
}
if b.inner != nil && b.inner.scope == b.scope {
- log.Crash("Exit of parent block without exit of child block")
+ log.Panic("Exit of parent block without exit of child block")
}
}
b.outer.inner = nil
func (b *block) ChildScope() *Scope {
if b.inner != nil && b.inner.scope == b.scope {
- log.Crash("Failed to exit child block before entering a child scope")
+ log.Panic("Failed to exit child block before entering a child scope")
}
sub := b.enterChild()
sub.offset = 0
func (b *block) defineSlot(t Type, temp bool) *Variable {
if b.inner != nil && b.inner.scope == b.scope {
- log.Crash("Failed to exit child block before defining variable")
+ log.Panic("Failed to exit child block before defining variable")
}
index := -1
if !b.global || temp {
func (f *flowBuf) put(cond bool, term bool, jumps []*uint) {
pc := f.cb.nextPC()
if ent, ok := f.ents[pc]; ok {
- log.Crashf("Flow entry already exists at PC %d: %+v", pc, ent)
+ log.Panicf("Flow entry already exists at PC %d: %+v", pc, ent)
}
f.ents[pc] = &flowEnt{cond, term, jumps, false}
}
func (f *flowBuf) reachesEnd(pc uint) bool {
endPC := f.cb.nextPC()
if pc > endPC {
- log.Crashf("Reached bad PC %d past end PC %d", pc, endPC)
+ log.Panicf("Reached bad PC %d past end PC %d", pc, endPC)
}
for ; pc < endPC; pc++ {
func (a *stmtCompiler) compile(s ast.Stmt) {
if a.block.inner != nil {
- log.Crash("Child scope still entered")
+ log.Panic("Child scope still entered")
}
notimpl := false
notimpl = true
default:
- log.Crashf("unexpected ast node type %T", s)
+ log.Panicf("unexpected ast node type %T", s)
}
if notimpl {
}
if a.block.inner != nil {
- log.Crash("Forgot to exit child scope")
+ log.Panic("Forgot to exit child scope")
}
}
case *ast.FuncDecl:
if !a.block.global {
- log.Crash("FuncDecl at statement level")
+ log.Panic("FuncDecl at statement level")
}
case *ast.GenDecl:
if decl.Tok == token.IMPORT && !a.block.global {
- log.Crash("import at statement level")
+ log.Panic("import at statement level")
}
default:
- log.Crashf("Unexpected Decl type %T", s.Decl)
+ log.Panicf("Unexpected Decl type %T", s.Decl)
}
a.compileDecl(s.Decl)
}
// Declaration without assignment
if spec.Type == nil {
// Parser should have caught
- log.Crash("Type and Values nil")
+ log.Panic("Type and Values nil")
}
t := a.compileType(a.block, spec.Type)
// Define placeholders even if type compile failed
case *ast.GenDecl:
switch d.Tok {
case token.IMPORT:
- log.Crashf("%v not implemented", d.Tok)
+ log.Panicf("%v not implemented", d.Tok)
case token.CONST:
- log.Crashf("%v not implemented", d.Tok)
+ log.Panicf("%v not implemented", d.Tok)
case token.TYPE:
a.compileTypeDecl(a.block, d)
case token.VAR:
}
default:
- log.Crashf("Unexpected Decl type %T", decl)
+ log.Panicf("Unexpected Decl type %T", decl)
}
}
op = token.SUB
desc = "decrement statement"
default:
- log.Crashf("Unexpected IncDec token %v", s.Tok)
+ log.Panicf("Unexpected IncDec token %v", s.Tok)
}
effect, l := l.extractEffect(bc.block, desc)
assign := a.compileAssign(s.Pos(), bc.block, l.t, []*expr{binop}, "", "")
if assign == nil {
- log.Crashf("compileAssign type check failed")
+ log.Panicf("compileAssign type check failed")
}
lf := l.evalAddr
case ac.rmt.Elems[i].isFloat():
lt = FloatType
default:
- log.Crashf("unexpected ideal type %v", rs[i].t)
+ log.Panicf("unexpected ideal type %v", rs[i].t)
}
default:
assign := a.compileAssign(s.Pos(), bc.block, l.t, []*expr{binop}, "assignment", "value")
if assign == nil {
- log.Crashf("compileAssign type check failed")
+ log.Panicf("compileAssign type check failed")
}
lf := l.evalAddr
return
default:
- log.Crash("Unexpected branch token %v", s.Tok)
+ log.Panic("Unexpected branch token %v", s.Tok)
}
a.flow.put1(false, pc)
case 64:
return minFloat64Val
}
- log.Crashf("unexpected floating point bit count: %d", bits)
+ log.Panicf("unexpected floating point bit count: %d", bits)
panic("unreachable")
}
case 64:
return maxFloat64Val
}
- log.Crashf("unexpected floating point bit count: %d", bits)
+ log.Panicf("unexpected floating point bit count: %d", bits)
panic("unreachable")
}
func (t *NamedType) Complete(def Type) {
if !t.incomplete {
- log.Crashf("cannot complete already completed NamedType %+v", *t)
+ log.Panicf("cannot complete already completed NamedType %+v", *t)
}
// We strip the name from def because multiple levels of
// naming are useless.
case Type:
return def
}
- log.Crashf("name %s has unknown type %T", x.Name, def)
+ log.Panicf("name %s has unknown type %T", x.Name, def)
return nil
}
return int(audioSize), nil
}
if uintptr(len(data))*2 != audioSize {
- log.Stdoutf("invalid audio size want %d got %d", audioSize, len(data))
+ log.Printf("invalid audio size want %d got %d", audioSize, len(data))
}
e := os.NewSyscallError("audio_stream", syscall.AudioStream(&data[0], &audioSize))
return int(audioSize), e
var e event
switch buf[0] {
default:
- log.Stdout("unsupported event type", buf[0])
+ log.Print("unsupported event type", buf[0])
continue
case eventActive:
ea = new(activeEvent)
}
r := reader(buf)
if err := binary.Read(&r, binary.LittleEndian, e); err != nil {
- log.Stdout("unpacking %T event: %s", e, err)
+ log.Print("unpacking %T event: %s", e, err)
continue
}
- // log.Stdoutf("%#v\n", e);
+ // log.Printf("%#v\n", e);
switch buf[0] {
case eventExpose:
w.eventc <- draw.ConfigEvent{image.Config{ColorModel, w.Image.Bounds().Dx(), w.Image.Bounds().Dy()}}
}
m.unpackResponse()
if m.status != OK {
- log.Stderrf("NewClient service_discovery: %s", m.status)
+ log.Printf("NewClient service_discovery: %s", m.status)
return nil, m.status
}
for n, line := range bytes.Split(m.Ret[0].([]byte), []byte{'\n'}, -1) {
log.Exitf("client recv: %s", err)
}
if m.unpackResponse(); m.status != OK {
- log.Stderrf("invalid message: %s", m.status)
+ log.Printf("invalid message: %s", m.status)
continue
}
c.mu.Lock()
}
c.mu.Unlock()
if !ok {
- log.Stderrf("unexpected response")
+ log.Print("unexpected response")
continue
}
rpc.Ret = m.Ret
}
m.unpackRequest()
if !m.gotHeader {
- log.Stderrf("cannot unpack header: %s", m.status)
+ log.Printf("cannot unpack header: %s", m.status)
continue
}
- // log.Stdoutf("<- %#v", m);
+ // log.Printf("<- %#v", m);
m.isReq = false // set up for response
go serveMsg(m, c)
}
var s msgSender
s.fd = fd
for m := range c {
- // log.Stdoutf("-> %#v", m);
+ // log.Printf("-> %#v", m);
m.packResponse()
s.send(m)
}
action, err = p.goroutineExitHook.handle(ev)
default:
- log.Crashf("Unknown event type %T in queue", p.event)
+ log.Panicf("Unknown event type %T in queue", p.event)
}
if err != nil {
rt = &remoteType{t, offset, fieldAlign, mk}
default:
- log.Crashf("cannot manually construct type %T", t)
+ log.Panicf("cannot manually construct type %T", t)
}
typeMap[t] = rt
if sym != nil {
name = sym.Name
}
- log.Stderrf("%sParsing type at %#x (%s)", prtIndent, addr, name)
+ log.Printf("%sParsing type at %#x (%s)", prtIndent, addr, name)
prtIndent += " "
defer func() { prtIndent = prtIndent[0 : len(prtIndent)-1] }()
}
// Symbol name
name := s.BaseName()
if _, ok := pkg[name]; ok {
- log.Stderrf("Multiple definitions of symbol %s", s.Name)
+ log.Printf("Multiple definitions of symbol %s", s.Name)
continue
}
err := w.DefineConst(pkgName, pkgType, pkgVal)
if err != nil {
- log.Stderrf("while defining package %s: %v", pkgName, err)
+ log.Printf("while defining package %s: %v", pkgName, err)
}
}
// Publish declares an named exported variable. This should be called from a
// package's init function when it creates its Vars. If the name is already
-// registered then this will log.Crash.
+// registered then this will log.Panic.
func Publish(name string, v Var) {
mutex.Lock()
defer mutex.Unlock()
if _, existing := vars[name]; existing {
- log.Crash("Reuse of exported var name:", name)
+ log.Panicln("Reuse of exported var name:", name)
}
vars[name] = v
}
break
}
if dec.state.err != nil {
- log.Stderr("debug:", dec.state.err)
+ log.Print("debug:", dec.state.err)
}
}
// WriteHeader implements the ResponseWriter.WriteHeader method
func (w *response) WriteHeader(code int) {
if w.conn.hijacked {
- log.Stderr("http: response.WriteHeader on hijacked connection")
+ log.Print("http: response.WriteHeader on hijacked connection")
return
}
if w.wroteHeader {
- log.Stderr("http: multiple response.WriteHeader calls")
+ log.Print("http: multiple response.WriteHeader calls")
return
}
w.wroteHeader = true
// Write implements the ResponseWriter.Write method
func (w *response) Write(data []byte) (n int, err os.Error) {
if w.conn.hijacked {
- log.Stderr("http: response.Write on hijacked connection")
+ log.Print("http: response.Write on hijacked connection")
return 0, ErrHijacked
}
if !w.wroteHeader {
//
// func main() {
// http.HandleFunc("/", handler)
-// log.Stdoutf("About to listen on 10443. Go to https://127.0.0.1:10443/")
+// log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/")
// err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
// if err != nil {
// log.Exit(err)
}
func Logger(w http.ResponseWriter, req *http.Request) {
- log.Stdout(req.URL.Raw)
+ log.Print(req.URL.Raw)
w.WriteHeader(404)
w.Write([]byte("oops"))
}
http.Handle("/date", http.HandlerFunc(DateServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
- log.Crash("ListenAndServe: ", err)
+ log.Panicln("ListenAndServe:", err)
}
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Rudimentary logging package. Defines a type, Logger, with simple
-// methods for formatting output to one or two destinations. Also has
-// predefined Loggers accessible through helper functions Stdout[f],
-// Stderr[f], Exit[f], and Crash[f], which are easier to use than creating
-// a Logger manually.
-// Exit exits when written to.
-// Crash causes a crash when written to.
+// Simple logging package. It defines a type, Logger, with simple
+// methods for formatting output to one or two destinations. It also
+// has a predefined 'standard' Logger accessible through helper
+// functions Print[f|ln], Exit[f|ln], and Panic[f|ln], which are
+// easier to use than creating a Logger manually. That logger writes
+// to standard error and prints the date and time of each logged
+// message.
+// The Exit functions call os.Exit(1) after writing the log message.
+// The Panic functions call panic after writing the log message.
package log
import (
"time"
)
-// These flags define the properties of the Logger and the output they produce.
+// These flags define the output Loggers produce.
const (
- // Flags
- Lok = iota
- Lexit // terminate execution when written
- Lcrash // crash (panic) when written
// Bits or'ed together to control what's printed. There is no control over the
// order they appear (the order listed here) or the format they present (as
// described in the comments). A colon appears after these items:
Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime.
Llongfile // full file name and line number: /a/b/c/d.go:23
Lshortfile // final file name element and line number: d.go:23. overrides Llongfile
- lAllBits = Ldate | Ltime | Lmicroseconds | Llongfile | Lshortfile
+ lallBits = Ldate | Ltime | Lmicroseconds | Llongfile | Lshortfile
)
// Logger represents an active logging object.
type Logger struct {
- out0 io.Writer // first destination for output
- out1 io.Writer // second destination for output; may be nil
+ out io.Writer // destination for output
prefix string // prefix to write at beginning of each line
flag int // properties
}
-// New creates a new Logger. The out0 and out1 variables set the
-// destinations to which log data will be written; out1 may be nil.
+// New creates a new Logger. The out variable sets the
+// destination to which log data will be written.
// The prefix appears at the beginning of each generated log line.
// The flag argument defines the logging properties.
-func New(out0, out1 io.Writer, prefix string, flag int) *Logger {
- return &Logger{out0, out1, prefix, flag}
+func New(out io.Writer, prefix string, flag int) *Logger {
+ return &Logger{out, prefix, flag}
}
var (
- stdout = New(os.Stdout, nil, "", Lok|Ldate|Ltime)
- stderr = New(os.Stderr, nil, "", Lok|Ldate|Ltime)
- exit = New(os.Stderr, nil, "", Lexit|Ldate|Ltime)
- crash = New(os.Stderr, nil, "", Lcrash|Ldate|Ltime)
+ std = New(os.Stderr, "", Ldate|Ltime)
+ stdout = New(os.Stdout, "", Ldate|Ltime) // Deprecated.
)
-var shortnames = make(map[string]string) // cache of short names to avoid allocation.
-
// Cheap integer to fixed-width decimal ASCII. Use a negative width to avoid zero-padding
func itoa(i int, wid int) string {
var u uint = uint(i)
_, file, line, ok := runtime.Caller(calldepth)
if ok {
if l.flag&Lshortfile != 0 {
- short, ok := shortnames[file]
- if !ok {
- short = file
- for i := len(file) - 1; i > 0; i-- {
- if file[i] == '/' {
- short = file[i+1:]
- break
- }
+ short := file
+ for i := len(file) - 1; i > 0; i-- {
+ if file[i] == '/' {
+ short = file[i+1:]
+ break
}
- shortnames[file] = short
}
file = short
}
newline = ""
}
s = l.formatHeader(now, calldepth+1) + s + newline
- _, err := io.WriteString(l.out0, s)
- if l.out1 != nil {
- _, err1 := io.WriteString(l.out1, s)
- if err == nil && err1 != nil {
- err = err1
- }
- }
- switch l.flag & ^lAllBits {
- case Lcrash:
- panic("log: fatal error")
- case Lexit:
- os.Exit(1)
- }
+ _, err := io.WriteString(l.out, s)
return err
}
+// Printf prints to the logger in the manner of fmt.Printf.
+func (l *Logger) Printf(format string, v ...interface{}) {
+ l.Output(2, fmt.Sprintf(format, v...))
+}
+
+// Print prints to the logger in the manner of fmt.Print.
+func (l *Logger) Print(v ...interface{}) { l.Output(2, fmt.Sprint(v...)) }
+
+// Println prints to the logger in the manner of fmt.Println.
+func (l *Logger) Println(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }
+
+// SetOutput sets the output destination for the standard logger.
+func SetOutput(w io.Writer) {
+ std.out = w
+}
+
+// SetFlags sets the output flags for the standard logger.
+func SetFlags(flag int) {
+ std.flag = flag & lallBits
+}
+
+// SetPrefix sets the output prefix for the standard logger.
+func SetPrefix(prefix string) {
+ std.prefix = prefix
+}
+
+// These functions write to the standard logger.
+
+// Print prints to the standard logger in the manner of fmt.Print.
+func Print(v ...interface{}) {
+ std.Output(2, fmt.Sprint(v...))
+}
+
+// Printf prints to the standard logger in the manner of fmt.Printf.
+func Printf(format string, v ...interface{}) {
+ std.Output(2, fmt.Sprintf(format, v...))
+}
+
+// Println prints to the standard logger in the manner of fmt.Println.
+func Println(v ...interface{}) {
+ std.Output(2, fmt.Sprintln(v...))
+}
+
+// Exit is equivalent to Print() followed by a call to os.Exit(1).
+func Exit(v ...interface{}) {
+ std.Output(2, fmt.Sprint(v...))
+ os.Exit(1)
+}
+
+// Exitf is equivalent to Printf() followed by a call to os.Exit(1).
+func Exitf(format string, v ...interface{}) {
+ std.Output(2, fmt.Sprintf(format, v...))
+ os.Exit(1)
+}
+
+// Exitln is equivalent to Println() followed by a call to os.Exit(1).
+func Exitln(v ...interface{}) {
+ std.Output(2, fmt.Sprintln(v...))
+ os.Exit(1)
+}
+
+// Panic is equivalent to Print() followed by a call to panic().
+func Panic(v ...interface{}) {
+ s := fmt.Sprint(v...)
+ std.Output(2, s)
+ panic(s)
+}
+
+// Panicf is equivalent to Printf() followed by a call to panic().
+func Panicf(format string, v ...interface{}) {
+ s := fmt.Sprintf(format, v...)
+ std.Output(2, s)
+ panic(s)
+}
+
+// Panicln is equivalent to Println() followed by a call to panic().
+func Panicln(v ...interface{}) {
+ s := fmt.Sprintln(v...)
+ std.Output(2, s)
+ panic(s)
+}
+
+// Everything from here on is deprecated and will be removed after the next release.
+
// Logf is analogous to Printf() for a Logger.
+// Deprecated.
func (l *Logger) Logf(format string, v ...interface{}) {
l.Output(2, fmt.Sprintf(format, v...))
}
// Log is analogous to Print() for a Logger.
+// Deprecated.
func (l *Logger) Log(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }
// Stdout is a helper function for easy logging to stdout. It is analogous to Print().
+// Deprecated.
func Stdout(v ...interface{}) { stdout.Output(2, fmt.Sprint(v...)) }
// Stderr is a helper function for easy logging to stderr. It is analogous to Fprint(os.Stderr).
-func Stderr(v ...interface{}) { stderr.Output(2, fmt.Sprintln(v...)) }
+// Deprecated.
+func Stderr(v ...interface{}) { std.Output(2, fmt.Sprintln(v...)) }
// Stdoutf is a helper functions for easy formatted logging to stdout. It is analogous to Printf().
+// Deprecated.
func Stdoutf(format string, v ...interface{}) { stdout.Output(2, fmt.Sprintf(format, v...)) }
// Stderrf is a helper function for easy formatted logging to stderr. It is analogous to Fprintf(os.Stderr).
-func Stderrf(format string, v ...interface{}) { stderr.Output(2, fmt.Sprintf(format, v...)) }
-
-// Exit is equivalent to Stderr() followed by a call to os.Exit(1).
-func Exit(v ...interface{}) { exit.Output(2, fmt.Sprintln(v...)) }
-
-// Exitf is equivalent to Stderrf() followed by a call to os.Exit(1).
-func Exitf(format string, v ...interface{}) { exit.Output(2, fmt.Sprintf(format, v...)) }
+// Deprecated.
+func Stderrf(format string, v ...interface{}) { std.Output(2, fmt.Sprintf(format, v...)) }
// Crash is equivalent to Stderr() followed by a call to panic().
-func Crash(v ...interface{}) { crash.Output(2, fmt.Sprintln(v...)) }
+// Deprecated.
+func Crash(v ...interface{}) { Panicln(v...) }
// Crashf is equivalent to Stderrf() followed by a call to panic().
-func Crashf(format string, v ...interface{}) { crash.Output(2, fmt.Sprintf(format, v...)) }
+// Deprecated.
+func Crashf(format string, v ...interface{}) { Panicf(format, v...) }
// These tests are too simple.
import (
- "bufio"
- "os"
+ "bytes"
"regexp"
"testing"
)
Rdate = `[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]`
Rtime = `[0-9][0-9]:[0-9][0-9]:[0-9][0-9]`
Rmicroseconds = `\.[0-9][0-9][0-9][0-9][0-9][0-9]`
- Rline = `(58|60):` // must update if the calls to l.Logf / l.Log below move
+ Rline = `(53|55):` // must update if the calls to l.Printf / l.Print below move
Rlongfile = `.*/[A-Za-z0-9_\-]+\.go:` + Rline
Rshortfile = `[A-Za-z0-9_\-]+\.go:` + Rline
)
// individual pieces:
tester{0, "", ""},
tester{0, "XXX", "XXX"},
- tester{Lok | Ldate, "", Rdate + " "},
- tester{Lok | Ltime, "", Rtime + " "},
- tester{Lok | Ltime | Lmicroseconds, "", Rtime + Rmicroseconds + " "},
- tester{Lok | Lmicroseconds, "", Rtime + Rmicroseconds + " "}, // microsec implies time
- tester{Lok | Llongfile, "", Rlongfile + " "},
- tester{Lok | Lshortfile, "", Rshortfile + " "},
- tester{Lok | Llongfile | Lshortfile, "", Rshortfile + " "}, // shortfile overrides longfile
+ tester{Ldate, "", Rdate + " "},
+ tester{Ltime, "", Rtime + " "},
+ tester{Ltime | Lmicroseconds, "", Rtime + Rmicroseconds + " "},
+ tester{Lmicroseconds, "", Rtime + Rmicroseconds + " "}, // microsec implies time
+ tester{Llongfile, "", Rlongfile + " "},
+ tester{Lshortfile, "", Rshortfile + " "},
+ tester{Llongfile | Lshortfile, "", Rshortfile + " "}, // shortfile overrides longfile
// everything at once:
- tester{Lok | Ldate | Ltime | Lmicroseconds | Llongfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rlongfile + " "},
- tester{Lok | Ldate | Ltime | Lmicroseconds | Lshortfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rshortfile + " "},
+ tester{Ldate | Ltime | Lmicroseconds | Llongfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rlongfile + " "},
+ tester{Ldate | Ltime | Lmicroseconds | Lshortfile, "XXX", "XXX" + Rdate + " " + Rtime + Rmicroseconds + " " + Rshortfile + " "},
}
-// Test using Log("hello", 23, "world") or using Logf("hello %d world", 23)
-func testLog(t *testing.T, flag int, prefix string, pattern string, useLogf bool) {
- r, w, err1 := os.Pipe()
- if err1 != nil {
- t.Fatal("pipe", err1)
- }
- defer r.Close()
- defer w.Close()
- buf := bufio.NewReader(r)
- l := New(w, nil, prefix, flag)
- if useLogf {
- l.Logf("hello %d world", 23)
+// Test using Println("hello", 23, "world") or using Printf("hello %d world", 23)
+func testPrint(t *testing.T, flag int, prefix string, pattern string, useFormat bool) {
+ buf := new(bytes.Buffer)
+ SetOutput(buf)
+ SetFlags(flag)
+ SetPrefix(prefix)
+ if useFormat {
+ Printf("hello %d world", 23)
} else {
- l.Log("hello", 23, "world")
- }
- line, err3 := buf.ReadString('\n')
- if err3 != nil {
- t.Fatal("log error", err3)
+ Println("hello", 23, "world")
}
+ line := buf.String()
line = line[0 : len(line)-1]
pattern = "^" + pattern + "hello 23 world$"
matched, err4 := regexp.MatchString(pattern, line)
}
}
-func TestAllLog(t *testing.T) {
+func TestAll(t *testing.T) {
for _, testcase := range tests {
- testLog(t, testcase.flag, testcase.prefix, testcase.pattern, false)
- testLog(t, testcase.flag, testcase.prefix, testcase.pattern, true)
+ testPrint(t, testcase.flag, testcase.prefix, testcase.pattern, false)
+ testPrint(t, testcase.flag, testcase.prefix, testcase.pattern, true)
}
}
// expLog is a logging convenience function. The first argument must be a string.
func expLog(args ...interface{}) {
args[0] = "netchan export: " + args[0].(string)
- log.Stderr(args...)
+ log.Print(args...)
}
// An Exporter allows a set of channels to be published on a single
// impLog is a logging convenience function. The first argument must be a string.
func impLog(args ...interface{}) {
args[0] = "netchan import: " + args[0].(string)
- log.Stderr(args...)
+ log.Print(args...)
}
// An Importer allows a set of channels to be imported from a single
}
client.mutex.Unlock()
if err != os.EOF || !client.closing {
- log.Stderr("rpc: client protocol error:", err)
+ log.Println("rpc: client protocol error:", err)
}
}
// RPCs that will be using that channel. If the channel
// is totally unbuffered, it's best not to run at all.
if cap(done) == 0 {
- log.Crash("rpc: done channel is unbuffered")
+ log.Panic("rpc: done channel is unbuffered")
}
}
c.Done = done
}
if s.typ.PkgPath() != "" && !isPublic(sname) {
s := "rpc Register: type " + sname + " is not public"
- log.Stderr(s)
+ log.Print(s)
return os.ErrorString(s)
}
if _, present := server.serviceMap[sname]; present {
}
// Method needs three ins: receiver, *args, *reply.
if mtype.NumIn() != 3 {
- log.Stderr("method", mname, "has wrong number of ins:", mtype.NumIn())
+ log.Println("method", mname, "has wrong number of ins:", mtype.NumIn())
continue
}
argType, ok := mtype.In(1).(*reflect.PtrType)
if !ok {
- log.Stderr(mname, "arg type not a pointer:", mtype.In(1))
+ log.Println(mname, "arg type not a pointer:", mtype.In(1))
continue
}
replyType, ok := mtype.In(2).(*reflect.PtrType)
if !ok {
- log.Stderr(mname, "reply type not a pointer:", mtype.In(2))
+ log.Println(mname, "reply type not a pointer:", mtype.In(2))
continue
}
if argType.Elem().PkgPath() != "" && !isPublic(argType.Elem().Name()) {
- log.Stderr(mname, "argument type not public:", argType)
+ log.Println(mname, "argument type not public:", argType)
continue
}
if replyType.Elem().PkgPath() != "" && !isPublic(replyType.Elem().Name()) {
- log.Stderr(mname, "reply type not public:", replyType)
+ log.Println(mname, "reply type not public:", replyType)
continue
}
if mtype.NumIn() == 4 {
t := mtype.In(3)
if t != reflect.Typeof((*ClientInfo)(nil)) {
- log.Stderr(mname, "last argument not *ClientInfo")
+ log.Println(mname, "last argument not *ClientInfo")
continue
}
}
// Method needs one out: os.Error.
if mtype.NumOut() != 1 {
- log.Stderr("method", mname, "has wrong number of outs:", mtype.NumOut())
+ log.Println("method", mname, "has wrong number of outs:", mtype.NumOut())
continue
}
if returnType := mtype.Out(0); returnType != typeOfOsError {
- log.Stderr("method", mname, "returns", returnType.String(), "not os.Error")
+ log.Println("method", mname, "returns", returnType.String(), "not os.Error")
continue
}
s.method[mname] = &methodType{method: method, argType: argType, replyType: replyType}
if len(s.method) == 0 {
s := "rpc Register: type " + sname + " has no public methods of suitable type"
- log.Stderr(s)
+ log.Print(s)
return os.ErrorString(s)
}
server.serviceMap[s.name] = s
sending.Lock()
err := codec.WriteResponse(resp, reply)
if err != nil {
- log.Stderr("rpc: writing response: ", err)
+ log.Println("rpc: writing response:", err)
}
sending.Unlock()
}
if err != nil {
if err == os.EOF || err == io.ErrUnexpectedEOF {
if err == io.ErrUnexpectedEOF {
- log.Stderr("rpc: ", err)
+ log.Println("rpc:", err)
}
break
}
replyv := _new(mtype.replyType)
err = codec.ReadRequestBody(argv.Interface())
if err != nil {
- log.Stderr("rpc: tearing down", serviceMethod[0], "connection:", err)
+ log.Println("rpc: tearing down", serviceMethod[0], "connection:", err)
sendResponse(sending, req, replyv.Interface(), codec, err.String())
break
}
}
conn, _, err := w.Hijack()
if err != nil {
- log.Stderr("rpc hijacking ", w.RemoteAddr(), ": ", err.String())
+ log.Print("rpc hijacking ", w.RemoteAddr(), ": ", err.String())
return
}
io.WriteString(conn, "HTTP/1.0 "+connected+"\n\n")
log.Exitf("net.Listen tcp :0: %v", e)
}
serverAddr = l.Addr().String()
- log.Stderr("Test RPC server listening on ", serverAddr)
+ log.Println("Test RPC server listening on", serverAddr)
go Accept(l)
HandleHTTP()
l, e = net.Listen("tcp", "127.0.0.1:0") // any available address
if e != nil {
- log.Stderrf("net.Listen tcp :0: %v", e)
+ log.Printf("net.Listen tcp :0: %v", e)
os.Exit(1)
}
httpServerAddr = l.Addr().String()
- log.Stderr("Test HTTP RPC server listening on ", httpServerAddr)
+ log.Println("Test HTTP RPC server listening on", httpServerAddr)
go http.Serve(l, nil)
}
if err != nil {
return nil
}
- return log.New(s, nil, "", flag)
+ return log.New(s, "", flag)
}
func (l *writeLogger) Write(p []byte) (n int, err os.Error) {
n, err = l.w.Write(p)
if err != nil {
- log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err)
+ log.Printf("%s %x: %v", l.prefix, p[0:n], err)
} else {
- log.Stdoutf("%s %x", l.prefix, p[0:n])
+ log.Printf("%s %x", l.prefix, p[0:n])
}
return
}
// NewWriteLogger returns a writer that behaves like w except
-// that it logs (using log.Stdout) each write to standard output,
+// that it logs (using log.Printf) each write to standard error,
// printing the prefix and the hexadecimal data written.
func NewWriteLogger(prefix string, w io.Writer) io.Writer {
return &writeLogger{prefix, w}
func (l *readLogger) Read(p []byte) (n int, err os.Error) {
n, err = l.r.Read(p)
if err != nil {
- log.Stdoutf("%s %x: %v", l.prefix, p[0:n], err)
+ log.Printf("%s %x: %v", l.prefix, p[0:n], err)
} else {
- log.Stdoutf("%s %x", l.prefix, p[0:n])
+ log.Printf("%s %x", l.prefix, p[0:n])
}
return
}
// NewReadLogger returns a reader that behaves like r except
-// that it logs (using log.Stdout) each read to standard output,
+// that it logs (using log.Print) each read to standard error,
// printing the prefix and the hexadecimal data written.
func NewReadLogger(prefix string, r io.Reader) io.Reader {
return &readLogger{prefix, r}
log.Exitf("net.Listen tcp :0 %v", e)
}
serverAddr = l.Addr().String()
- log.Stderr("Test WebSocket server listening on ", serverAddr)
+ log.Print("Test WebSocket server listening on ", serverAddr)
http.Handle("/echo", Handler(echoServer))
http.Handle("/echoDraft75", Draft75Handler(echoServer))
go http.Serve(l, nil)