本文整理汇总了Golang中launchpad/net/juju-core/log.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ReadHeader
func (c *Codec) ReadHeader(hdr *rpc.Header) error {
c.msg = inMsg{} // avoid any potential cross-message contamination.
var err error
if c.isLogging() {
var m json.RawMessage
err = c.conn.Receive(&m)
if err == nil {
log.Debugf("rpc/jsoncodec: <- %s", m)
err = json.Unmarshal(m, &c.msg)
} else {
log.Debugf("rpc/jsoncodec: <- error: %v (closing %v)", err, c.isClosing())
}
} else {
err = c.conn.Receive(&c.msg)
}
if err != nil {
// If we've closed the connection, we may get a spurious error,
// so ignore it.
if c.isClosing() || err == io.EOF {
return io.EOF
}
return fmt.Errorf("error receiving message: %v", err)
}
hdr.RequestId = c.msg.RequestId
hdr.Type = c.msg.Type
hdr.Id = c.msg.Id
hdr.Request = c.msg.Request
hdr.Error = c.msg.Error
hdr.ErrorCode = c.msg.ErrorCode
return nil
}
示例2: StateInfo
// StateInfo is a reusable implementation of Environ.StateInfo, available to
// providers that also use the other functionality from this file.
func StateInfo(env Environ) (*state.Info, *api.Info, error) {
st, err := LoadState(env.Storage())
if err != nil {
return nil, nil, err
}
config := env.Config()
if _, hasCert := config.CACert(); !hasCert {
return nil, nil, fmt.Errorf("no CA certificate in environment configuration")
}
// Wait for the DNS names of any of the instances
// to become available.
log.Debugf("waiting for DNS name(s) of state server instances %v", st.StateInstances)
var hostnames []string
for a := LongAttempt.Start(); len(hostnames) == 0 && a.Next(); {
insts, err := env.Instances(st.StateInstances)
if err != nil && err != ErrPartialInstances {
log.Debugf("error getting state instances: %v", err.Error())
return nil, nil, err
}
hostnames = getDNSNames(insts)
}
if len(hostnames) == 0 {
return nil, nil, fmt.Errorf("timed out waiting for mgo address from %v", st.StateInstances)
}
stateInfo, apiInfo := getStateInfo(config, hostnames)
return stateInfo, apiInfo, nil
}
示例3: WriteMessage
func (c *Codec) WriteMessage(hdr *rpc.Header, body interface{}) error {
r := &outMsg{
RequestId: hdr.RequestId,
Type: hdr.Type,
Id: hdr.Id,
Request: hdr.Request,
Error: hdr.Error,
ErrorCode: hdr.ErrorCode,
}
if hdr.IsRequest() {
r.Params = body
} else {
r.Response = body
}
if c.isLogging() {
data, err := json.Marshal(r)
if err != nil {
log.Debugf("rpc/jsoncodec: -> marshal error: %v", err)
return err
}
log.Debugf("rpc/jsoncodec: -> %s", data)
}
return c.conn.Send(r)
}
示例4: tryLock
// tryLock tries locking l.keys, one at a time, and succeeds only if it
// can lock all of them in order. The keys should be pre-sorted so that
// two-way conflicts can't happen. If any of the keys fail to be locked,
// and expiring the old lock doesn't work, tryLock undoes all previous
// locks and aborts with an error.
func (l *UpdateLock) tryLock() error {
for i, key := range l.keys {
log.Debugf("store: Trying to lock charm %s for updates...", key)
doc := bson.D{{"_id", key}, {"time", l.time}}
err := l.locks.Insert(doc)
if err == nil {
log.Debugf("store: Charm %s is now locked for updates.", key)
continue
}
if lerr, ok := err.(*mgo.LastError); ok && lerr.Code == 11000 {
log.Debugf("store: Charm %s is locked. Trying to expire lock.", key)
l.tryExpire(key)
err = l.locks.Insert(doc)
if err == nil {
log.Debugf("store: Charm %s is now locked for updates.", key)
continue
}
}
// Couldn't lock everyone. Undo previous locks.
for j := i - 1; j >= 0; j-- {
// Using time below should be unnecessary, but it's an extra check.
// Can't do anything about errors here. Lock will expire anyway.
l.locks.Remove(bson.D{{"_id", l.keys[j]}, {"time", l.time}})
}
err = maybeConflict(err)
log.Errorf("store: Can't lock charms %v for updating: %v", l.keys, err)
return err
}
return nil
}
示例5: upgradeChanged
// upgradeChanged responds to changes in the service or in the
// upgrade requests that defines which charm changes should be
// delivered as upgrades.
func (f *filter) upgradeChanged() (err error) {
if f.life != state.Alive {
log.Debugf("worker/uniter/filter: charm check skipped, unit is dying")
f.outUpgrade = nil
return nil
}
if f.upgradeFrom.url == nil {
log.Debugf("worker/uniter/filter: charm check skipped, not yet installed.")
f.outUpgrade = nil
return nil
}
if *f.upgradeAvailable.url != *f.upgradeFrom.url {
if f.upgradeAvailable.force || !f.upgradeFrom.force {
log.Debugf("worker/uniter/filter: preparing new upgrade event")
if f.upgrade == nil || *f.upgrade != *f.upgradeAvailable.url {
f.upgrade = f.upgradeAvailable.url
}
f.outUpgrade = f.outUpgradeOn
return nil
}
}
log.Debugf("worker/uniter/filter: no new charm event")
f.outUpgrade = nil
return nil
}
示例6: Run
// Run updates the configuration of a service
func (c *SetCommand) Run(ctx *cmd.Context) error {
var unvalidated = make(map[string]string)
var remove []string
contents, err := c.Config.Read(ctx)
if err != nil && err != cmd.ErrNoPath {
return err
}
if len(contents) > 0 {
if err := goyaml.Unmarshal(contents, &unvalidated); err != nil {
return err
}
} else {
unvalidated, remove, err = parse(c.Options)
if err != nil {
return err
}
}
conn, err := juju.NewConnFromName(c.EnvName)
if err != nil {
return err
}
defer conn.Close()
srv, err := conn.State.Service(c.ServiceName)
if err != nil {
return err
}
charm, _, err := srv.Charm()
if err != nil {
return err
}
// 1. Validate will convert this partial configuration
// into a full configuration by inserting charm defaults
// for missing values.
validated, err := charm.Config().Validate(unvalidated)
if err != nil {
return err
}
// 2. strip out the additional default keys added in the previous step.
validated = strip(validated, unvalidated)
cfg, err := srv.Config()
if err != nil {
return err
}
// 3. Update any keys that remain after validation and filtering.
if len(validated) > 0 {
log.Debugf("cmd/juju: updating configuration items: %v", validated)
cfg.Update(validated)
}
// 4. Delete any removed keys.
if len(remove) > 0 {
log.Debugf("cmd/juju: removing configuration items: %v", remove)
for _, k := range remove {
cfg.Delete(k)
}
}
_, err = cfg.Write()
return err
}
示例7: Kill
// Stop stops p's periodical ping and immediately report that it is dead.
func (p *Pinger) Kill() error {
p.mu.Lock()
defer p.mu.Unlock()
if p.started {
log.Debugf("state/presence: killing pinger for %q (was started)", p.beingKey)
return p.killStarted()
}
log.Debugf("state/presence: killing pinger for %q (was stopped)", p.beingKey)
return p.killStopped()
}
示例8: CharmInfo
// CharmInfo retrieves the CharmInfo value for the charm at url.
func (s *Store) CharmInfo(url *charm.URL) (info *CharmInfo, err error) {
session := s.session.Copy()
defer session.Close()
log.Debugf("store: Retrieving charm info for %s", url)
rev := url.Revision
url = url.WithRevision(-1)
charms := session.Charms()
var cdoc charmDoc
var qdoc interface{}
if rev == -1 {
qdoc = bson.D{{"urls", url}}
} else {
qdoc = bson.D{{"urls", url}, {"revision", rev}}
}
err = charms.Find(qdoc).Sort("-revision").One(&cdoc)
if err != nil {
log.Errorf("store: Failed to find charm %s: %v", url, err)
return nil, ErrNotFound
}
info = &CharmInfo{
cdoc.Revision,
cdoc.Digest,
cdoc.Sha256,
cdoc.Size,
cdoc.FileId,
cdoc.Meta,
cdoc.Config,
}
return info, nil
}
示例9: Main
// Main runs the Command specified by req, and fills in resp. A single command
// is run at a time.
func (j *Jujuc) Main(req Request, resp *Response) error {
if req.CommandName == "" {
return badReqErrorf("command not specified")
}
if !filepath.IsAbs(req.Dir) {
return badReqErrorf("Dir is not absolute")
}
c, err := j.getCmd(req.ContextId, req.CommandName)
if err != nil {
return badReqErrorf("%s", err)
}
var stdin, stdout, stderr bytes.Buffer
ctx := &cmd.Context{
Dir: req.Dir,
Stdin: &stdin,
Stdout: &stdout,
Stderr: &stderr,
}
j.mu.Lock()
defer j.mu.Unlock()
log.Infof("worker/uniter/jujuc: running hook tool %q %q", req.CommandName, req.Args)
log.Debugf("worker/uniter/jujuc: hook context id %q; dir %q", req.ContextId, req.Dir)
resp.Code = cmd.Main(c, ctx, req.Args)
resp.Stdout = stdout.Bytes()
resp.Stderr = stderr.Bytes()
return nil
}
示例10: userData
func (e *environ) userData(scfg *startInstanceParams) ([]byte, error) {
cfg := &cloudinit.MachineConfig{
StateServer: scfg.stateServer,
StateInfo: scfg.info,
StateServerCert: scfg.stateServerCert,
StateServerKey: scfg.stateServerKey,
InstanceIdAccessor: "$(curl http://169.254.169.254/1.0/meta-data/instance-id)",
ProviderType: "ec2",
DataDir: "/var/lib/juju",
Tools: scfg.tools,
MachineId: scfg.machineId,
AuthorizedKeys: e.ecfg().AuthorizedKeys(),
Config: scfg.config,
}
cloudcfg, err := cloudinit.New(cfg)
if err != nil {
return nil, err
}
data, err := cloudcfg.Render()
if err != nil {
return nil, err
}
cdata := trivial.Gzip(data)
log.Debugf("environs/ec2: ec2 user data; %d bytes: %q", len(cdata), data)
return cdata, nil
}
示例11: killWorker
func killWorker(id string, info *workerInfo) {
if info.worker != nil {
log.Debugf("worker: killing %q", id)
info.worker.Kill()
info.worker = nil
}
info.stopping = true
info.start = nil
}
示例12: Unlock
// Unlock removes the previously acquired server-side lock that prevents
// other processes from attempting to update a set of charm URLs.
func (l *UpdateLock) Unlock() {
log.Debugf("store: Unlocking charms for future updates: %v", l.keys)
defer l.locks.Database.Session.Close()
for i := len(l.keys) - 1; i >= 0; i-- {
// Using time below ensures only the proper lock is removed.
// Can't do much about errors here. Locks will expire anyway.
l.locks.Remove(bson.D{{"_id", l.keys[i]}, {"time", l.time}})
}
}
示例13: modeContext
// modeContext returns a function that implements logging and common error
// manipulation for Mode funcs.
func modeContext(name string, err *error) func() {
log.Printf("worker/uniter: %s starting", name)
return func() {
log.Debugf("worker/uniter: %s exiting", name)
switch *err {
case nil, tomb.ErrDying, worker.ErrDead:
default:
*err = errors.New(name + ": " + (*err).Error())
}
}
}
示例14: modeContext
// modeContext returns a function that implements logging and common error
// manipulation for Mode funcs.
func modeContext(name string, err *error) func() {
log.Infof("worker/uniter: %s starting", name)
return func() {
log.Debugf("worker/uniter: %s exiting", name)
switch *err {
case nil, tomb.ErrDying, worker.ErrTerminateAgent:
default:
*err = stderrors.New(name + ": " + (*err).Error())
}
}
}
示例15: upgradeChanged
// upgradeChanged responds to changes in the service or in the
// upgrade requests that defines which charm changes should be
// delivered as upgrades.
func (f *filter) upgradeChanged() (err error) {
if f.life != state.Alive {
log.Debugf("worker/uniter/filter: charm check skipped, unit is dying")
f.outUpgrade = nil
return nil
}
if *f.upgradeAvailable.url != *f.upgradeRequested.url {
if f.upgradeAvailable.force || !f.upgradeRequested.force {
log.Debugf("worker/uniter/filter: preparing new upgrade event")
if f.upgrade == nil || *f.upgrade.URL() != *f.upgradeAvailable.url {
if f.upgrade, err = f.st.Charm(f.upgradeAvailable.url); err != nil {
return err
}
}
f.outUpgrade = f.outUpgradeOn
return nil
}
}
log.Debugf("worker/uniter/filter: no new charm event")
return nil
}