本文整理匯總了Golang中code/cloudfoundry/org/lager.Logger類的典型用法代碼示例。如果您正苦於以下問題:Golang Logger類的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Logger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: connectToNatsServer
func connectToNatsServer(logger lager.Logger, c *config.Config, startMsg chan<- struct{}) *nats.Conn {
var natsClient *nats.Conn
var natsHost atomic.Value
var err error
options := natsOptions(logger, c, &natsHost, startMsg)
attempts := 3
for attempts > 0 {
natsClient, err = options.Connect()
if err == nil {
break
} else {
attempts--
time.Sleep(100 * time.Millisecond)
}
}
if err != nil {
logger.Fatal("nats-connection-error", err)
}
var natsHostStr string
natsUrl, err := url.Parse(natsClient.ConnectedUrl())
if err == nil {
natsHostStr = natsUrl.Host
}
logger.Info("Successfully-connected-to-nats", lager.Data{"host": natsHostStr})
natsHost.Store(natsHostStr)
return natsClient
}
示例2: FailTask
func (db *SQLDB) FailTask(logger lager.Logger, taskGuid, failureReason string) (*models.Task, error) {
logger = logger.Session("fail-task", lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("complete")
var task *models.Task
err := db.transact(logger, func(logger lager.Logger, tx *sql.Tx) error {
var err error
task, err = db.fetchTaskForUpdate(logger, taskGuid, tx)
if err != nil {
logger.Error("failed-locking-task", err)
return err
}
if err = task.ValidateTransitionTo(models.Task_Completed); err != nil {
if task.State != models.Task_Pending {
logger.Error("failed-to-transition-task-to-completed", err)
return err
}
}
return db.completeTask(logger, task, true, failureReason, "", tx)
})
return task, err
}
示例3: commonTasks
func (h *TaskHandler) commonTasks(logger lager.Logger, w http.ResponseWriter, req *http.Request, version format.Version) {
var err error
logger = logger.Session("tasks", lager.Data{"revision": 0})
request := &models.TasksRequest{}
response := &models.TasksResponse{}
defer func() { exitIfUnrecoverable(logger, h.exitChan, response.Error) }()
defer writeResponse(w, response)
err = parseRequest(logger, req, request)
if err != nil {
logger.Error("failed-parsing-request", err)
response.Error = models.ConvertError(err)
return
}
filter := models.TaskFilter{Domain: request.Domain, CellID: request.CellId}
response.Tasks, err = h.controller.Tasks(logger, filter.Domain, filter.CellID)
if err != nil {
response.Error = models.ConvertError(err)
return
}
for i := range response.Tasks {
task := response.Tasks[i]
if task.TaskDefinition == nil {
continue
}
response.Tasks[i] = task.VersionDownTo(version)
}
}
示例4: initializeDropsonde
func initializeDropsonde(logger lager.Logger) {
dropsondeDestination := fmt.Sprint("localhost:", *dropsondePort)
err := dropsonde.Initialize(dropsondeDestination, dropsondeOrigin)
if err != nil {
logger.Error("failed-to-initialize-dropsonde", err)
}
}
示例5: NewPoller
func NewPoller(logger lager.Logger, httpClient *http.Client, pollInterval time.Duration) Poller {
return &poller{
client: httpClient,
pollInterval: pollInterval,
logger: logger.Session("poller"),
}
}
示例6: DesireTask
func (db *ETCDDB) DesireTask(logger lager.Logger, taskDef *models.TaskDefinition, taskGuid, domain string) error {
logger = logger.WithData(lager.Data{"task_guid": taskGuid})
logger.Info("starting")
defer logger.Info("finished")
now := db.clock.Now().UnixNano()
task := &models.Task{
TaskDefinition: taskDef,
TaskGuid: taskGuid,
Domain: domain,
State: models.Task_Pending,
CreatedAt: now,
UpdatedAt: now,
}
value, err := db.serializeModel(logger, task)
if err != nil {
return err
}
logger.Debug("persisting-task")
_, err = db.client.Create(TaskSchemaPathByGuid(task.TaskGuid), value, NO_TTL)
if err != nil {
return ErrorFromEtcdError(logger, err)
}
logger.Debug("succeeded-persisting-task")
return nil
}
示例7: resolveRestartableCrashedActualLRPS
func (db *ETCDDB) resolveRestartableCrashedActualLRPS(logger lager.Logger, actualLRP *models.ActualLRP, starts *startRequests) func() {
return func() {
actualKey := actualLRP.ActualLRPKey
logger = logger.Session("restart-crash", lager.Data{
"process_guid": actualKey.ProcessGuid,
"index": actualKey.Index,
})
if actualLRP.State != models.ActualLRPStateCrashed {
logger.Error("failed-actual-lrp-state-is-not-crashed", nil)
return
}
logger.Debug("unclaiming-actual-lrp", lager.Data{"process_guid": actualLRP.ActualLRPKey.ProcessGuid, "index": actualLRP.ActualLRPKey.Index})
_, err := db.unclaimActualLRP(logger, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey)
if err != nil {
logger.Error("failed-unclaiming-crash", err)
return
}
logger.Debug("succeeded-unclaiming-actual-lrp")
starts.Add(logger, &actualKey)
}
}
示例8: StartActualLRP
func (h *ActualLRPLifecycleHandler) StartActualLRP(logger lager.Logger, w http.ResponseWriter, req *http.Request) {
var err error
logger = logger.Session("start-actual-lrp")
request := &models.StartActualLRPRequest{}
response := &models.ActualLRPLifecycleResponse{}
defer func() { exitIfUnrecoverable(logger, h.exitChan, response.Error) }()
defer writeResponse(w, response)
err = parseRequest(logger, req, request)
if err != nil {
response.Error = models.ConvertError(err)
return
}
before, after, err := h.db.StartActualLRP(logger, request.ActualLrpKey, request.ActualLrpInstanceKey, request.ActualLrpNetInfo)
if err != nil {
response.Error = models.ConvertError(err)
return
}
if before == nil {
go h.actualHub.Emit(models.NewActualLRPCreatedEvent(after))
} else if !before.Equal(after) {
go h.actualHub.Emit(models.NewActualLRPChangedEvent(before, after))
}
}
示例9: initializeDropsonde
func initializeDropsonde(logger lager.Logger, uploaderConfig config.UploaderConfig) {
dropsondeDestination := fmt.Sprint("localhost:", uploaderConfig.DropsondePort)
err := dropsonde.Initialize(dropsondeDestination, dropsondeOrigin)
if err != nil {
logger.Error("failed to initialize dropsonde: %v", err)
}
}
示例10: RemoveActualLRP
func (h *ActualLRPLifecycleHandler) RemoveActualLRP(logger lager.Logger, w http.ResponseWriter, req *http.Request) {
var err error
logger = logger.Session("remove-actual-lrp")
request := &models.RemoveActualLRPRequest{}
response := &models.ActualLRPLifecycleResponse{}
defer func() { exitIfUnrecoverable(logger, h.exitChan, response.Error) }()
defer writeResponse(w, response)
err = parseRequest(logger, req, request)
if err != nil {
response.Error = models.ConvertError(err)
return
}
beforeActualLRPGroup, err := h.db.ActualLRPGroupByProcessGuidAndIndex(logger, request.ProcessGuid, request.Index)
if err != nil {
response.Error = models.ConvertError(err)
return
}
err = h.db.RemoveActualLRP(logger, request.ProcessGuid, request.Index, request.ActualLrpInstanceKey)
if err != nil {
response.Error = models.ConvertError(err)
return
}
go h.actualHub.Emit(models.NewActualLRPRemovedEvent(beforeActualLRPGroup))
}
示例11: ClaimActualLRP
func (h *ActualLRPLifecycleHandler) ClaimActualLRP(logger lager.Logger, w http.ResponseWriter, req *http.Request) {
var err error
logger = logger.Session("claim-actual-lrp")
request := &models.ClaimActualLRPRequest{}
response := &models.ActualLRPLifecycleResponse{}
defer func() { exitIfUnrecoverable(logger, h.exitChan, response.Error) }()
defer writeResponse(w, response)
err = parseRequest(logger, req, request)
if err != nil {
response.Error = models.ConvertError(err)
return
}
before, after, err := h.db.ClaimActualLRP(logger, request.ProcessGuid, request.Index, request.ActualLrpInstanceKey)
if err != nil {
response.Error = models.ConvertError(err)
return
}
if !after.Equal(before) {
go h.actualHub.Emit(models.NewActualLRPChangedEvent(before, after))
}
}
示例12: DiffSize
func (a *AUFSDiffSizer) DiffSize(logger lager.Logger, containerRootFSPath string) (uint64, error) {
_, err := os.Stat(containerRootFSPath)
if os.IsNotExist(err) {
return 0, fmt.Errorf("get usage: %s", err)
}
log := logger.Session("diff-size", lager.Data{"path": containerRootFSPath})
log.Debug("start")
command := fmt.Sprintf("df -B 1 %s | tail -n1 | awk -v N=3 '{print $N}'", a.AUFSDiffPathFinder.GetDiffLayerPath((containerRootFSPath)))
outbytes, err := exec.Command("sh", "-c", command).CombinedOutput()
if err != nil {
log.Error("df-failed", err)
return 0, fmt.Errorf("get usage: df: %s, %s", err, string(outbytes))
}
var bytesUsed uint64
if _, err := fmt.Sscanf(string(outbytes), "%d", &bytesUsed); err != nil {
log.Error("scanf-failed", err, lager.Data{"out": string(outbytes)})
return 0, nil
}
log.Debug("finished", lager.Data{"bytes": bytesUsed})
return bytesUsed, nil
}
示例13: mountCgroup
func (s *CgroupStarter) mountCgroup(logger lager.Logger, cgroupPath, subsystems string) error {
logger = logger.Session("mount-cgroup", lager.Data{
"path": cgroupPath,
"subsystems": subsystems,
})
logger.Info("started")
if !s.isMountPoint(cgroupPath) {
if err := os.MkdirAll(cgroupPath, 0755); err != nil {
return fmt.Errorf("mkdir '%s': %s", cgroupPath, err)
}
cmd := exec.Command("mount", "-n", "-t", "cgroup", "-o", subsystems, "cgroup", cgroupPath)
cmd.Stderr = logging.Writer(logger.Session("mount-cgroup-cmd"))
if err := s.CommandRunner.Run(cmd); err != nil {
return fmt.Errorf("mounting subsystems '%s' in '%s': %s", subsystems, cgroupPath, err)
}
} else {
logger.Info("subsystems-already-mounted")
}
logger.Info("finished")
return nil
}
示例14: NewMetrics
func NewMetrics(logger lager.Logger, backingStoresPath, depotPath string) Metrics {
return &metrics{
backingStoresPath: backingStoresPath,
depotPath: depotPath,
logger: logger.Session("metrics"),
}
}
示例15: NewPresence
func NewPresence(
logger lager.Logger,
consulClient consuladapter.Client,
lockKey string,
lockValue []byte,
clock clock.Clock,
retryInterval time.Duration,
lockTTL time.Duration,
) Presence {
uuid, err := uuid.NewV4()
if err != nil {
logger.Fatal("create-uuid-failed", err)
}
session, err := NewSessionNoChecks(uuid.String(), lockTTL, consulClient)
if err != nil {
logger.Fatal("consul-session-failed", err)
}
return Presence{
consul: session,
key: lockKey,
value: lockValue,
clock: clock,
retryInterval: retryInterval,
logger: logger,
}
}