func (log *Log) Start(ctx *Context) error {
	if log.Verbose && log.Quiet {
		return fmt.Errorf(`"verbose" and "quiet" flags clash, please use one or the other, not both`)
	}
	ctx.quiet = log.Quiet
	ctx.verbose = log.Verbose
	if log.Path != "" {
		path := ctx.AbsPath(log.Path)
		target, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
		writer := log.GetLogWriter(target)
		err = loggo.RegisterWriter("logfile", writer)
		if err != nil {
			return err
		}
	}
	level := loggo.WARNING
	if log.ShowLog {
		level = loggo.INFO
	}
	if log.Debug {
		log.ShowLog = true
		level = loggo.DEBUG
		// override quiet or verbose if set, this way all the information goes
		// to the log file.
		ctx.quiet = true
		ctx.verbose = false
	}

	if log.ShowLog {
		// We replace the default writer to use ctx.Stderr rather than os.Stderr.
		writer := log.GetLogWriter(ctx.Stderr)
		_, err := loggo.ReplaceDefaultWriter(writer)
		if err != nil {
			return err
		}
	} else {
		loggo.RemoveWriter("default")
		// Create a simple writer that doesn't show filenames, or timestamps,
		// and only shows warning or above.
		writer := NewWarningWriter(ctx.Stderr)
		err := loggo.RegisterWriter("warning", writer)
		if err != nil {
			return err
		}
	}
	// Set the level on the root logger.
	root := loggo.GetLogger("")
	root.SetLogLevel(level)
	// Override the logging config with specified logging config.
	loggo.ConfigureLoggers(log.Config)
	return nil
}
// Start starts logging using the given Context.
Start starts logging using the given Context.
// Start starts logging using the given Context .
func (log *Log) Start(ctx *Context) error {
	if log.Verbose && log.Quiet {
		return fmt.Errorf(`"verbose" and "quiet" flags clash, please use one or the other, not both`)
	}
	ctx.quiet = log.Quiet
	ctx.verbose = log.Verbose
	if log.Path != "" {
		path := ctx.AbsPath(log.Path)
		target, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
		writer := log.GetLogWriter(target)
		err = loggo.RegisterWriter("logfile", writer)
		if err != nil {
			return err
		}
	}
	level := loggo.WARNING
	if log.ShowLog {
		level = loggo.INFO
	}
	if log.Debug {
		log.ShowLog = true
		level = loggo.DEBUG
		ctx.quiet = true
		ctx.verbose = false
	}
	if log.ShowLog {
		writer := log.GetLogWriter(ctx.Stderr)
		_, err := loggo.ReplaceDefaultWriter(writer)
		if err != nil {
			return err
		}
	} else {
		loggo.RemoveWriter("default")
		writer := NewWarningWriter(ctx.Stderr)
		err := loggo.RegisterWriter("warning", writer)
		if err != nil {
			return err
		}
	}
	root := loggo.GetLogger("")
	root.SetLogLevel(level)
	loggo.ConfigureLoggers(log.Config)
	return nil
}
func ( log * Log ) Start ( ctx * Context ) error { if log . Verbose && log . Quiet { return fmt . Errorf ( `"verbose" and "quiet" flags clash, please use one or the other, not both` ) } ctx . quiet = log . Quiet ctx . verbose = log . Verbose if log . Path != " " { path := ctx . AbsPath ( log . Path ) target , err := os . OpenFile ( path , os . O_WRONLY | os . O_APPEND | os . O_CREATE , 0644 ) if err != nil { return err } writer := log . GetLogWriter ( target ) err = loggo . RegisterWriter ( " " , writer ) if err != nil { return err } } level := loggo . WARNING if log . ShowLog { level = loggo . INFO } if log . Debug { log . ShowLog = true level = loggo . DEBUG ctx . quiet = true ctx . verbose = false } if log . ShowLog { writer := log . GetLogWriter ( ctx . Stderr ) _ , err := loggo . ReplaceDefaultWriter ( writer ) if err != nil { return err } } else { loggo . RemoveWriter ( " " ) writer := NewWarningWriter ( ctx . Stderr ) err := loggo . RegisterWriter ( " " , writer ) if err != nil { return err } } root := loggo . GetLogger ( " " ) root . SetLogLevel ( level ) loggo . ConfigureLoggers ( log . Config ) return nil }
Start starts logging using the given Context.
Start starts logging using the given Context .
// override quiet or verbose if set, this way all the information goes // to the log file. // We replace the default writer to use ctx.Stderr rather than os.Stderr. // Create a simple writer that doesn't show filenames, or timestamps, // and only shows warning or above. // Set the level on the root logger. // Override the logging config with specified logging config.