Skip to content

Commit

Permalink
Add syslog logging target, rework logging interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Mar 14, 2013
1 parent 0239f00 commit 1501128
Show file tree
Hide file tree
Showing 65 changed files with 530 additions and 310 deletions.
9 changes: 0 additions & 9 deletions .bzrignore

This file was deleted.

2 changes: 1 addition & 1 deletion charm/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (zp *zipPacker) visit(path string, fi os.FileInfo, err error) error {
if filepath.Dir(relpath) == "hooks" {
hookName := filepath.Base(relpath)
if _, ok := zp.hooks[hookName]; !fi.IsDir() && ok && mode&0100 == 0 {
log.Printf("charm: WARNING: making %q executable in charm", path)
log.Warningf("charm: making %q executable in charm", path)
perm = perm | 0100
}
}
Expand Down
8 changes: 4 additions & 4 deletions charm/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (s *DirSuite) TestBundleTo(c *C) {

// Bug #864164: Must complain if charm hooks aren't executable
func (s *DirSuite) TestBundleToWithNonExecutableHooks(c *C) {
orig := log.Target
log.Target = c
defer func() { log.Target = orig }()
orig := log.Local
log.Local = c
defer func() { log.Local = orig }()
hooks := []string{"install", "start", "config-changed", "upgrade-charm", "stop"}
for _, relName := range []string{"foo", "bar", "self"} {
for _, kind := range []string{"joined", "changed", "departed", "broken"} {
Expand All @@ -139,7 +139,7 @@ func (s *DirSuite) TestBundleToWithNonExecutableHooks(c *C) {
tlog := c.GetTestLog()
for _, hook := range hooks {
fullpath := filepath.Join(dir.Path, "hooks", hook)
exp := fmt.Sprintf(`^(.|\n)*JUJU charm: WARNING: making "%s" executable in charm(.|\n)*$`, fullpath)
exp := fmt.Sprintf(`^(.|\n)*WARNING: charm: making "%s" executable in charm(.|\n)*$`, fullpath)
c.Assert(tlog, Matches, exp, Commentf("hook %q was not made executable", fullpath))
}

Expand Down
4 changes: 2 additions & 2 deletions charm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *store) info(curl *URL) (rev int, digest string, err error) {
return
}
for _, w := range info.Warnings {
log.Printf("charm: WARNING: charm store reports for %q: %s", key, w)
log.Warningf("charm: charm store reports for %q: %s", key, w)
}
if info.Errors != nil {
err = fmt.Errorf(
Expand Down Expand Up @@ -210,7 +210,7 @@ func (r *LocalRepository) Get(curl *URL) (Charm, error) {
}
chPath := filepath.Join(path, info.Name())
if ch, err := Read(chPath); err != nil {
log.Printf("charm: WARNING: failed to load charm at %q: %s", chPath, err)
log.Warningf("charm: failed to load charm at %q: %s", chPath, err)
} else if ch.Meta().Name == curl.Name {
if ch.Revision() == curl.Revision {
return ch, nil
Expand Down
14 changes: 7 additions & 7 deletions charm/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func (s *StoreSuite) TestError(c *C) {
}

func (s *StoreSuite) TestWarning(c *C) {
orig := log.Target
log.Target = c
defer func() { log.Target = orig }()
orig := log.Local
log.Local = c
defer func() { log.Local = orig }()
curl := charm.MustParseURL("cs:series/unwise")
expect := `.* JUJU charm: WARNING: charm store reports for "cs:series/unwise": foolishness` + "\n"
expect := `.* WARNING: charm: charm store reports for "cs:series/unwise": foolishness` + "\n"
r, err := s.store.Latest(curl)
c.Assert(r, Equals, 23)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -312,9 +312,9 @@ func (s *LocalRepoSuite) TestLogsErrors(c *C) {
c.Assert(err, IsNil)
c.Assert(ch.Revision(), Equals, 1)
c.Assert(c.GetTestLog(), Matches, `
.* JUJU charm: WARNING: failed to load charm at ".*/series/blah": .*
.* JUJU charm: WARNING: failed to load charm at ".*/series/blah.charm": .*
.* JUJU charm: WARNING: failed to load charm at ".*/series/upgrade2": .*
.* WARNING: charm: failed to load charm at ".*/series/blah": .*
.* WARNING: charm: failed to load charm at ".*/series/blah.charm": .*
.* WARNING: charm: failed to load charm at ".*/series/upgrade2": .*
`[1:])
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/builddb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func main() {
log.Target = corelog.New(os.Stdout, "", corelog.LstdFlags)
log.Local = corelog.New(os.Stdout, "", corelog.LstdFlags)
if err := build(); err != nil {
corelog.Fatalf("error: %v", err)
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func build() error {
return err
}

log.Printf("builddb: Waiting for unit to reach %q status...", state.UnitStarted)
log.Infof("builddb: Waiting for unit to reach %q status...", state.UnitStarted)
unit := units[0]
last, info, err := unit.Status()
if err != nil {
Expand All @@ -79,15 +79,15 @@ func build() error {
if !ok {
return fmt.Errorf("cannot retrieve files: build unit lacks a public-address")
}
log.Printf("builddb: Built files published at http://%s", addr)
log.Printf("builddb: Remember to destroy the environment when you're done...")
log.Infof("builddb: Built files published at http://%s", addr)
log.Infof("builddb: Remember to destroy the environment when you're done...")
return nil
}

func logStatus(status state.UnitStatus, info string) {
if info == "" {
log.Printf("builddb: Unit status is %q", status)
log.Infof("builddb: Unit status is %q", status)
} else {
log.Printf("builddb: Unit status is %q: %s", status, info)
log.Infof("builddb: Unit status is %q: %s", status, info)
}
}
2 changes: 1 addition & 1 deletion cmd/charmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags)
log.Local = stdlog.New(os.Stdout, "", stdlog.LstdFlags)
err := serve()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/charmload/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func main() {
log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags)
log.Local = stdlog.New(os.Stdout, "", stdlog.LstdFlags)
err := load()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func Main(c Command, ctx *Context, args []string) int {
}
if err := c.Run(ctx); err != nil {
if err != ErrSilent {
log.Printf("%s command failed: %s\n", c.Info().Name, err)
log.Errf("%s command failed: %s\n", c.Info().Name, err)
fmt.Fprintf(ctx.Stderr, "error: %v\n", err)
}
return 1
Expand Down
30 changes: 30 additions & 0 deletions cmd/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
stdlog "log"
"net"
"time"
)

func runSyslog(c net.PacketConn, done chan<- string) {
var buf [4096]byte
var rcvd string = ""
for {
n, _, err := c.ReadFrom(buf[0:])
if err != nil || n == 0 {
break
}
rcvd += string(buf[0:n])
}
done <- rcvd
}

func StartTestSysLogServer(done chan<- string) string {
c, e := net.ListenPacket("udp", "127.0.0.1:0")
if e != nil {
stdlog.Fatalf("net.ListenPacket failed udp :0 %v", e)
}
c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
go runSyslog(c, done)
return c.LocalAddr().String()
}
4 changes: 2 additions & 2 deletions cmd/juju/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (s *MainSuite) TestActualRunJujuArgsBeforeCommand(c *C) {
c.Assert(out, Equals, "error: "+msg+"\n")
content, err := ioutil.ReadFile(logpath)
c.Assert(err, IsNil)
fullmsg := fmt.Sprintf(`(.|\n)*JUJU juju bootstrap command failed: %s\n`, msg)
fullmsg := fmt.Sprintf(`(.|\n)*ERROR: juju bootstrap command failed: %s\n`, msg)
c.Assert(string(content), Matches, fullmsg)
}

Expand All @@ -174,7 +174,7 @@ func (s *MainSuite) TestActualRunJujuArgsAfterCommand(c *C) {
c.Assert(out, Equals, "error: "+msg+"\n")
content, err := ioutil.ReadFile(logpath)
c.Assert(err, IsNil)
fullmsg := fmt.Sprintf(`(.|\n)*JUJU juju bootstrap command failed: %s\n`, msg)
fullmsg := fmt.Sprintf(`(.|\n)*ERROR: juju bootstrap command failed: %s\n`, msg)
c.Assert(string(content), Matches, fullmsg)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func (c *SSHCommand) Run(ctx *cmd.Context) error {
func (c *SSHCommon) hostFromTarget(target string) (string, error) {
// is the target the id of a machine ?
if state.IsMachineId(target) {
log.Printf("cmd/juju: looking up address for machine %s...", target)
log.Infof("cmd/juju: looking up address for machine %s...", target)
// TODO(dfc) maybe we should have machine.PublicAddress() ?
return c.machinePublicAddress(target)
}
// maybe the target is a unit ?
if state.IsUnitName(target) {
log.Printf("cmd/juju: Looking up address for unit %q...", c.Target)
log.Infof(fmt.Sprintf("cmd/juju: Looking up address for unit %q...", c.Target))
unit, err := c.State.Unit(target)
if err != nil {
return "", err
Expand Down
14 changes: 7 additions & 7 deletions cmd/jujud/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ waiting:
select {
case info := <-done:
if info.err != nil {
log.Printf("cmd/jujud: %s: %v", tasks[info.index], info.err)
log.Errf("cmd/jujud: %s: %v", tasks[info.index], info.err)
logged[info.index] = true
err = info.err
break waiting
Expand All @@ -85,7 +85,7 @@ waiting:
for i, t := range tasks {
err1 := t.Stop()
if !logged[i] && err1 != nil {
log.Printf("cmd/jujud: %s: %v", t, err1)
log.Errf("cmd/jujud: %s: %v", t, err1)
logged[i] = true
}
if moreImportant(err1, err) {
Expand Down Expand Up @@ -131,25 +131,25 @@ type Agent interface {
// runLoop repeatedly calls runOnce until it returns worker.ErrDead or
// an upgraded error, or a value is received on stop.
func runLoop(runOnce func() error, stop <-chan struct{}) error {
log.Printf("cmd/jujud: agent starting")
log.Noticef("cmd/jujud: agent starting")
for {
err := runOnce()
if err == worker.ErrDead {
log.Printf("cmd/jujud: entity is dead")
log.Noticef("cmd/jujud: entity is dead")
return nil
}
if isFatal(err) {
return err
}
if err == nil {
log.Printf("cmd/jujud: agent died with no error")
log.Alertf("cmd/jujud: agent died with no error")
} else {
log.Printf("cmd/jujud: %v", err)
log.Errf("cmd/jujud: %v", err)
}
if !isleep(retryDelay, stop) {
return nil
}
log.Printf("cmd/jujud: rerunning agent")
log.Noticef("cmd/jujud: rerunning agent")
}
panic("unreachable")
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/jujud/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (a *MachineAgent) Run(_ *cmd.Context) error {
if err := a.Conf.read(state.MachineEntityName(a.MachineId)); err != nil {
return err
}
defer log.Printf("cmd/jujud: machine agent exiting")
defer log.Noticef("cmd/jujud: machine agent exiting")
defer a.tomb.Done()

// We run the API server worker first, because we may
Expand Down Expand Up @@ -101,7 +101,7 @@ func (a *MachineAgent) Run(_ *cmd.Context) error {

func (a *MachineAgent) RunOnce(st *state.State, e AgentState) error {
m := e.(*state.Machine)
log.Printf("cmd/jujud: jobs for machine agent: %v", m.Jobs())
log.Infof("cmd/jujud: jobs for machine agent: %v", m.Jobs())
tasks := []task{NewUpgrader(st, m, a.Conf.DataDir)}
for _, j := range m.Jobs() {
switch j {
Expand All @@ -116,7 +116,7 @@ func (a *MachineAgent) RunOnce(st *state.State, e AgentState) error {
// Ignore because it's started independently.
continue
default:
log.Printf("cmd/jujud: ignoring unknown job %q", j)
log.Infof("cmd/jujud: ignoring unknown job %q", j)
}
}
return runTasks(a.tomb.Dying(), tasks...)
Expand Down Expand Up @@ -172,15 +172,15 @@ func (a *MachineAgent) maybeRunAPIServerOnce(conf *agent.Conf) error {
if len(conf.StateServerCert) == 0 || len(conf.StateServerKey) == 0 {
return &fatalError{"configuration does not have state server cert/key"}
}
log.Printf("cmd/jujud: running API server job")
log.Infof("cmd/jujud: running API server job")
srv, err := apiserver.NewServer(st, fmt.Sprintf(":%d", conf.APIPort), conf.StateServerCert, conf.StateServerKey)
if err != nil {
return err
}
select {
case <-a.tomb.Dying():
case <-srv.Dead():
log.Printf("jujud: API server has died: %v", srv.Stop())
log.Noticef("jujud: API server has died: %v", srv.Stop())
}
return srv.Stop()
}
2 changes: 1 addition & 1 deletion cmd/jujud/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (a *UnitAgent) Run(ctx *cmd.Context) error {
if err := a.Conf.read(state.UnitEntityName(a.UnitName)); err != nil {
return err
}
defer log.Printf("cmd/jujud: unit agent exiting")
defer log.Noticef("cmd/jujud: unit agent exiting")
defer a.tomb.Done()
err := RunAgentLoop(a.Conf.Conf, a)
if ug, ok := err.(*UpgradeReadyError); ok {
Expand Down
Loading

0 comments on commit 1501128

Please sign in to comment.