Exemplo n.º 1
0
func configureTargets() io.Writer {
	if viper.IsSet("log.targets") {
		var (
			writers    []io.Writer
			logTargets []logTarget
		)
		if err := mapstructure.Decode(viper.Get("log.targets"), &logTargets); err != nil {
			panic(fmt.Errorf("Failed to process log targets: %s", err))
		}
		for _, target := range logTargets {
			switch target.Type {
			case "os":
				if target.Target == "stdout" {
					writers = append(writers, output.Stdout())
				} else if target.Target == "stderr" {
					writers = append(writers, output.Stderr())
				}
			case "file":
				file, err := os.OpenFile(target.Target, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
				if err != nil {
					if os.IsNotExist(err) {
						file, err = os.Create(target.Target)
						if err != nil {
							panic(fmt.Errorf("Failed creating a file log target: %s", err))
						}
					} else {
						panic(err)
					}
				}
				writers = append(writers, file)
			}
		}

		return io.MultiWriter(writers...)
	}

	return output.Stdout()
}
Exemplo n.º 2
0
package cli

import (
	"github.com/bbuck/dragon-mud/info"
	"github.com/bbuck/dragon-mud/output"
	"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
	Use:   "version",
	Short: "Display the version of the DragonMUD server",
	Run: func(cmd *cobra.Command, args []string) {
		output.Stdout().PlainPrintln(info.Version)
	},
}

func init() {
	RootCmd.AddCommand(versionCmd)
}