本文整理汇总了Golang中minilog.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
logSetup()
log.Debug("using minimega: %v", *f_minimega)
// invoke minimega and get the doc json
doc, err := exec.Command(*f_minimega, "-cli").Output()
if err != nil {
log.Fatalln(err)
}
log.Debug("got doc: %v", string(doc))
// decode the JSON for our template
if err := json.Unmarshal(doc, &handlers); err != nil {
log.Fatalln(err)
}
exclude = strings.Split(*f_exclude, ",")
values = strings.Split(*f_values, ",")
for {
if err := fuzz(); err != nil {
log.Fatal("fuzz: %v", err)
}
if err := cleanup(); err != nil {
log.Fatal("cleanup: %v", err)
}
}
}
示例2: commandHandler
func commandHandler() {
for commands := range Client.commandChan {
var ids []int
for k, _ := range commands {
ids = append(ids, k)
}
sort.Ints(ids)
for _, id := range ids {
log.Debug("ron commandHandler: %v", id)
if id <= Client.CommandCounter {
continue
}
if !Client.Matches(commands[id].Filter) {
continue
}
log.Debug("ron commandHandler match: %v", id)
processCommand(commands[id])
}
}
log.Info("command handler exit")
}
示例3: cliPreprocess
// cliPreprocess performs expansion on a single string and returns the update
// string or an error.
func cliPreprocess(v string) (string, error) {
if u, err := url.Parse(v); err == nil {
switch u.Scheme {
case "file":
log.Debug("file preprocessor")
return iomHelper(u.Opaque)
case "http", "https":
log.Debug("http/s preprocessor")
// Check if we've already downloaded the file
v2, err := iomHelper(u.Path)
if err == nil {
return v2, err
}
if err.Error() == "file not found" {
log.Info("attempting to download %v", u)
// Try to download the file, save to files
dst := filepath.Join(*f_iomBase, u.Path)
if err := wget(v, dst); err != nil {
return "", err
}
return dst, nil
}
return "", err
}
}
return v, nil
}
示例4: fieldsQuoteEscape
// Return a slice of strings, split on whitespace, not unlike strings.Fields(),
// except that quoted fields are grouped.
// Example: a b "c d"
// will return: ["a", "b", "c d"]
func fieldsQuoteEscape(c string, input string) []string {
log.Debug("fieldsQuoteEscape splitting on %v: %v", c, input)
f := strings.Fields(input)
var ret []string
trace := false
temp := ""
for _, v := range f {
if trace {
if strings.Contains(v, c) {
trace = false
temp += " " + trimQuote(c, v)
ret = append(ret, temp)
} else {
temp += " " + v
}
} else if strings.Contains(v, c) {
temp = trimQuote(c, v)
if strings.HasSuffix(v, c) {
// special case, single word like 'foo'
ret = append(ret, temp)
} else {
trace = true
}
} else {
ret = append(ret, v)
}
}
log.Debug("generated: %#v", ret)
return ret
}
示例5: ConnectImage
// ConnectImage exports a image using the NBD protocol using the qemu-nbd. If
// successful, returns the NBD device.
func ConnectImage(image string) (string, error) {
var nbdPath string
var err error
for i := 0; i < maxConnectRetries; i++ {
nbdPath, err = GetDevice()
if err != ErrNoDeviceAvailable {
break
}
log.Debug("all nbds in use, sleeping before retrying")
time.Sleep(time.Second * 10)
}
if err != nil {
return "", err
}
// connect it to qemu-nbd
cmd := exec.Command(process("qemu-nbd"), "-c", nbdPath, image)
log.Debug("connecting to nbd with cmd: %v", cmd)
result, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("unable to connect to nbd: %v", string(result))
}
return nbdPath, nil
}
示例6: containerNukeWalker
func containerNukeWalker(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
log.Debug("walking file: %v", path)
switch info.Name() {
case "tasks":
d, err := ioutil.ReadFile(path)
if err != nil {
return nil
}
pids := strings.Fields(string(d))
for _, pid := range pids {
log.Debug("found pid: %v", pid)
fmt.Println("killing process:", pid)
processWrapper("kill", "-9", pid)
}
}
return nil
}
示例7: dnsClient
func dnsClient() {
rand.Seed(time.Now().UnixNano())
t := NewEventTicker(*f_mean, *f_stddev, *f_min, *f_max)
m := new(dns.Msg)
for {
t.Tick()
h, _ := randomHost()
d := randomDomain()
var t uint16
if *f_dnsv4 {
t = dns.TypeA
} else if *f_dnsv6 {
t = dns.TypeAAAA
} else {
t = randomQuestionType()
}
m.SetQuestion(dns.Fqdn(d), t)
log.Debug("dns client: question=%v", m.Question)
in, err := dns.Exchange(m, h+addr)
if err != nil {
log.Debug(err.Error())
} else {
log.Debug("dns client: answer=%v", in)
dnsReportChan <- 1
}
}
}
示例8: GetDevice
// GetDevice returns the first available NBD. If there are no devices
// available, returns ErrNoDeviceAvailable.
func GetDevice() (string, error) {
// Get a list of all devices
devFiles, err := ioutil.ReadDir("/dev")
if err != nil {
return "", err
}
nbdPath := ""
// Find the first available nbd
for _, devInfo := range devFiles {
dev := devInfo.Name()
// we don't want to include partitions here
if !strings.Contains(dev, "nbd") || strings.Contains(dev, "p") {
continue
}
// check whether a pid exists for the current nbd
_, err = os.Stat(filepath.Join("/sys/block", dev, "pid"))
if err != nil {
log.Debug("found available nbd: " + dev)
nbdPath = filepath.Join("/dev", dev)
break
} else {
log.Debug("nbd %v could not be used", dev)
}
}
if nbdPath == "" {
return "", ErrNoDeviceAvailable
}
return nbdPath, nil
}
示例9: iomCompleter
// a filename completer for goreadline that searches for the file: prefix,
// attempts to find matching files, and returns an array of candidates.
func iomCompleter(line string) []string {
f := strings.Fields(line)
if len(f) == 0 {
return nil
}
last := f[len(f)-1]
if strings.HasPrefix(last, IOM_HELPER_MATCH) {
fileprefix := strings.TrimPrefix(last, IOM_HELPER_MATCH)
matches := iom.Info(fileprefix + "*")
log.Debug("got raw matches: %v", matches)
// we need to clean up matches to collapse directories, unless
// there is a directory common prefix, in which case we
// collapse offset by the number of common directories.
dlcp := lcp(matches)
didx := strings.LastIndex(dlcp, string(filepath.Separator))
drel := ""
if didx > 0 {
drel = dlcp[:didx]
}
log.Debug("dlcp: %v, drel: %v", dlcp, drel)
if len(fileprefix) < len(drel) {
r := IOM_HELPER_MATCH + drel + string(filepath.Separator)
return []string{r, r + "0"} // hack to prevent readline from fastforwarding beyond the directory name
}
var finalMatches []string
for _, v := range matches {
if strings.Contains(v, "*") {
continue
}
r, err := filepath.Rel(drel, v)
if err != nil {
log.Errorln(err)
return nil
}
dir := filepath.Dir(r)
if dir == "." {
finalMatches = append(finalMatches, IOM_HELPER_MATCH+v)
continue
}
paths := strings.Split(dir, string(filepath.Separator))
found := false
for _, d := range finalMatches {
if d == paths[0]+string(filepath.Separator) {
found = true
break
}
}
if !found {
finalMatches = append(finalMatches, IOM_HELPER_MATCH+filepath.Join(drel, paths[0])+string(filepath.Separator))
}
}
return finalMatches
}
return nil
}
示例10: cmdTimeout
// cmdTimeout runs the command c and returns a timeout if it doesn't complete
// after time t. If a timeout occurs, cmdTimeout will kill the process.
func cmdTimeout(c *exec.Cmd, t time.Duration) error {
log.Debug("cmdTimeout: %v", c)
start := time.Now()
err := c.Start()
if err != nil {
return fmt.Errorf("cmd start: %v", err)
}
done := make(chan error)
go func() {
done <- c.Wait()
}()
select {
case <-time.After(t):
err = c.Process.Kill()
if err != nil {
return err
}
return <-done
case err = <-done:
log.Debug("cmd %v completed in %v", c, time.Now().Sub(start))
return err
}
}
示例11: vncClear
func vncClear() {
for k, v := range vncKBRecording {
if inNamespace(v.VM) {
log.Debug("stopping kb recording for %v", k)
if err := v.Stop(); err != nil {
log.Error("%v", err)
}
delete(vncKBRecording, k)
}
}
for k, v := range vncFBRecording {
if inNamespace(v.VM) {
log.Debug("stopping fb recording for %v", k)
if err := v.Stop(); err != nil {
log.Error("%v", err)
}
delete(vncFBRecording, k)
}
}
for k, v := range vncPlaying {
if inNamespace(v.VM) {
log.Debug("stopping kb playing for %v", k)
if err := v.Stop(); err != nil {
log.Error("%v", err)
}
delete(vncPlaying, k)
}
}
}
示例12: iomPreprocessor
// walk every arg looking for "file:" and calling iomHelper on the suffix.
// Replace the arg with the local file if found.
func iomPreprocessor(c *minicli.Command) (*minicli.Command, error) {
for k, v := range c.StringArgs {
if strings.HasPrefix(v, IOM_HELPER_MATCH) {
file := strings.TrimPrefix(v, IOM_HELPER_MATCH)
local, err := iomHelper(file)
if err != nil {
return nil, err
}
log.Debug("iomPreProcessor: %v -> %v", v, local)
c.StringArgs[k] = local
}
}
for k, v := range c.ListArgs {
for x, y := range v {
if strings.HasPrefix(y, IOM_HELPER_MATCH) {
file := strings.TrimPrefix(y, IOM_HELPER_MATCH)
local, err := iomHelper(file)
if err != nil {
return nil, err
}
log.Debug("iomPreProcessor: %v -> %v", y, local)
c.ListArgs[k][x] = local
}
}
}
return c, nil
}
示例13: deployRun
func deployRun(hosts []string, user, remotePath string, sudo bool) []error {
log.Debug("deployRun: %v, %v", hosts, user)
var errs []error
// minimega command
flags := deployGetFlags()
log.Debug("minimega flags: %v", flags)
var minimegaCommand string
if sudo {
minimegaCommand = fmt.Sprintf("sudo -b nohup %v %v > /dev/null 2>&1 &", remotePath, flags)
} else {
minimegaCommand = fmt.Sprintf("nohup %v %v > /dev/null 2>&1 &", remotePath, flags)
}
for _, host := range hosts {
command := []string{"ssh", "-o", "StrictHostKeyChecking=no"}
if user != "" {
command = append(command, fmt.Sprintf("%[email protected]%v", user, host))
} else {
command = append(command, fmt.Sprintf("%v", host))
}
command = append(command, minimegaCommand)
log.Debug("ssh command: %v", command)
out, err := processWrapper(command...)
if err != nil {
errs = append(errs, fmt.Errorf("%v: %v", err, out))
}
}
return errs
}
示例14: Trunk
// Trunk reads data from remote, constructs a *Message, and sends it using fn.
// Returns the first error.
func Trunk(remote net.Conn, uuid string, fn func(*Message) error) {
var n int
var err error
for err == nil {
buf := make([]byte, 32*1024)
n, err = remote.Read(buf)
log.Debug("trunking %v bytes for %v", n, uuid)
if err == nil {
m := &Message{
Type: MESSAGE_TUNNEL,
UUID: uuid,
Tunnel: buf[:n],
}
err = fn(m)
}
if err != nil && err != io.ErrClosedPipe {
log.Errorln(err)
}
}
if err != io.ErrClosedPipe {
log.Error("trunk failed for %v: %v", err)
}
log.Debug("trunk exit for %v", uuid)
}
示例15: handleMSA
func (n *Node) handleMSA(m *Message) {
log.Debug("handleMSA: %v", m)
n.meshLock.Lock()
defer n.meshLock.Unlock()
if len(n.network[m.Source]) == len(m.Body.([]string)) {
diff := false
for i, v := range n.network[m.Source] {
if m.Body.([]string)[i] != v {
diff = true
break
}
}
if !diff {
log.Debugln("MSA discarded, client data hasn't changed")
return
}
}
n.network[m.Source] = m.Body.([]string)
if log.WillLog(log.DEBUG) {
log.Debug("new network is: %v", n.network)
}
n.updateNetwork = true
}