-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
421 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ import ( | |
"net/http" | ||
"os" | ||
"os/exec" | ||
"runtime/debug" | ||
"runtime" | ||
"runtime/debug" | ||
"strings" | ||
"time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,102 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
"github.com/xhd2015/xgo/support/osinfo" | ||
) | ||
|
||
var logDebugFile *os.File | ||
|
||
func setupDebugLog(logDebugOption *string) (func(), error) { | ||
var logDebugFileName string | ||
if logDebugOption != nil { | ||
logDebugFileName = *logDebugOption | ||
if logDebugFileName == "" { | ||
logDebugFileName = "debug.log" | ||
} | ||
} | ||
if logDebugFileName == "" { | ||
return nil, nil | ||
} | ||
return initLog(logDebugFileName) | ||
} | ||
|
||
func initLog(logDebugFileName string) (func(), error) { | ||
if logDebugFileName == "stdout" { | ||
logDebugFile = os.Stdout | ||
return nil, nil | ||
} | ||
if logDebugFileName == "stderr" { | ||
logDebugFile = os.Stderr | ||
return nil, nil | ||
} | ||
var err error | ||
logDebugFile, err = os.Create(logDebugFileName) | ||
if err != nil { | ||
return nil, fmt.Errorf("create log: %s %w", logDebugFileName, err) | ||
} | ||
return func() { | ||
logDebugFile.Close() | ||
}, nil | ||
} | ||
|
||
func logDebug(format string, args ...interface{}) { | ||
if logDebugFile == nil { | ||
return | ||
} | ||
fmt.Fprint(logDebugFile, time.Now().Format("2006-01-02 15:04:05"), " ") | ||
fmt.Fprintf(logDebugFile, format, args...) | ||
if !strings.HasSuffix(format, "\n") { | ||
fmt.Fprintln(logDebugFile) | ||
} | ||
logDebugFile.Sync() | ||
} | ||
|
||
func logStartup() { | ||
logDebug("start: %v", os.Args) | ||
logDebug("runtime.GOOS=%s", runtime.GOOS) | ||
logDebug("runtime.GOARCH=%s", runtime.GOARCH) | ||
logDebug("runtime.Version()=%s", runtime.Version()) | ||
logDebug("runtime.GOROOT()=%s", runtime.GOROOT()) | ||
logDebug("os exe suffix: %s", osinfo.EXE_SUFFIX) | ||
logDebug("os force copy unsym: %v", osinfo.FORCE_COPY_UNSYM) | ||
} | ||
|
||
// if [[ $verbose = true ]];then | ||
// | ||
// tail -fn1 "$shdir/compile.log" & | ||
// trap "kill -9 $!" EXIT | ||
// fi | ||
func tailLog(logFile string) { | ||
file, err := os.OpenFile(logFile, os.O_RDONLY|os.O_CREATE, 0755) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "open compile log: %v\n", err) | ||
return | ||
} | ||
_, err = file.Seek(0, io.SeekEnd) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "seek tail compile log: %v\n", err) | ||
return | ||
} | ||
buf := make([]byte, 1024) | ||
for { | ||
n, err := file.Read(buf) | ||
if n > 0 { | ||
os.Stdout.Write(buf[:n]) | ||
} | ||
if err != nil { | ||
if err == io.EOF { | ||
time.Sleep(50 * time.Millisecond) | ||
continue | ||
} | ||
fmt.Fprintf(os.Stderr, "tail compile log: %v\n", err) | ||
return | ||
} | ||
} | ||
} | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"runtime" | ||
"strings" | ||
"time" | ||
|
||
"github.com/xhd2015/xgo/support/osinfo" | ||
) | ||
|
||
var logDebugFile *os.File | ||
|
||
func setupDebugLog(logDebugOption *string) (func(), error) { | ||
var logDebugFileName string | ||
if logDebugOption != nil { | ||
logDebugFileName = *logDebugOption | ||
if logDebugFileName == "" { | ||
logDebugFileName = "debug.log" | ||
} | ||
} | ||
if logDebugFileName == "" { | ||
return nil, nil | ||
} | ||
return initLog(logDebugFileName) | ||
} | ||
|
||
func initLog(logDebugFileName string) (func(), error) { | ||
if logDebugFileName == "stdout" { | ||
logDebugFile = os.Stdout | ||
return nil, nil | ||
} | ||
if logDebugFileName == "stderr" { | ||
logDebugFile = os.Stderr | ||
return nil, nil | ||
} | ||
var err error | ||
logDebugFile, err = os.Create(logDebugFileName) | ||
if err != nil { | ||
return nil, fmt.Errorf("create log: %s %w", logDebugFileName, err) | ||
} | ||
return func() { | ||
logDebugFile.Close() | ||
}, nil | ||
} | ||
|
||
func logDebug(format string, args ...interface{}) { | ||
if logDebugFile == nil { | ||
return | ||
} | ||
fmt.Fprint(logDebugFile, time.Now().Format("2006-01-02 15:04:05"), " ") | ||
fmt.Fprintf(logDebugFile, format, args...) | ||
if !strings.HasSuffix(format, "\n") { | ||
fmt.Fprintln(logDebugFile) | ||
} | ||
logDebugFile.Sync() | ||
} | ||
|
||
func logStartup() { | ||
logDebug("start: %v", os.Args) | ||
logDebug("runtime.GOOS=%s", runtime.GOOS) | ||
logDebug("runtime.GOARCH=%s", runtime.GOARCH) | ||
logDebug("runtime.Version()=%s", runtime.Version()) | ||
logDebug("runtime.GOROOT()=%s", runtime.GOROOT()) | ||
logDebug("os exe suffix: %s", osinfo.EXE_SUFFIX) | ||
logDebug("os force copy unsym: %v", osinfo.FORCE_COPY_UNSYM) | ||
} | ||
|
||
// if [[ $verbose = true ]];then | ||
// | ||
// tail -fn1 "$shdir/compile.log" & | ||
// trap "kill -9 $!" EXIT | ||
// fi | ||
func tailLog(logFile string) { | ||
file, err := os.OpenFile(logFile, os.O_RDONLY|os.O_CREATE, 0755) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "open compile log: %v\n", err) | ||
return | ||
} | ||
_, err = file.Seek(0, io.SeekEnd) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "seek tail compile log: %v\n", err) | ||
return | ||
} | ||
buf := make([]byte, 1024) | ||
for { | ||
n, err := file.Read(buf) | ||
if n > 0 { | ||
os.Stdout.Write(buf[:n]) | ||
} | ||
if err != nil { | ||
if err == io.EOF { | ||
time.Sleep(50 * time.Millisecond) | ||
continue | ||
} | ||
fmt.Fprintf(os.Stderr, "tail compile log: %v\n", err) | ||
return | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package osinfo | ||
|
||
const EXE_SUFFIX = "" | ||
|
||
// when copy files, should use | ||
// symbolic as long as possible | ||
const FORCE_COPY_UNSYM = false | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package osinfo | ||
|
||
const EXE_SUFFIX = "" | ||
|
||
// when copy files, should use | ||
// symbolic as long as possible | ||
const FORCE_COPY_UNSYM = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package osinfo | ||
|
||
const EXE_SUFFIX = ".exe" | ||
|
||
// when copy files, don't use | ||
// symbolic as it may cause failure | ||
const FORCE_COPY_UNSYM = true | ||
//go:build windows | ||
// +build windows | ||
|
||
package osinfo | ||
|
||
const EXE_SUFFIX = ".exe" | ||
|
||
// when copy files, don't use | ||
// symbolic as it may cause failure | ||
const FORCE_COPY_UNSYM = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.