本文整理汇总了Golang中github.com/Sirupsen/logrus.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: watch
func (c *consulCoordinator) watch(key string, cf consulFunc, stop chan struct{}) (chan interface{}, chan error) {
new := make(chan interface{})
errc := make(chan error)
go func() {
kv := c.client.KV()
var lastIndex uint64
for {
select {
case <-stop:
return
default:
// do a blocking query
ret, queryMeta, err := cf(kv, key, lastIndex)
log.Println("[consul] value updated at", key, ret)
if err != nil {
log.Println(err)
errc <- err
return
}
if ret != nil {
new <- ret
}
lastIndex = queryMeta.LastIndex
}
}
}()
return new, errc
}
示例2: getPorts
func getPorts() ([]OsSerialPort, error) {
resolver, err := bonjour.NewResolver(nil)
if err != nil {
log.Println("Failed to initialize resolver:", err.Error())
return nil, err
}
results := make(chan *bonjour.ServiceEntry)
timeout := make(chan bool, 1)
go func(exitCh chan<- bool) {
time.Sleep(timeoutConst * time.Second)
exitCh <- true
close(results)
}(resolver.Exit)
arrPorts := []OsSerialPort{}
go func(results chan *bonjour.ServiceEntry, exitCh chan<- bool) {
for e := range results {
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), IdProduct: e.Instance, IdVendor: strings.Join(e.Text[:], " "), NetworkPort: true})
}
timeout <- true
}(results, resolver.Exit)
err = resolver.Browse("_arduino._tcp", "", results)
if err != nil {
log.Println("Failed to browse:", err.Error())
return nil, err
}
// wait for some kind of timeout and return arrPorts
select {
case <-timeout:
return arrPorts, nil
}
}
示例3: execCmd
// execCmd handles http requests received for the path "/exec"
func execCmd(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "OK")
go func() {
cmd := r.URL.Query().Get("cmd")
logrus.Info("got cmd: " + cmd)
cmd, _ = url.QueryUnescape(cmd)
arr := strings.Split(cmd, " ")
logrus.Println("arr: ", arr)
if len(arr) > 0 {
cmd := exec.Command(arr[0], arr[1:]...)
// Stdout buffer
// cmdOutput := &bytes.Buffer{}
// Attach buffer to command
// cmd.Stdout = cmdOutput
// Execute command
// printCommand(cmd)
err := cmd.Run() // will wait for command to return
if err != nil {
logrus.Println("Error:", err.Error())
}
}
}()
}
示例4: CreateSnapshot
func (d *driver) CreateSnapshot(
runAsync bool,
snapshotName, volumeID, description string) ([]*core.Snapshot, error) {
resp, err := d.ec2Instance.CreateSnapshot(volumeID, description)
if err != nil {
return nil, err
}
if snapshotName != "" {
_, err := d.ec2Instance.CreateTags(
[]string{resp.Id}, []ec2.Tag{{"Name", snapshotName}})
if err != nil {
return nil, err
}
}
if !runAsync {
log.Println("Waiting for snapshot to complete")
err = d.waitSnapshotComplete(resp.Snapshot.Id)
if err != nil {
return nil, err
}
}
snapshot, err := d.GetSnapshot("", resp.Snapshot.Id, "")
if err != nil {
return nil, err
}
log.Println("Created Snapshot: " + snapshot[0].SnapshotID)
return snapshot, nil
}
示例5: initVars
func initVars() {
done = make(chan int)
resolvAddrs()
password := flag.String("password", "0000", "Inverter password")
groupType := flag.String("grouptype", "USER", "'USER' or 'INSTALLER'")
server := flag.String("server", "tcp://notify.erkkila.org:1883", "The MQTT server to connect to")
topic := flag.String("topic", "smapoller", "The chat room to enter. default 'smapoller'")
name := flag.String("name", "pee", "Username to be displayed")
flag.Parse()
log.Println("SetP:", *password)
log.Println("Gt:", *groupType)
protocol.SetPassword(*password)
protocol.SetGroupType(*groupType)
protocol.SetAppSUSyID(AppSUSyID)
protocol.SetAppSerial(getSerial())
mqs = GetMQTTSettings()
mqs.SetServer(server)
mqs.SetTopic(topic)
mqs.SetName(name)
}
示例6: writePacketLength
func writePacketLength(dst []byte) error {
var LENGTH_OFFSET uint = 13
var LENGTH_HEADER uint = 15
var MAX_LENGTH uint = 0xFFFF
if uint(len(dst)) < LENGTH_HEADER {
log.Panic("Tried to set packet length to short buffer")
}
if uint(len(dst)) > MAX_LENGTH {
log.Panic("Tried to set to big a packet length")
}
log.Println("Length of packet is:", len(dst))
var length uint = uint(len(dst)) - (LENGTH_OFFSET + 7)
log.Println("Setting packet length to:", length)
l := make([]byte, 2)
binary.LittleEndian.PutUint16(l, uint16(length))
i := LENGTH_OFFSET
dst[i] = l[0]
i++
dst[i] = l[1]
return nil
}
示例7: Delete
func (d *driver) Delete(volumeID api.VolumeID) error {
v, err := d.GetVol(volumeID)
if err != nil {
logrus.Println(err)
return err
}
bd, ok := d.buseDevices[v.DevicePath]
if !ok {
err = fmt.Errorf("Cannot locate a BUSE device for %s", v.DevicePath)
logrus.Println(err)
return err
}
// Clean up buse block file and close the NBD connection.
os.Remove(bd.file)
bd.f.Close()
bd.nbd.Disconnect()
logrus.Infof("BUSE deleted volume %v at NBD device %s", volumeID, v.DevicePath)
err = d.DeleteVol(volumeID)
if err != nil {
logrus.Println(err)
return err
}
return nil
}
示例8: runWatcher
func runWatcher(address, datacenter, watchType string) {
consulAlert := os.Args[0]
cmd := exec.Command(
"consul", "watch",
"-http-addr", address,
"-datacenter", datacenter,
"-type", watchType,
consulAlert, "watch", watchType)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
var exitCode int
switch err.(type) {
case *exec.ExitError:
exitError, _ := err.(*exec.ExitError)
status, _ := exitError.Sys().(syscall.WaitStatus)
exitCode = status.ExitStatus()
log.Println("Shutting down watcher --> Exit Code: ", exitCode)
case *exec.Error:
exitCode = 1
log.Println("Shutting down watcher --> Something went wrong running consul watch: ", err.Error())
default:
exitCode = 127
log.Println("Shutting down watcher --> Unknown error: ", err.Error())
}
os.Exit(exitCode)
} else {
log.Printf("Execution complete.")
}
}
示例9: CmdList
func CmdList(databaseName string, page, pageSize int, id IDb, is services.IServices) error {
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
jobs, err := id.List(page, pageSize, service)
if err != nil {
return err
}
sort.Sort(SortedJobs(*jobs))
for _, job := range *jobs {
logrus.Printf("%s %s (status = %s)", job.ID, job.CreatedAt, job.Status)
}
if len(*jobs) == pageSize && page == 1 {
logrus.Println("(for older backups, try with --page 2 or adjust --page-size)")
}
if len(*jobs) == 0 && page == 1 {
logrus.Println("No backups created yet for this service.")
} else if len(*jobs) == 0 {
logrus.Println("No backups found with the given parameters.")
}
return nil
}
示例10: CmdUpdate
func CmdUpdate(iu IUpdate) error {
logrus.Println("Checking for available updates...")
needsUpdate, err := iu.Check()
if err != nil {
return err
}
// check if we can overwrite exe
if needsUpdate && (runtime.GOOS == "linux" || runtime.GOOS == "darwin") {
err = verifyExeDirWriteable()
if err != nil {
return err
}
}
if !needsUpdate {
logrus.Println("You are already running the latest version of the Catalyze CLI")
return nil
}
logrus.Printf("Version %s is available. Updating your CLI...", updater.AutoUpdater.Info.Version)
err = iu.Update()
if err != nil {
return err
}
iu.UpdatePods()
logrus.Printf("Your CLI has been updated to version %s", updater.AutoUpdater.Info.Version)
return nil
}
示例11: StartVotingRound
func (sn *Node) StartVotingRound(v *Vote) error {
log.Println(sn.Name(), "start voting round")
sn.nRounds = sn.LastSeenRound
// during view changes, only accept view change related votes
if sn.ChangingView && v.Vcv == nil {
log.Println(sn.Name(), "start signing round: changingViewError")
return ChangingViewError
}
sn.nRounds++
v.Round = sn.nRounds
v.Index = int(atomic.LoadInt64(&sn.LastSeenVote)) + 1
v.Count = &Count{}
v.Confirmed = false
// only default fill-in view numbers when not prefilled
if v.View == 0 {
v.View = sn.ViewNo
}
if v.Av != nil && v.Av.View == 0 {
v.Av.View = sn.ViewNo + 1
}
if v.Rv != nil && v.Rv.View == 0 {
v.Rv.View = sn.ViewNo + 1
}
if v.Vcv != nil && v.Vcv.View == 0 {
v.Vcv.View = sn.ViewNo + 1
}
return sn.StartAnnouncement(
&AnnouncementMessage{LogTest: []byte("vote round"), Round: sn.nRounds, Vote: v})
}
示例12: prepareQuery
func prepareQuery(topic *string, startTime *string, endTime *string, lastEvaluatedKey *map[string]*dynamodb.AttributeValue) *dynamodb.QueryInput {
params := &dynamodb.QueryInput{
TableName: aws.String("midmessages"), // Required
ConsistentRead: aws.Bool(false),
ExclusiveStartKey: prepareLastKey(lastEvaluatedKey),
ExpressionAttributeNames: map[string]*string{
"#ts": aws.String("timestamp"),
},
ExpressionAttributeValues: *prepareAttrValues(topic, startTime, endTime),
//FilterExpression: nil,
//IndexName: nil,
KeyConditionExpression: prepareKeyCondition(topic, startTime, endTime),
//KeyConditions: nil,
// Limit: aws.Long(1),
ProjectionExpression: aws.String("topic,#ts,sender,messageID,message,subject,notificationID"),
//QueryFilter: nil,
// ReturnConsumedCapacity: aws.String("TOTAL"),
ScanIndexForward: aws.Bool(true),
}
log.Println("endTime: ", *endTime)
log.Println("prepareQuery:KeyConditionExpression: ", *params.KeyConditionExpression)
return params
}
示例13: Wait
func (e *AbstractExecutor) Wait() error {
e.Build.BuildState = common.Running
buildTimeout := e.Build.Timeout
if buildTimeout <= 0 {
buildTimeout = common.DefaultTimeout
}
// Wait for signals: cancel, timeout, abort or finish
log.Debugln(e.Config.ShortDescription(), e.Build.ID, "Waiting for signals...")
select {
case <-e.BuildCanceled:
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build got canceled.")
e.Build.FinishBuild(common.Failed, "Build got canceled")
case <-time.After(time.Duration(buildTimeout) * time.Second):
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build timedout.")
e.Build.FinishBuild(common.Failed, "CI Timeout. Execution took longer then %d seconds", buildTimeout)
case signal := <-e.Build.BuildAbort:
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build got aborted", signal)
e.Build.FinishBuild(common.Failed, "Build got aborted: %v", signal)
case err := <-e.BuildFinish:
if err != nil {
return err
}
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build succeeded.")
e.Build.FinishBuild(common.Success, "Build succeeded.")
}
return nil
}
示例14: Start
func (c *consulCoordinator) Start(addr net.Addr, errCh chan error) error {
if addr == nil {
addr = &net.TCPAddr{}
}
c.addr = addr
session := c.client.Session()
// set session to delete our keys on invalidation
sessionOptions := &api.SessionEntry{
Behavior: api.SessionBehaviorDelete,
LockDelay: c.config.LockDelay,
TTL: c.config.TTL,
}
var sessionID string
var err error
err = backoff.RetryNotify(func() error {
sessionID, _, err = session.Create(sessionOptions, nil)
return err
}, backoff.NewExponentialBackOff(), func(err error, t time.Duration) {
log.Println("Cannot create session, retrying in", t, ". Error:", err)
})
if err != nil {
return fmt.Errorf("failed to create consul session: %v", err)
}
// set up a long-running goroutine for renewing the session
c.sessionRenew = make(chan struct{})
c.sessionID = sessionID
log.Println("[coordinator] Coordinator ready")
go func() {
errCh <- session.RenewPeriodic("5s", sessionID, nil, c.sessionRenew)
}()
return nil
}
示例15: write
func write(wr writeRequest, id string) {
cmds, idArr, bufTypeArr := createCommands(wr, id)
qr := qReport{
Cmd: "Queued",
//Type: bufTypeArr,
Ids: idArr,
D: cmds,
QCnt: wr.p.itemsInBuffer,
Port: wr.p.portConf.Name,
}
json, _ := json.Marshal(qr)
h.broadcastSys <- json
// now send off the commands to the appropriate channel
for index, cmdToSendToChannel := range cmds {
//cmdIdCtr++
//cmdId := "fakeid-" + strconv.Itoa(cmdIdCtr)
cmdId := idArr[index]
if bufTypeArr[index] == "Buf" {
log.Println("Send was normal send, so sending to wr.p.sendBuffered")
wr.p.sendBuffered <- Cmd{cmdToSendToChannel, cmdId, false, false}
} else {
log.Println("Send was sendnobuf, so sending to wr.p.sendNoBuf")
wr.p.sendNoBuf <- Cmd{cmdToSendToChannel, cmdId, true, false}
}
}
// garbage collect
if *gcType == "max" {
debug.FreeOSMemory()
}
}