use 'go.wit.com/log'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
25715e30ee
commit
3233c9d6ab
|
@ -0,0 +1,18 @@
|
||||||
|
package cloudflare
|
||||||
|
|
||||||
|
// initializes logging and command line options
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var INFO log.LogFlag
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
INFO.B = false
|
||||||
|
INFO.Name = "INFO"
|
||||||
|
INFO.Subsystem = "shell"
|
||||||
|
INFO.Short = "shell"
|
||||||
|
INFO.Desc = "general info"
|
||||||
|
INFO.Register()
|
||||||
|
}
|
40
shell.go
40
shell.go
|
@ -1,17 +1,17 @@
|
||||||
package shell
|
package shell
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
import "time"
|
"strings"
|
||||||
import "os"
|
"time"
|
||||||
import "os/exec"
|
"os"
|
||||||
import "bufio"
|
"os/exec"
|
||||||
import "io/ioutil"
|
"bufio"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
"go.wit.com/log"
|
||||||
import "github.com/svent/go-nbreader"
|
"github.com/svent/go-nbreader"
|
||||||
|
)
|
||||||
|
|
||||||
// import "log"
|
|
||||||
import log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
// TODO: look at https://github.com/go-cmd/cmd/issues/20
|
// TODO: look at https://github.com/go-cmd/cmd/issues/20
|
||||||
// use go-cmd instead here?
|
// use go-cmd instead here?
|
||||||
|
@ -29,7 +29,7 @@ var quiet bool = false
|
||||||
// var bytesSplice []byte
|
// var bytesSplice []byte
|
||||||
|
|
||||||
func handleError(c interface{}, ret int) {
|
func handleError(c interface{}, ret int) {
|
||||||
log.Debug("shell.Run() Returned", ret)
|
log.Log(INFO, "shell.Run() Returned", ret)
|
||||||
if (callback != nil) {
|
if (callback != nil) {
|
||||||
callback(c, ret)
|
callback(c, ret)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func Script(cmds string) int {
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = Chomp(line) // this is like 'chomp' in perl
|
line = Chomp(line) // this is like 'chomp' in perl
|
||||||
log.Println("LINE:", line)
|
log.Log(INFO, "LINE:", line)
|
||||||
time.Sleep(1)
|
time.Sleep(1)
|
||||||
Run(line)
|
Run(line)
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,8 @@ func RM(filename string) {
|
||||||
spew.Dump(process.ProcessState)
|
spew.Dump(process.ProcessState)
|
||||||
}
|
}
|
||||||
// stuff := err.(*exec.ExitError)
|
// stuff := err.(*exec.ExitError)
|
||||||
log.Debug("ERROR ", err.Error())
|
log.Log(INFO, "ERROR ", err.Error())
|
||||||
log.Debug("END ", cmdline)
|
log.Log(INFO, "END ", cmdline)
|
||||||
handleError(err, -1)
|
handleError(err, -1)
|
||||||
return ""
|
return ""
|
||||||
*/
|
*/
|
||||||
|
@ -123,7 +123,7 @@ func nonBlockingReader(buffReader *bufio.Reader, writeFileHandle *os.File, stdou
|
||||||
oneByte := make([]byte, 1024)
|
oneByte := make([]byte, 1024)
|
||||||
count, err := nbr.Read(oneByte)
|
count, err := nbr.Read(oneByte)
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Debug("count, err =", count, err)
|
log.Log(INFO, "count, err =", count, err)
|
||||||
handleError(err, -1)
|
handleError(err, -1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -131,11 +131,11 @@ func nonBlockingReader(buffReader *bufio.Reader, writeFileHandle *os.File, stdou
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
time.Sleep(time.Duration(msecDelay) * time.Millisecond) // without this delay this will peg the CPU
|
time.Sleep(time.Duration(msecDelay) * time.Millisecond) // without this delay this will peg the CPU
|
||||||
if (totalCount != 0) {
|
if (totalCount != 0) {
|
||||||
log.Debug("STDERR: totalCount = ", totalCount)
|
log.Log(INFO, "STDERR: totalCount = ", totalCount)
|
||||||
totalCount = 0
|
totalCount = 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Debug("STDERR: count = ", count)
|
log.Log(INFO, "STDERR: count = ", count)
|
||||||
writeFileHandle.Write(oneByte[0:count])
|
writeFileHandle.Write(oneByte[0:count])
|
||||||
if (quiet == false) {
|
if (quiet == false) {
|
||||||
stdout.Write(oneByte[0:count])
|
stdout.Write(oneByte[0:count])
|
||||||
|
@ -150,7 +150,7 @@ func nonBlockingReader(buffReader *bufio.Reader, writeFileHandle *os.File, stdou
|
||||||
// TODO: pass STDOUT, STDERR, STDIN correctly
|
// TODO: pass STDOUT, STDERR, STDIN correctly
|
||||||
// TODO: figure out how to nohup the process and exit
|
// TODO: figure out how to nohup the process and exit
|
||||||
func Exec(cmdline string) {
|
func Exec(cmdline string) {
|
||||||
log.Println("shell.Run() START " + cmdline)
|
log.Log(INFO, "shell.Run() START " + cmdline)
|
||||||
|
|
||||||
cmd := Chomp(cmdline) // this is like 'chomp' in perl
|
cmd := Chomp(cmdline) // this is like 'chomp' in perl
|
||||||
cmdArgs := strings.Fields(cmd)
|
cmdArgs := strings.Fields(cmd)
|
||||||
|
@ -161,7 +161,7 @@ func Exec(cmdline string) {
|
||||||
process.Stdout = os.Stdout
|
process.Stdout = os.Stdout
|
||||||
process.Start()
|
process.Start()
|
||||||
err := process.Wait()
|
err := process.Wait()
|
||||||
log.Println("shell.Exec() err =", err)
|
log.Log(INFO, "shell.Exec() err =", err)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ func Dir(dirname string) bool {
|
||||||
// Cat a file into a string
|
// Cat a file into a string
|
||||||
func Cat(filename string) string {
|
func Cat(filename string) string {
|
||||||
buffer, err := ioutil.ReadFile(Path(filename))
|
buffer, err := ioutil.ReadFile(Path(filename))
|
||||||
// log.Println("buffer =", string(buffer))
|
// log.Log(INFO, "buffer =", string(buffer))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue