mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
Improve debug logging in golang
This commit is contained in:
parent
5353e9e90f
commit
08e005d45f
3 changed files with 10 additions and 9 deletions
8
main.go
8
main.go
|
@ -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
3
os.go
|
@ -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 {
|
||||
|
|
8
util.go
8
util.go
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue