예제 #1
0
func assertLogs(c *C, ctx jujuc.Context, badge string) {
	loggo.ConfigureLoggers("juju=DEBUG")
	writer := &loggo.TestWriter{}
	old_writer, err := loggo.ReplaceDefaultWriter(writer)
	c.Assert(err, IsNil)
	defer loggo.ReplaceDefaultWriter(old_writer)
	msg1 := "the chickens"
	msg2 := "are 110% AWESOME"
	com, err := jujuc.NewCommand(ctx, "juju-log")
	c.Assert(err, IsNil)
	for _, t := range commonLogTests {
		writer.Clear()
		c.Assert(err, IsNil)

		var args []string
		if t.debugFlag {
			args = []string{"--debug", msg1, msg2}
		} else {
			args = []string{msg1, msg2}
		}
		code := cmd.Main(com, &cmd.Context{}, args)
		c.Assert(code, Equals, 0)
		c.Assert(writer.Log, HasLen, 1)
		c.Assert(writer.Log[0].Level, Equals, t.level)
		c.Assert(writer.Log[0].Message, Equals, fmt.Sprintf("%s: %s %s", badge, msg1, msg2))
	}
}
예제 #2
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
}
예제 #3
0
// SetupLog set application's modules log level
func SetupLog(appModules []string, verbose bool, logfile string) error {
	var hivyModules = []string{
		"hivy",
		"hivy.security",
	}
  for _, module := range appModules {
    hivyModules = append(hivyModules, module)
  }
	logLevel := defaultLogLevel
	if verbose {
		logLevel = superVerboseLogLevel
	}

	// If a file was specified, replace console output
	if logfile != "" {
		target, err := os.OpenFile(logfile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
		fileWriter := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{})
		//loggo.RegisterWriter("logfile", file_writer, log_level)
		_, err = loggo.ReplaceDefaultWriter(fileWriter)
		if err != nil {
			return err
		}
	}

	// Central log level configuration
	for _, module := range hivyModules {
		if err := loggo.ConfigureLoggers(module + "=" + logLevel.String()); err != nil {
			return err
		}
	}

	//log.Debugf("logging level:", loggo.LoggerInfo())
	return nil
}
예제 #4
0
파일: log.go 프로젝트: rif/golang-stuff
func (t *LoggingSuite) SetUpTest(c *C) {
	loggo.ResetWriters()
	loggo.ReplaceDefaultWriter(&gocheckWriter{c})
	loggo.ResetLoggers()
	loggo.GetLogger("juju").SetLogLevel(loggo.DEBUG)
}