Esempio n. 1
0
// Start starts logging using the given Context.
func (l *Log) Start(ctx *Context) (err error) {
	var target io.Writer
	if l.Path != "" {
		path := ctx.AbsPath(l.Path)
		target, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
	} else if l.Verbose || l.Debug {
		target = ctx.Stderr
	}

	if target != nil {
		writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{})
		_, err = loggo.ReplaceDefaultWriter(writer)
		if err != nil {
			return err
		}
	} else {
		loggo.RemoveWriter("default")
	}
	if l.Verbose || l.Debug {
		level := loggo.INFO
		if l.Debug {
			level = loggo.DEBUG
		}
		// Set the level on the root logger.
		loggo.GetLogger("").SetLogLevel(level)
	}
	loggo.ConfigureLoggers(l.Config)
	return nil
}
Esempio n. 2
0
func (s *ConfigDeprecationSuite) setupLogger(c *gc.C) {
	var err error
	s.writer = &testWriter{}
	s.oldWriter, s.oldLevel, err = loggo.RemoveWriter("default")
	c.Assert(err, gc.IsNil)
	err = loggo.RegisterWriter("test", s.writer, loggo.TRACE)
	c.Assert(err, gc.IsNil)
}
Esempio n. 3
0
func (s *suite) SetUpTest(c *C) {
	var err error
	s.writer = &testWriter{}
	s.oldWriter, s.oldLevel, err = loggo.RemoveWriter("default")
	c.Assert(err, IsNil)
	err = loggo.RegisterWriter("test", s.writer, loggo.TRACE)
	c.Assert(err, IsNil)
	logger := loggo.GetLogger("juju")
	logger.SetLogLevel(loggo.TRACE)
}
Esempio n. 4
0
func (t *testSuite) TestLogger() {
	//NOTE Logfile is not implemented yet
	filename := ""
	verbose := true
	notVerbose := false

	err := SetupLog("test", verbose, filename)
	t.Nil(err)
	err = SetupLog("test", notVerbose, filename)
	t.Nil(err)
	loggo.RemoveWriter("hivy.main")
}
Esempio n. 5
0
func main() {
	// Command line flags configuration
	app := cli.NewApp()
	app.Name = "hivy"
	app.Usage = "Hive router system"
	version := beacon.StableVersion()
	app.Version = version.String()

	// The 2 firsts are hivy's, the lasts are etcd's
	app.Flags = []cli.Flag{
		cli.BoolFlag{Name: "verbose", Usage: "verbose mode"},
		cli.StringFlag{Name: "logfile", Value: "", Usage: "If specified, will write log there"},
		cli.StringFlag{Name: "listen", Value: "127.0.0.1:8080", Usage: "url to listen to"},
		cli.StringFlag{Name: "n", Value: "", Usage: "the node name (required)"},
		cli.StringFlag{Name: "C", Value: "", Usage: "Node to join"},
		cli.StringFlag{Name: "c", Value: "127.0.0.1:4001", Usage: "Etcd client ip to listen on"},
		cli.StringFlag{Name: "s", Value: "127.0.0.1:7001", Usage: "Raft server ip to listen on"},
		cli.StringFlag{Name: "d", Value: "default-node", Usage: "the directory to store etcd log and snapshot"},
		cli.BoolFlag{Name: "f", Usage: "force new etcd node configuration if existing is found (WARNING: data loss!)"},
		cli.BoolFlag{Name: "profile", Usage: "Profile requests and etcd perfs"},
	}

	// Main function as defined by the cli package
	app.Action = func(c *cli.Context) {
		// Current logger configuration
		modules := []string{"hivy.app", "hivy.worker"}
		beacon.SetupLog(modules, c.Bool("verbose"), c.String("logfile"))
		defer loggo.RemoveWriter("hivy.main")

		// Setup centralized configuration
		// Need to be a new node in the cluster to be ran
		stop := make(chan bool)
		if c.String("n") != "" {
			go beacon.RunEtcd(stop, c.String("n"), c.String("d"), c.String("c"), c.String("s"),
				c.String("C"), c.Bool("f"), c.Bool("verbose"), c.Bool("profile"))
			defer func() {
				stop <- true
			}()
		} else {
			stop = nil
		}

		// Properly shutdown the server when CTRL-C is received
		// Send true on its given channel
		beacon.CatchInterruption(stop)

		// Map routes and start up Hivy server
		serveApp(c.String("listen"), c.Bool("profile"))
	}

	app.Run(os.Args)
}
Esempio n. 6
0
func (c *SyncToolsCommand) Run(ctx *cmd.Context) error {
	// Register writer for output on screen.
	loggo.RegisterWriter("synctools", sync.NewSyncLogWriter(ctx.Stdout, ctx.Stderr), loggo.INFO)
	defer loggo.RemoveWriter("synctools")
	// Prepare syncing.
	sctx := &sync.SyncContext{
		EnvName:      c.EnvName,
		AllVersions:  c.allVersions,
		DryRun:       c.dryRun,
		PublicBucket: c.publicBucket,
		Dev:          c.dev,
		Source:       c.source,
	}
	return syncTools(sctx)
}
Esempio n. 7
0
// ensureToolsAvailability verifies the tools are available. If no tools are
// found, it will automatically synchronize them.
func (c *BootstrapCommand) ensureToolsAvailability(env environs.Environ, ctx *cmd.Context) error {
	// Capture possible logging while syncing and write it on the screen.
	loggo.RegisterWriter("bootstrap", sync.NewSyncLogWriter(ctx.Stdout, ctx.Stderr), loggo.INFO)
	defer loggo.RemoveWriter("bootstrap")

	// Try to find bootstrap tools.
	_, err := environs.FindBootstrapTools(env, c.Constraints)
	if errors.IsNotFoundError(err) {
		// Not tools available, so synchronize.
		sctx := &sync.SyncContext{
			EnvName: c.EnvName,
			Source:  c.Source,
		}
		if err = syncTools(sctx); err != nil {
			return err
		}
		// Synchronization done, try again.
		_, err = environs.FindBootstrapTools(env, c.Constraints)
	} else if err != nil {
		return err
	}
	return err
}
Esempio n. 8
0
func (s *ConfigDeprecationSuite) resetLogger(c *gc.C) {
	_, _, err := loggo.RemoveWriter("test")
	c.Assert(err, gc.IsNil)
	err = loggo.RegisterWriter("default", s.oldWriter, s.oldLevel)
	c.Assert(err, gc.IsNil)
}
Esempio n. 9
0
func (s *suite) TearDownTest(c *C) {
	_, _, err := loggo.RemoveWriter("test")
	c.Assert(err, IsNil)
	err = loggo.RegisterWriter("default", s.oldWriter, s.oldLevel)
	c.Assert(err, IsNil)
}