本文整理汇总了Golang中github.com/eris-ltd/eris-cli/Godeps/_workspace/src/github.com/Sirupsen/logrus.WithField函数的典型用法代码示例。如果您正苦于以下问题:Golang WithField函数的具体用法?Golang WithField怎么用?Golang WithField使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithField函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readActionDefinition
func readActionDefinition(actionName []string, dropped map[string]string, varNum int) (*viper.Viper, map[string]string, error) {
if len(actionName) == 0 {
log.WithFields(log.Fields{
"action": actionName,
"drop": dropped,
"var#": varNum,
}).Debug("Failed to load action definition file")
return nil, dropped, fmt.Errorf("The marmots could not find the action definition file.\nPlease check your actions with [eris actions ls]")
}
log.WithField("file", strings.Join(actionName, "_")).Debug("Preparing to read action definition file")
log.WithField("drop", dropped).Debug()
var actionConf = viper.New()
actionConf.AddConfigPath(dir.ActionsPath)
actionConf.SetConfigName(strings.Join(actionName, "_"))
err := actionConf.ReadInConfig()
if err != nil {
log.WithField("action", actionName[len(actionName)-1]).Debug("Dropping and retrying")
dropped[fmt.Sprintf("$%d", varNum)] = actionName[len(actionName)-1]
actionName = actionName[:len(actionName)-1]
varNum++
return readActionDefinition(actionName, dropped, varNum)
} else {
log.Debug("Successfully read action definition file")
}
return actionConf, dropped, nil
}
示例2: TestRmChain
func TestRmChain(t *testing.T) {
testStartChain(t, chainName)
do := def.NowDo()
do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
log.WithField("=>", do.Name).Info("Removing keys (from tests)")
if e := services.KillService(do); e != nil {
tests.IfExit(e)
}
do = def.NowDo()
do.Name, do.Rm, do.RmD = chainName, false, false
log.WithField("=>", do.Name).Info("Stopping chain (from tests)")
if e := KillChain(do); e != nil {
tests.IfExit(e)
}
testExistAndRun(t, chainName, true, false)
do = def.NowDo()
do.Name = chainName
do.RmD = true
log.WithField("=>", do.Name).Info("Removing chain (from tests)")
if e := RmChain(do); e != nil {
tests.IfExit(e)
}
testExistAndRun(t, chainName, false, false)
}
示例3: StartServicesAndChains
func StartServicesAndChains(do *definitions.Do) error {
// start the services and chains
doSrvs := definitions.NowDo()
if do.Action.Dependencies == nil || len(do.Action.Dependencies.Services) == 0 {
log.Debug("No services to start")
} else {
doSrvs.Operations.Args = do.Action.Dependencies.Services
log.WithField("args", doSrvs.Operations.Args).Debug("Starting services")
if err := services.StartService(doSrvs); err != nil {
return err
}
}
doChns := definitions.NowDo()
doChns.Name = do.Action.Chain
if doChns.Name == "" {
log.Debug("No chain to start")
} else {
log.WithField("=>", doChns.Name).Debug("Starting chain")
if err := chains.StartChain(do); err != nil {
return err
}
}
return nil
}
示例4: RmData
// TODO: skip errors flag
func RmData(do *definitions.Do) (err error) {
if len(do.Operations.Args) == 0 {
do.Operations.Args = []string{do.Name}
}
for _, name := range do.Operations.Args {
do.Name = name
if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
log.WithField("=>", do.Name).Info("Removing data container")
srv := definitions.BlankServiceDefinition()
srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)
if err = perform.DockerRemove(srv.Service, srv.Operations, false, do.Volumes); err != nil {
log.Errorf("Error removing %s: %v", do.Name, err)
return err
}
} else {
err = fmt.Errorf("I cannot find that data container for %s. Please check the data container name you sent me.", do.Name)
log.Error(err)
return err
}
if do.RmHF {
log.WithField("=>", do.Name).Warn("Removing host directory")
if err = os.RemoveAll(filepath.Join(DataContainersPath, do.Name)); err != nil {
return err
}
}
}
do.Result = "success"
return err
}
示例5: ListRunningOrExisting
// lists the containers running for a chain/service
// eventually remotes/actions
// existing -> true to ls existing; false to ls running
func ListRunningOrExisting(quiet, existing bool, typ string) (result string, err error) {
re := "Running"
if existing {
re = "Existing"
}
log.WithField("status", strings.ToLower(re)).Debug("Asking Docker to list containers")
//gotta go
if quiet {
if typ == "services" {
result = strings.Join(util.ServiceContainerNames(existing), "\n")
}
if typ == "chains" {
result = strings.Join(util.ChainContainerNames(existing), "\n")
}
} else {
if typ == "services" {
log.WithField("=>", fmt.Sprintf("service:%v", strings.ToLower(re))).Debug("Printing table")
result, _ = PrintTableReport("service", existing, false) //false is for All, dealt with somewhere else
}
if typ == "chains" {
log.WithField("=>", fmt.Sprintf("chain:%v", strings.ToLower(re))).Debugf("Printing table")
result, _ = PrintTableReport("chain", existing, false)
}
}
return result, nil
}
示例6: DockerStop
// DockerStop stops a running ops.SrvContainerName container unforcedly.
// timeout is a number of seconds to wait before killing the container process
// ungracefully.
// It returns Docker errors on exit if not successful. DockerStop doesn't return
// an error if the container isn't running.
func DockerStop(srv *def.Service, ops *def.Operation, timeout uint) error {
// don't limit this to verbose because it takes a few seconds
// [zr] unless force sets timeout to 0 (for, eg. stdout)
if timeout != 0 {
log.WithField("=>", srv.Name).Warn("Stopping (may take a few seconds)")
}
log.WithFields(log.Fields{
"=>": ops.SrvContainerName,
"timeout": timeout,
}).Info("Stopping container")
_, running := ContainerExists(ops)
if running {
log.WithField("=>", ops.SrvContainerName).Debug("Container found running")
err := stopContainer(ops.SrvContainerName, timeout)
if err != nil {
return err
}
} else {
log.WithField("=>", ops.SrvContainerName).Debug("Container found not running")
}
log.WithField("=>", ops.SrvContainerName).Info("Container stopped")
return nil
}
示例7: createContainer
// ----------------------------------------------------------------------------
// --------------------- Container Core ------------------------------------
// ----------------------------------------------------------------------------
func createContainer(opts docker.CreateContainerOptions) (*docker.Container, error) {
dockerContainer, err := util.DockerClient.CreateContainer(opts)
if err != nil {
if err == docker.ErrNoSuchImage {
if os.Getenv("ERIS_PULL_APPROVE") != "true" {
var input string
log.WithField("image", opts.Config.Image).Warn("The docker image not found locally")
fmt.Print("Would you like the marmots to pull it from the repository? (y/n): ")
fmt.Scanln(&input)
if input == "Y" || input == "y" || input == "YES" || input == "Yes" || input == "yes" {
log.Debug("User assented to pull")
} else {
log.Debug("User refused to pull")
return nil, fmt.Errorf("Cannot start a container based on an image you will not let me pull.\n")
}
} else {
log.WithField("image", opts.Config.Image).Warn("The Docker image is not found locally")
log.Warn("The marmots are approved to pull it from the repository on your behalf")
log.Warn("This could take a few minutes")
}
if err := pullImage(opts.Config.Image, nil); err != nil {
return nil, err
}
dockerContainer, err = util.DockerClient.CreateContainer(opts)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
return dockerContainer, nil
}
示例8: testNumbersExistAndRun
//[zr] TODO move to testings package
func testNumbersExistAndRun(t *testing.T, servName string, containerExist, containerRun int) {
log.WithFields(log.Fields{
"=>": servName,
"existing#": containerExist,
"running#": containerRun,
}).Info("Checking number of containers for")
log.WithField("=>", servName).Debug("Checking existing containers for")
exist := util.HowManyContainersExisting(servName, "service")
log.WithField("=>", servName).Debug("Checking running containers for")
run := util.HowManyContainersRunning(servName, "service")
if exist != containerExist {
log.WithFields(log.Fields{
"name": servName,
"expected": containerExist,
"got": exist,
}).Error("Wrong number of existing containers")
fatal(t, nil)
}
if run != containerRun {
log.WithFields(log.Fields{
"name": servName,
"expected": containerExist,
"got": run,
}).Error("Wrong number of running containers")
fatal(t, nil)
}
log.Info("All good")
}
示例9: DockerExecData
// DockerExecData runs a data container with volumes-from field set interactively.
//
// ops.Args - command line parameters
// ops.Interactive - if true, set Entrypoint to ops.Args,
// if false, set Cmd to ops.Args
//
// See parameter description for DockerRunData.
func DockerExecData(ops *def.Operation, service *def.Service) (err error) {
log.WithFields(log.Fields{
"=>": ops.DataContainerName,
"args": ops.Args,
}).Info("Executing data container")
opts := configureVolumesFromContainer(ops, service)
log.WithField("image", opts.Config.Image).Info("Data container configured")
_, err = createContainer(opts)
if err != nil {
return err
}
// Clean up the container.
defer func() {
log.WithField("=>", opts.Name).Info("Removing data container")
if err2 := removeContainer(opts.Name, true, false); err2 != nil {
if os.Getenv("CIRCLE_BRANCH") == "" {
err = fmt.Errorf("Tragic! Error removing data container after executing (%v): %v", err, err2)
}
}
log.WithField("=>", opts.Name).Info("Data container removed")
}()
// Start the container.
log.WithField("=>", opts.Name).Info("Executing interactive data container")
if err = startInteractiveContainer(opts); err != nil {
return err
}
return nil
}
示例10: ContainerDisassemble
func ContainerDisassemble(containerName string) *ContainerName {
pop := strings.Split(containerName, "_")
if len(pop) < 4 {
log.WithField("=>", containerName).Debug("The marmots cannot disassemble container name")
return &ContainerName{}
}
if !(pop[0] == "eris" || pop[0] == "/eris") {
log.WithField("=>", containerName).Debug("The marmots cannot disassemble container name")
return &ContainerName{}
}
typ := pop[1]
srt := strings.Join(pop[2:len(pop)-1], "_")
num, err := strconv.Atoi(pop[len(pop)-1])
if err != nil {
log.WithField("=>", containerName).Debug("The marmots cannot disassemble container name")
return &ContainerName{}
}
// remove the leading slash docker adds
containerName = strings.Replace(containerName, "/", "", 1)
return &ContainerName{
FullName: containerName,
DockersName: "/" + containerName,
Type: typ,
Number: num,
ShortName: srt,
}
}
示例11: TestKillRmService
func TestKillRmService(t *testing.T) {
testStartService(t, servName, false)
do := def.NowDo()
do.Name = servName
do.Rm = false
do.RmD = false
do.Operations.Args = []string{servName}
log.WithField("=>", servName).Debug("Stopping service (from tests)")
if e := KillService(do); e != nil {
log.Error(e)
tests.IfExit(e)
}
testExistAndRun(t, servName, 1, true, false)
testNumbersExistAndRun(t, servName, 1, 0)
if os.Getenv("TEST_IN_CIRCLE") == "true" {
log.Warn("Testing in Circle where we don't have rm privileges. Skipping test")
return
}
do = def.NowDo()
do.Name = servName
do.Operations.Args = []string{servName}
do.File = false
do.RmD = true
log.WithField("=>", servName).Debug("Removing service (from tests)")
if e := RmService(do); e != nil {
log.Error(e)
tests.IfExit(e)
}
testExistAndRun(t, servName, 1, false, false)
testNumbersExistAndRun(t, servName, 0, 0)
}
示例12: ChangeDirectory
func ChangeDirectory(to string) {
if to == "bin" {
erisLoc, err := exec.LookPath("eris")
if err != nil {
log.Fatalf("Error finding eris binary: %v", err)
}
err = os.Chdir(filepath.Dir(erisLoc))
if err != nil {
log.Fatalf("Error changing directory: %v", err)
}
log.WithField("dir", erisLoc).Debug("Directory changed to")
} else if to == "src" {
goPath := os.Getenv("GOPATH")
if goPath == "" {
log.Fatal("You do not have $GOPATH set. Please make sure this is set and rerun the command.")
}
dir := filepath.Join(goPath, "src", "github.com", "eris-ltd", "eris-cli")
err := os.Chdir(dir)
if err != nil {
log.Fatalf("Error changing directory: %v")
}
log.WithField("dir", dir).Debug("Directory changed to")
}
}
示例13: AutoMagic
// AutoMagic will return the highest container number which would represent the most recent
// container to work on unless newCont == true in which case it would return the highest
// container number plus one.
func AutoMagic(cNum int, typ string, newCont bool) int {
log.WithField("automagic", cNum).Debug()
contns := ErisContainersByType(typ, true)
contnums := make([]int, len(contns))
for i, c := range contns {
contnums[i] = c.Number
}
// get highest container number
g := 0
for _, n := range contnums {
if n >= g {
g = n
}
}
// ensure outcomes appropriate
result := g
if newCont {
result = g + 1
}
if result == 0 {
result = 1
}
log.WithField("automagic", result).Debug()
return result
}
示例14: TestRmChain
func TestRmChain(t *testing.T) {
start(t, chainName)
do := def.NowDo()
do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
if err := services.KillService(do); err != nil {
t.Fatalf("expected service to be stopped, got %v", err)
}
do = def.NowDo()
do.Name, do.Rm, do.RmD = chainName, false, false
log.WithField("=>", do.Name).Info("Stopping chain (from tests)")
if err := KillChain(do); err != nil {
t.Fatalf("expected chain to be stopped, got %v", err)
}
if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
t.Fatalf("expecting 1 chain containers, got %v", n)
}
do = def.NowDo()
do.Name = chainName
do.RmD = true
log.WithField("=>", do.Name).Info("Removing chain (from tests)")
if err := RmChain(do); err != nil {
t.Fatalf("expected chain to be removed, got %v", err)
}
if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 0 {
t.Fatalf("expecting 0 chain containers, got %v", n)
}
}
示例15: RenameAction
func RenameAction(do *definitions.Do) error {
if do.Name == do.NewName {
return fmt.Errorf("Cannot rename to same name")
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
do.NewName = strings.Replace(do.NewName, " ", "_", -1)
act, _, err := LoadActionDefinition(do.Name)
if err != nil {
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Debug("Failed renaming action")
return err
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
log.WithField("file", do.Name).Debug("Finding action definition file")
oldFile := util.GetFileByNameAndType("actions", do.Name)
if oldFile == "" {
return fmt.Errorf("Could not find that action definition file.")
}
log.WithField("file", oldFile).Debug("Found action definition file")
// if !strings.Contains(oldFile, ActionsPath) {
// oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
// }
var newFile string
newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)
if newNameBase == do.Name {
newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
} else {
newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
newFile = strings.Replace(newFile, " ", "_", -1)
}
if newFile == oldFile {
log.Info("Not renaming the same file")
return nil
}
act.Name = strings.Replace(newNameBase, "_", " ", -1)
log.WithFields(log.Fields{
"old": act.Name,
"new": newFile,
}).Debug("Writing new action definition file")
err = WriteActionDefinitionFile(act, newFile)
if err != nil {
return err
}
log.WithField("file", oldFile).Debug("Removing old file")
os.Remove(oldFile)
return nil
}