1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Improve debug logging in golang

This commit is contained in:
Ryan Dahl 2018-05-25 12:25:55 -04:00
parent 5353e9e90f
commit 08e005d45f
3 changed files with 10 additions and 9 deletions

View file

@ -3,8 +3,6 @@ package main
import (
"flag"
"github.com/ry/v8worker2"
"io/ioutil"
"log"
"os"
"runtime/pprof"
)
@ -28,10 +26,6 @@ func FlagsParse() []string {
}
args = v8worker2.SetFlags(args)
// Unless the debug flag is specified, discard logs.
if !*flagDebug {
log.SetOutput(ioutil.Discard)
}
return args
}
@ -43,7 +37,7 @@ func main() {
if *flagGoProf != "" {
f, err := os.Create(*flagGoProf)
if err != nil {
log.Fatal(err)
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()

3
os.go
View file

@ -3,7 +3,6 @@ package main
import (
"github.com/golang/protobuf/proto"
"io/ioutil"
"log"
"net/url"
"os"
"path"
@ -37,7 +36,7 @@ func InitOS() {
func ResolveModule(moduleSpecifier string, containingFile string) (
moduleName string, filename string, err error) {
log.Printf("ResolveModule %s %s", moduleSpecifier, containingFile)
logDebug("ResolveModule %s %s", moduleSpecifier, containingFile)
moduleUrl, err := url.Parse(moduleSpecifier)
if err != nil {

View file

@ -1,10 +1,18 @@
package main
import (
"fmt"
"net/url"
"os"
)
func logDebug(format string, v ...interface{}) {
// Unless the debug flag is specified, discard logs.
if *flagDebug {
fmt.Printf(format+"\n", v)
}
}
func assert(cond bool, msg string) {
if !cond {
panic(msg)