本文整理匯總了Golang中github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/Sirupsen/logrus.WithField函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithField函數的具體用法?Golang WithField怎麽用?Golang WithField使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithField函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildExpression
func buildExpression(expr cfg.AnalyticExpr, metrics map[string]float64, constraints map[string]float64) string {
toBuild := expr.Expr
for _, metric := range expr.Metrics {
if value, ok := metrics[metric]; ok {
toBuild = strings.Replace(toBuild, metric, strconv.FormatFloat(value, 'f', -1, 64), -1)
} else {
log.WithField("metric", metric).Debugln("Cannot build expression: metric unknown")
return "noexp"
}
}
for _, constraint := range expr.Constraints {
if value, ok := constraints[constraint]; ok {
toBuild = strings.Replace(toBuild, constraint, strconv.FormatFloat(value, 'f', -1, 64), -1)
} else {
log.WithField("constraint", constraint).Debugln("Cannot build expression: constraint unknown")
return "noexp"
}
}
return toBuild
}
示例2: getFriendsData
func getFriendsData(friends map[string]string) ([]data.Shared, error) {
var err error
friendsData := make([]data.Shared, 0, len(friends))
for friend, address := range friends {
friendRoute := address + c_ROUTE_SHARED
friendData, err := network.DoRequest("GET", friendRoute, nil)
if err != nil {
log.WithField("address", address).Debugln("Error retrieving friend stats")
}
err = storage.StoreData(friend, friendData, enum.SHARED)
if err != nil {
log.WithField("err", err).Debugln("Error storing friends data")
}
sharedData, err := data.ByteToShared(friendData)
if err != nil {
log.WithField("address", address).Debugln("Friend data not stored")
} else {
friendsData = append(friendsData, sharedData)
}
}
return friendsData, err
}
示例3: Run
func (p *Stop) Run(config Action) error {
var err error
var toStop string
running := config.Instances.Running
if len(running) < 1 {
log.WithField("err", ErrNoContainerToStop).Errorln("Cannot stop running container. Trying with pending ones...")
pending := config.Instances.Pending
if len(pending) < 1 {
log.WithField("err", ErrNoContainerToStop).Errorln("Cannot stop pending container")
return ErrNoContainerToStop
}
toStop = pending[0]
} else {
toStop = running[0]
}
err = container.Docker().Client.StopContainer(toStop, config.Parameters.StopTimeout)
if err != nil {
log.WithField("err", err).Errorln("Cannot stop container ", toStop)
return err
}
return nil
}
示例4: readCommand
func readCommand(r *http.Request) (Command, error) {
var err error
var cmd Command
body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
if err != nil {
log.WithField("err", err).Errorln("Error reading command body")
return Command{}, err
}
if err = r.Body.Close(); err != nil {
log.WithField("err", err).Errorln("Error closing command body")
return Command{}, err
}
if err = json.Unmarshal(body, &cmd); err != nil {
log.WithField("err", err).Errorln("Error unmarshaling command body")
return Command{}, err
}
cmd.Timestamp = time.Now()
log.WithFields(log.Fields{
"name": cmd.Name,
"target": cmd.Target,
"timestamp": cmd.Timestamp,
}).Debugln("Received command")
return cmd, nil
}
示例5: RemoveServiceInstance
func RemoveServiceInstance(name string, instance string) error {
service, err := getServiceBy("name", name)
if err != nil {
log.WithField("service", name).Errorln("Cannot remove service instance: service unknown")
return err
}
instIndexStop, err := findIdIndex(instance, service.Instances.Stopped)
if err != nil {
log.WithField("instance", instance).Errorln("Cannot remove service instance: instance unknown")
return err
}
instIndexAll, err := findIdIndex(instance, service.Instances.All)
if err != nil {
log.WithField("instance", instance).Errorln("Cannot remove service instance: instance unknown")
return err
}
service.Instances.Stopped = append(service.Instances.Stopped[:instIndexStop],
service.Instances.Stopped[instIndexStop+1:]...)
service.Instances.All = append(service.Instances.All[:instIndexAll],
service.Instances.All[instIndexAll+1:]...)
return nil
}
示例6: initializeNetwork
func initializeNetwork(address string, port string) {
err := network.InitializeNetwork(address, port)
if err != nil {
log.WithField("err", err).Fatalln("Error initializing the network")
}
log.WithField(network.Config().IpAddress+":"+network.Config().Port, "ok").Infoln("Network initialized")
}
示例7: updateFriendsData
func updateFriendsData(nFriends int) error {
var err error
log.Debugln("Updating friends data")
err = clearFriendsData()
if err != nil {
return err
}
peers := getAllPeers()
log.WithField("peers", len(peers)).Debugln("Number of peers")
if len(peers) == 0 {
return ErrNoPeers
}
friends, err := chooseRandomFriends(peers, nFriends)
if err != nil {
return err
}
log.WithField("friends", friends).Debugln("Friends to connect with")
friendsData, err := getFriendsData(friends)
if err != nil {
return err
}
clusterData, err := mergeSharedData(friendsData)
if err != nil {
return err
}
data.SaveSharedCluster(clusterData)
return nil
}
示例8: startService
func startService(name string) {
log.WithField("name", name).Debugln("Starting service")
toStart, err := service.GetServiceByName(name)
if err != nil {
log.WithField("name", name).Debugln("Error starting service")
}
ch.SendActionStartMessage(toStart)
}
示例9: initializeContainerEngine
// TODO needs to make more "generic" the container engine package
func initializeContainerEngine() {
daemonUrl := getDaemonUrl()
log.WithField("daemonUrl", daemonUrl).Debugln("Container engine initialization")
err := container.Connect(daemonUrl, cfg.GetAgentDocker().DaemonTimeout)
if err != nil {
log.WithField("err", err).Fatalln("Error initializing container engine")
}
log.WithField("docker", "ok").Infoln("Container engine initialized")
}
示例10: checkConfiguration
func checkConfiguration(name string, conf *cfg.ServiceDocker) {
if conf.Memory == "" {
log.WithField("service", name).Warnln("Memory limit not set. Service will use all the memory available")
}
if conf.CpusetCpus == "" {
log.WithField("service", name).Warnln("Cores not assigned. Service will use all the cores")
}
}
示例11: SetPlannerStrategy
func SetPlannerStrategy(strategyName string) {
strtg, err := strategy.New(strategyName)
if err != nil {
log.WithField("err", err).Errorln("Strategy cannot be set")
// If error use default one
strtg, err = strategy.New("dummy")
}
currentStrategy = strtg
log.WithField("strategy", strtg.Name()).Infoln("Strategy initialized")
}
示例12: initiailizeMonitoring
func initiailizeMonitoring() {
defer log.Infoln("Initializing autonomic monitoring")
ch_aut_err := chn.GetAutonomicErrChannel()
enableLogReading = cfg.GetAgentAutonomic().EnableLogReading
mtr.Initialize(srv.List())
// Start log reader if needed
if enableLogReading {
lgr.StartLogReader()
log.WithField("logreader", enableLogReading).Debugln("Log reading is enabled")
}
// Get the list of containers (running or not) to monitor
containers, err := container.Docker().Client.ListContainers(true, false, "")
if err != nil {
log.WithField("err", err).Debugln("Error monitoring containers")
ch_aut_err <- err
}
// Start the monitor for each configured service
for _, c := range containers {
info, _ := container.Docker().Client.InspectContainer(c.Id)
status := getContainerStatus(info)
service, err := srv.GetServiceByImage(c.Image)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"image": c.Image,
}).Warningln("Error monitoring service")
} else {
e := evt.Event{
Service: service.Name,
Image: c.Image,
Instance: c.Id,
Status: status,
}
evt.HandleCreateEvent(e)
evt.HanldeStartEvent(e)
mtr.AddInstance(c.Id)
if _, ok := instBuffer[c.Id]; !ok {
instBuffer[c.Id] = instanceMetricBuffer{
cpuInst: utils.BuildBuffer(c_B_SIZE),
cpuSys: utils.BuildBuffer(c_B_SIZE),
}
}
container.Docker().Client.StartMonitorStats(c.Id, statCallBack, ch_mnt_stats_err)
if status == enum.PENDING && enableLogReading {
startMonitorLog(c.Id)
}
}
}
}
示例13: ComputeUsedResources
func ComputeUsedResources() {
var err error
_, err = ComputeUsedCpus()
if err != nil {
log.WithField("err", err).Errorln("Error computing used CPU")
}
_, err = ComputeUsedMemory()
if err != nil {
log.WithField("err", err).Errorln("Error computing used Memory")
}
}
示例14: stopService
func stopService(name string) {
log.WithField("name", name).Debugln("Stopping service")
toStop, err := service.GetServiceByName(name)
if err != nil {
log.WithField("name", name).Debugln("Error stopping service")
}
if len(toStop.Instances.All) < 1 {
log.WithField("service", name).Debugln("No active instance to stop")
return
}
ch.SendActionStopMessage(toStop)
}
示例15: computeMetrics
func computeMetrics() data.MetricStats {
metrics := data.MetricStats{}
instMetrics := computeInstancesMetrics()
log.WithField("instMetrics", instMetrics).Debugln("Computed instances metrics")
servMetrics := computeServicesMetrics(instMetrics)
log.WithField("servMetrics", servMetrics).Debugln("Computed service metrics")
sysMetrics := computeSysMetrics(instMetrics)
log.WithField("sysMetrics", sysMetrics).Debugln("Computed system metrics")
metrics.Instance = instMetrics
metrics.Service = servMetrics
metrics.System = sysMetrics
return metrics
}