本文整理匯總了Golang中github.com/eris-ltd/eris-cli/Godeps/_workspace/src/github.com/Sirupsen/logrus.WithFields函數的典型用法代碼示例。如果您正苦於以下問題:Golang WithFields函數的具體用法?Golang WithFields怎麽用?Golang WithFields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了WithFields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestInspectData
func TestInspectData(t *testing.T) {
testCreateDataByImport(t, dataName)
defer testKillDataCont(t, dataName)
do := definitions.NowDo()
do.Name = dataName
do.Operations.Args = []string{"name"}
do.Operations.ContainerNumber = 1
log.WithFields(log.Fields{
"data container": do.Name,
"args": do.Operations.Args,
}).Info("Inspecting data (from tests)")
if err := InspectData(do); err != nil {
log.Error(err)
t.FailNow()
}
do = definitions.NowDo()
do.Name = dataName
do.Operations.Args = []string{"config.network_disabled"}
do.Operations.ContainerNumber = 1
log.WithFields(log.Fields{
"data container": do.Name,
"args": do.Operations.Args,
}).Info("Inspecting data (from tests)")
if err := InspectData(do); err != nil {
log.Error(err)
t.Fail()
}
}
示例2: 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")
}
示例3: TestRenameChain
func TestRenameChain(t *testing.T) {
aChain := "hichain"
rename1 := "niahctset"
rename2 := chainName
testNewChain(aChain)
defer testKillChain(t, rename2)
do := def.NowDo()
do.Name = aChain
do.NewName = rename1
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Info("Renaming chain (from tests)")
if e := RenameChain(do); e != nil {
tests.IfExit(e)
}
testExistAndRun(t, rename1, true, true)
do = def.NowDo()
do.Name = rename1
do.NewName = rename2
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Info("Renaming chain (from tests)")
if e := RenameChain(do); e != nil {
tests.IfExit(e)
}
testExistAndRun(t, chainName, true, true)
}
示例4: TestRenameAction
func TestRenameAction(t *testing.T) {
testExist(t, newName, false)
testExist(t, oldName, true)
do := definitions.NowDo()
do.Name = oldName
do.NewName = newName
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Info("Renaming action (from tests)")
if err := RenameAction(do); err != nil {
log.Error(err)
t.Fail()
}
testExist(t, newName, true)
testExist(t, oldName, false)
do = definitions.NowDo()
do.Name = newName
do.NewName = oldName
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Info("Renaming action (from tests)")
if err := RenameAction(do); err != nil {
log.Error(err)
t.Fail()
}
testExist(t, newName, false)
testExist(t, oldName, true)
}
示例5: MoveOutOfDirAndRmDir
func MoveOutOfDirAndRmDir(src, dest string) error {
log.WithFields(log.Fields{
"from": src,
"to": dest,
}).Info("Move all files/dirs out of a dir and `rm -fr` that dir")
toMove, err := filepath.Glob(filepath.Join(src, "*"))
if err != nil {
return err
}
if len(toMove) == 0 {
log.Debug("No files to move")
}
for _, f := range toMove {
t := filepath.Join(dest, filepath.Base(f))
log.WithFields(log.Fields{
"from": f,
"to": t,
}).Debug("Moving")
// using a copy (read+write) strategy to get around swap partitions and other
// problems that cause a simple rename strategy to fail. it is more io overhead
// to do this, but for now that is preferable to alternative solutions.
Copy(f, t)
}
log.WithField("=>", src).Info("Removing directory")
err = os.RemoveAll(src)
if err != nil {
return err
}
return nil
}
示例6: TestExistAndRun
func TestExistAndRun(name, t string, contNum int, toExist, toRun bool) error {
log.WithFields(log.Fields{
"=>": name,
"running": toRun,
"existing": toExist,
}).Info("Checking container")
if existing := FindContainer(name, t, contNum, false); existing != toExist {
log.WithFields(log.Fields{
"=>": name,
"expected": toExist,
"got": existing,
}).Info("Checking container existing")
return ErrContainerExistMismatch
}
if running := FindContainer(name, t, contNum, true); running != toRun {
log.WithFields(log.Fields{
"=>": name,
"expected": toExist,
"got": running,
}).Info("Checking container running")
return ErrContainerRunMismatch
}
return nil
}
示例7: TestInspectService
func TestInspectService(t *testing.T) {
testStartService(t, servName, false)
defer testKillService(t, servName, true)
do := def.NowDo()
do.Name = servName
do.Operations.Args = []string{"name"}
do.Operations.ContainerNumber = 1
log.WithFields(log.Fields{
"=>": fmt.Sprintf("%s:%d", servName, do.Operations.ContainerNumber),
"args": do.Operations.Args,
}).Debug("Inspect service (from tests)")
e := InspectService(do)
if e != nil {
log.Infof("Error inspecting service: %v", e)
tests.IfExit(e)
}
do = def.NowDo()
do.Name = servName
do.Operations.Args = []string{"config.user"}
do.Operations.ContainerNumber = 1
log.WithFields(log.Fields{
"=>": servName,
"args": do.Operations.Args,
}).Debug("Inspect service (from tests)")
e = InspectService(do)
if e != nil {
log.Infof("Error inspecting service: %v", e)
tests.IfExit(e)
}
}
示例8: TestNewService
func TestNewService(t *testing.T) {
do := def.NowDo()
servName := "keys"
do.Name = servName
do.Operations.Args = []string{"quay.io/eris/keys"}
log.WithFields(log.Fields{
"=>": do.Name,
"args": do.Operations.Args,
}).Debug("Creating a new service (from tests)")
e := NewService(do)
if e != nil {
log.Error(e)
tests.IfExit(e)
}
do = def.NowDo()
do.Operations.Args = []string{servName}
log.WithFields(log.Fields{
"container number": do.Operations.ContainerNumber,
"args": do.Operations.Args,
}).Debug("Starting service (from tests)")
e = StartService(do)
if e != nil {
log.Error(e)
tests.IfExit(e)
}
testExistAndRun(t, servName, 1, true, true)
testNumbersExistAndRun(t, servName, 1, 1)
testKillService(t, servName, true)
testExistAndRun(t, servName, 1, false, false)
}
示例9: TestLoadServiceDefinition
func TestLoadServiceDefinition(t *testing.T) {
var e error
srv, e = loaders.LoadServiceDefinition(servName, true, 1)
if e != nil {
log.Error(e)
tests.IfExit(e)
}
if srv.Name != servName {
log.WithFields(log.Fields{
"expected": servName,
"got": srv.Name,
}).Error("Improper name on load")
}
if srv.Service.Name != servName {
log.WithFields(log.Fields{
"expected": servName,
"got": srv.Service.Name,
}).Error("Improper service name on load")
tests.IfExit(e)
}
if !srv.Service.AutoData {
log.Error("data_container not properly read on load")
tests.IfExit(e)
}
if srv.Operations.DataContainerName == "" {
log.Error("data_container_name not set")
tests.IfExit(e)
}
}
示例10: 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
}
示例11: StartService
func StartService(do *definitions.Do) (err error) {
var services []*definitions.ServiceDefinition
do.Operations.Args = append(do.Operations.Args, do.ServicesSlice...)
log.WithField("args", do.Operations.Args).Info("Building services group")
for _, srv := range do.Operations.Args {
s, e := BuildServicesGroup(srv, do.Operations.ContainerNumber)
if e != nil {
return e
}
services = append(services, s...)
}
// [csk]: controls for ops reconciliation, overwrite will, e.g., merge the maps and stuff
for _, s := range services {
util.Merge(s.Operations, do.Operations)
}
log.Debug("Preparing to build chain")
for _, s := range services {
log.WithFields(log.Fields{
"name": s.Name,
"dependencies": s.Dependencies,
"links": s.Service.Links,
"volumes from": s.Service.VolumesFrom,
}).Debug()
// Spacer.
log.Debug()
}
services, err = BuildChainGroup(do.ChainName, services)
if err != nil {
return err
}
log.Debug("Checking services after build chain")
for _, s := range services {
log.WithFields(log.Fields{
"name": s.Name,
"dependencies": s.Dependencies,
"links": s.Service.Links,
"volumes from": s.Service.VolumesFrom,
}).Debug()
// Spacer.
log.Debug()
}
// NOTE: the top level service should be at the end of the list
topService := services[len(services)-1]
topService.Service.Environment = append(topService.Service.Environment, do.Env...)
topService.Service.Links = append(topService.Service.Links, do.Links...)
services[len(services)-1] = topService
return StartGroup(services)
}
示例12: RegisterChain
func RegisterChain(do *definitions.Do) error {
// do.Name is mandatory
if do.Name == "" {
return fmt.Errorf("RegisterChain requires a chainame")
}
etcbChain := do.ChainID
do.ChainID = do.Name
// NOTE: registration expects you to have the data container
if !util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
return fmt.Errorf("Registration requires you to have a data container for the chain. Could not find data for %s", do.Name)
}
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
log.WithField("image", chain.Service.Image).Debug("Chain loaded")
// set chainid and other vars
envVars := []string{
fmt.Sprintf("CHAIN_ID=%s", do.ChainID), // of the etcb chain
fmt.Sprintf("PUBKEY=%s", do.Pubkey), // pubkey to register chain with
fmt.Sprintf("ETCB_CHAIN_ID=%s", etcbChain), // chain id of the etcb chain
fmt.Sprintf("NODE_ADDR=%s", do.Gateway), // etcb node to send the register tx to
fmt.Sprintf("NEW_P2P_SEEDS=%s", do.Operations.Args[0]), // seeds to register for the chain // TODO: deal with multi seed (needs support in tendermint)
}
envVars = append(envVars, do.Env...)
log.WithFields(log.Fields{
"environment": envVars,
"links": do.Links,
}).Debug("Registering chain with")
chain.Service.Environment = append(chain.Service.Environment, envVars...)
chain.Service.Links = append(chain.Service.Links, do.Links...)
if err := bootDependencies(chain, do); err != nil {
return err
}
log.WithFields(log.Fields{
"=>": chain.Service.Name,
"image": chain.Service.Image,
}).Debug("Performing chain container start")
chain.Operations = loaders.LoadDataDefinition(chain.Service.Name, do.Operations.ContainerNumber)
chain.Operations.Args = []string{loaders.ErisChainRegister}
_, err = perform.DockerRunData(chain.Operations, chain.Service)
return err
}
示例13: 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
}
示例14: setAppType
func setAppType(app *definitions.Contracts, name, command, typ string) error {
var t string
log.WithFields(log.Fields{
"task": command,
"type": typ,
"app": name,
}).Debug("Setting app type")
if typ != "" {
t = typ
} else {
switch command {
case "test":
t = app.TestType
case "deploy":
t = app.DeployType
}
}
switch t {
case "embark":
app.AppType = definitions.EmbarkApp()
case "sunit":
app.AppType = definitions.SUnitApp()
case "manual":
app.AppType = definitions.GulpApp()
default:
app.AppType = definitions.EPMApp()
}
log.WithField("app type", app.AppType.Name).Debug()
return nil
}
示例15: Migrate
func Migrate(dirsToMigrate map[string]string) error {
for depDir, newDir := range dirsToMigrate {
if !DoesDirExist(depDir) && !DoesDirExist(newDir) {
return fmt.Errorf("neither deprecated (%s) or new (%s) exists. please run `init` prior to `update`\n", depDir, newDir)
} else if DoesDirExist(depDir) && !DoesDirExist(newDir) { //never updated, just rename dirs
if err := os.Rename(depDir, newDir); err != nil {
return err
}
log.WithFields(log.Fields{
"from": depDir,
"to": newDir,
}).Warn("Directory migration successful")
} else if DoesDirExist(depDir) && DoesDirExist(newDir) { //both exist, better check what's in them
if err := checkFileNamesAndMigrate(depDir, newDir); err != nil {
return err
}
// [csk] once the files are migrated we need to remove the dir or
// the DoesDirExist function will return.
if err := os.Remove(depDir); err != nil {
return err
}
} else { //should never throw
return fmt.Errorf("unknown and unresolveable conflict between directory to deprecate (%s) and new directory (%s)\n", depDir, newDir)
}
if DoesDirExist(depDir) {
return fmt.Errorf("deprecated directory (%s) still exists, something went wrong", depDir)
}
}
return nil
}