本文整理汇总了Golang中github.com/Sirupsen/logrus.WithError函数的典型用法代码示例。如果您正苦于以下问题:Golang WithError函数的具体用法?Golang WithError怎么用?Golang WithError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: renderHTML
func renderHTML(w http.ResponseWriter, r *http.Request, task eremetic.Task, taskID string, conf *config.Config) {
var templateFile string
data := make(map[string]interface{})
funcMap := template.FuncMap{
"ToLower": strings.ToLower,
"FormatTime": FormatTime,
}
if reflect.DeepEqual(task, (eremetic.Task{})) {
notFound(w, r)
return
}
templateFile = "task.html"
data = makeMap(task)
data["Version"] = version.Version
source, _ := assets.Asset(fmt.Sprintf("templates/%s", templateFile))
tpl, err := template.New(templateFile).Funcs(funcMap).Parse(string(source))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
logrus.WithError(err).WithField("template", templateFile).Error("Unable to load template")
return
}
err = tpl.Execute(w, data)
if err != nil {
logrus.WithError(err).WithField("template", templateFile).Error("Unable to execute template")
}
}
示例2: Start
// Start begins periodic polling of Controller for the latest configuration. This is a blocking operation.
func (p *poller) Start() error {
// Stop existing ticker if necessary
if p.ticker != nil {
if err := p.Stop(); err != nil {
logrus.WithError(err).Error("Could not stop existing periodic poll")
return err
}
}
// Create new ticker
p.ticker = time.NewTicker(p.config.Controller.Poll)
// Do initial poll
if err := p.poll(); err != nil {
logrus.WithError(err).Error("Poll failed")
}
// Start periodic poll
for _ = range p.ticker.C {
if err := p.poll(); err != nil {
logrus.WithError(err).Error("Poll failed")
}
}
return nil
}
示例3: main
func main() {
flag.Parse()
if *NAME == "" {
log.Fatal("name required")
}
if *MEMORY == 0 {
log.Fatal("memory required")
}
if *CPUS == 0 {
log.Fatal("cpus required")
}
db, err := bolt.Open(*DB_PATH, 0600, nil)
if err != nil {
log.WithError(err).Fatal("failed to open database")
}
planrep := dal.NewBoltPlanrep(db)
plan := &models.Plan{
Name: *NAME,
Memory: *MEMORY * 1024 * 1024,
Cpus: *CPUS,
DiskSize: *DISK * 1024 * 1024 * 1024,
}
if err := planrep.Add(plan); err != nil {
log.WithError(err).WithField("plan", plan).Fatal("failed to add ip address")
}
}
示例4: run
func (sv *supervisor) run(name string, args ...string) {
isRunning, err := sv.dk.IsRunning(name)
if err != nil {
log.WithError(err).Warnf("could not check running status of %s.", name)
return
}
if isRunning {
return
}
ro := docker.RunOptions{
Name: name,
Image: images[name],
Args: args,
NetworkMode: "host",
VolumesFrom: []string{"minion"},
}
if name == Ovsvswitchd {
ro.Privileged = true
}
log.Infof("Start Container: %s", name)
_, err = sv.dk.Run(ro)
if err != nil {
log.WithError(err).Warnf("Failed to run %s.", name)
}
}
示例5: runApp
// Synchronize locally running "application" containers with the database.
func (sv *supervisor) runApp() {
for range sv.conn.TriggerTick(10, db.MinionTable, db.ContainerTable).C {
minion, err := sv.conn.MinionSelf()
if err != nil || minion.Role != db.Worker {
continue
}
if err := delStopped(sv.dk); err != nil {
log.WithError(err).Error("Failed to clean up stopped containers")
}
dkcs, err := sv.dk.List(map[string][]string{
"label": {docker.SchedulerLabelPair},
})
if err != nil {
log.WithError(err).Error("Failed to list local containers.")
continue
}
sv.conn.Transact(func(view db.Database) error {
sv.runAppTransact(view, dkcs)
return nil
})
}
}
示例6: Run
// Run blocks implementing the scheduler module.
func Run(conn db.Conn, dk docker.Client) {
bootWait(conn)
subnet := getMinionSubnet(conn)
err := dk.ConfigureNetwork(plugin.NetworkName, subnet)
if err != nil {
log.WithError(err).Fatal("Failed to configure network plugin")
}
loopLog := util.NewEventTimer("Scheduler")
trig := conn.TriggerTick(60, db.MinionTable, db.ContainerTable,
db.PlacementTable, db.EtcdTable).C
for range trig {
loopLog.LogStart()
minion, err := conn.MinionSelf()
if err != nil {
log.WithError(err).Warn("Missing self in the minion table.")
continue
}
if minion.Role == db.Worker {
subnet = updateNetwork(conn, dk, subnet)
runWorker(conn, dk, minion.PrivateIP, subnet)
} else if minion.Role == db.Master {
runMaster(conn)
}
loopLog.LogEnd()
}
}
示例7: main
func main() {
containers, err := exec.Command("quilt", "containers").Output()
if err != nil {
log.WithError(err).Fatal("Unable to get containers.")
}
fmt.Println("`quilt containers` output:")
fmt.Println(string(containers))
matches := regexp.MustCompile(`(\d+) .*run master.*`).
FindStringSubmatch(string(containers))
if len(matches) != 2 {
log.Fatal("Unable to find StitchID of Spark master.")
}
id := matches[1]
logs, err := exec.Command("quilt", "logs", id).CombinedOutput()
if err != nil {
log.WithError(err).Fatal("Unable to get Spark master logs.")
}
fmt.Printf("`quilt logs %s` output:\n", id)
fmt.Println(string(logs))
if !strings.Contains(string(logs), "Pi is roughly") {
fmt.Println("FAILED, sparkPI did not execute correctly.")
} else {
fmt.Println("PASSED")
}
}
示例8: updateContainerIP
func updateContainerIP(containers []db.Container, privateIP string, store Store) {
oldIPMap := map[string]string{}
selfStore := path.Join(nodeStore, privateIP)
etcdIPs, err := store.Get(path.Join(selfStore, minionIPStore))
if err != nil {
etcdErr, ok := err.(client.Error)
if !ok || etcdErr.Code != client.ErrorCodeKeyNotFound {
log.WithError(err).Error("Failed to load current IPs from Etcd")
return
}
}
json.Unmarshal([]byte(etcdIPs), &oldIPMap)
newIPMap := map[string]string{}
for _, c := range containers {
newIPMap[strconv.Itoa(c.StitchID)] = c.IP
}
if util.StrStrMapEqual(oldIPMap, newIPMap) {
return
}
jsonData, err := json.Marshal(newIPMap)
if err != nil {
log.WithError(err).Error("Failed to marshal minion container IP map")
return
}
err = store.Set(path.Join(selfStore, minionIPStore), string(jsonData), 0)
if err != nil {
log.WithError(err).Error("Failed to update minion container IP map")
}
}
示例9: main
func main() {
config, err := OpenConfig("config.yml")
if err != nil {
logrus.WithError(err).Fatal("Error loading config file")
}
logrus.Info("Loaded config")
repo, err := rethink.NewRepo(config.RethinkDB)
if err != nil {
logrus.WithError(err).Fatal("Error connecting to repository")
}
logrus.Info("Connected to repository")
tokenValidator := controllers.NewTokenValidator(config.Token.ClientID)
updateController := controllers.NewUpdateController(repo, tokenValidator)
readController := controllers.NewReadController(repo, tokenValidator)
readAllController := controllers.NewReadAllController(repo, tokenValidator)
subscribeController := controllers.NewSubscribeController(repo, tokenValidator)
unsubscribeController := controllers.NewUnsubscribeController(repo, tokenValidator)
http.Handle("/updates", updateController)
http.Handle("/read", readController)
http.Handle("/readall", readAllController)
http.Handle("/subscribe", subscribeController)
http.Handle("/unsubscribe", unsubscribeController)
logrus.Info("Starting server")
http.ListenAndServe(config.Server.Listen, nil)
}
示例10: Run
// Run retrieves and prints the requested containers.
func (cCmd *Container) Run() int {
localClient, err := cCmd.clientGetter.Client(cCmd.host)
if err != nil {
log.Error(err)
return 1
}
defer localClient.Close()
c, err := cCmd.clientGetter.LeaderClient(localClient)
if err != nil {
log.WithError(err).Error("Error connecting to leader.")
return 1
}
defer c.Close()
containers, err := c.QueryContainers()
if err != nil {
log.WithError(err).Error("Unable to query containers.")
return 1
}
machines, err := localClient.QueryMachines()
if err != nil {
log.WithError(err).Error("Unable to query machines")
return 1
}
writeContainers(os.Stdout, machines, containers)
return 0
}
示例11: write
func (hc *HyenaClient) write() {
stop := false
for f := range hc.send {
buf := f.Buffer()
if !stop {
size := byte(len(buf))
n, err := hc.conn.Write([]byte{size})
if err != nil || n != 1 {
log.WithError(err).Error("Writing to hyenad client connection")
hc.conn.Close()
stop = true
}
n, err = hc.conn.Write(buf)
if err != nil || n != len(buf) {
log.WithError(err).Error("Writing to hyenad client connection")
hc.conn.Close()
stop = true
}
frameBuffers.Return(buf)
} else {
frameBuffers.Return(buf)
log.WithField("Frame", f).Warn("Dropping frame, connection down")
}
}
}
示例12: readloop
func (d *dialer) readloop(u *upstream) {
for {
if atomic.LoadInt32(&u.closed) != 0 {
logrus.WithField("proto", u.proto).Warnln("dialer upstream is closed")
return
}
p := packet{}
switch u.proto {
case tcp:
err := u.decoder.Decode(&p)
if err != nil {
logrus.WithFields(logrus.Fields{
"error": err,
}).Warnln("Dialer docode upstream packet")
return
}
case udp:
udpbuf := make([]byte, buffersize)
n, err := u.conn.Read(udpbuf)
if err != nil {
logrus.WithError(err).Warnln("dialer Read UDP error")
return
}
if err := decodePacket(udpbuf[:n], &p); err != nil {
logrus.WithError(err).Warnln("dialer gop decode from udp error")
continue
}
p.udp = true
}
d.proc(u, &p)
}
}
示例13: ChangeUserTestGroup
func (ab *abManager) ChangeUserTestGroup(userid, appid, testname string) (models.ABUser, error) {
user, err := ab.User(userid)
if err != nil {
logrus.WithError(err).Errorf("User fetch failed")
return user, err
}
repo := ab.db.GetABRepo()
app, err := repo.App(appid)
if err != nil {
logrus.WithError(err).Errorf("App fetch failed")
return user, err
}
version := int32(-1)
if testname != "" {
for _, t := range app.Tests {
if t.Name == testname {
version = app.Version
break
}
}
} else {
version = app.Version
}
if version <= 0 {
return user, grpc.Errorf(codes.InvalidArgument, "invalid test group name")
}
if err := repo.ChangeTesterInfo(userid, appid, testname, version); err != nil {
logrus.WithError(err).Errorf("failed to change user testing info appid=%s to %s", appid, testname)
return user, err
}
return ab.User(userid)
}
示例14: Start
func (sys *System) Start() {
backends := make(map[edn.Keyword]*Backend)
for name, config := range sys.config.Backends {
backend, err := NewBackend(sys, string(name), config)
if err != nil {
log.WithError(err).Fatal("Can't start backend")
os.Exit(1)
}
backends[name] = backend
}
for _, config := range sys.config.Frontends {
switch string(config.Type) {
case "zmq":
backend, pst := backends[config.Backend]
if !pst {
log.Fatalf("There are no backend %s", config.Backend)
os.Exit(1)
}
_, err := NewZMQFrontend(sys, config, backend)
if err != nil {
log.WithError(err).Fatal("Can't start frontend")
os.Exit(1)
}
case "http":
NewHttpFrontend(sys, config.Endpoint)
}
}
sys.processes.Wait()
}
示例15: New
// New creates a GCE cluster.
//
// Clusters are differentiated (namespace) by setting the description and
// filtering off of that.
func New(namespace string) (*Cluster, error) {
if err := gceInit(); err != nil {
log.WithError(err).Debug("failed to start up gce")
return nil, err
}
clst := Cluster{
projID: "declarative-infrastructure",
ns: namespace,
ipv4Range: "192.168.0.0/16",
}
clst.baseURL = fmt.Sprintf("%s/%s", computeBaseURL, clst.projID)
clst.intFW = fmt.Sprintf("%s-internal", clst.ns)
clst.imgURL = fmt.Sprintf("%s/%s", computeBaseURL,
"ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20160921")
if err := clst.netInit(); err != nil {
log.WithError(err).Debug("failed to start up gce network")
return nil, err
}
if err := clst.fwInit(); err != nil {
log.WithError(err).Debug("failed to start up gce firewalls")
return nil, err
}
return &clst, nil
}