PKGBUILD/cmd/logger/add.go

55 lines
1003 B
Go

package logger
import (
"log"
"git.cryptic.systems/fh-trier/go-flucky/pkg/logger"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra"
)
var enabled bool
var addLoggerCmd = &cobra.Command{
Use: "add",
Short: "Add internal logger",
Args: cobra.ExactArgs(2),
Aliases: []string{"append"},
Example: "flucky logger add temperature /var/log/flucky/temperature.log",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
fc, err := config.Read(cfg)
if err != nil {
log.Fatalln(err)
}
// loggertype, err := logger.StringToLoggerType(args[0])
// if err != nil {
// log.Fatalln(err)
// }
logvalue, err := logger.StringToLogValue(args[0])
if err != nil {
log.Fatalln(err)
}
err = fc.AddLogFile(args[1], logvalue)
if err != nil {
log.Fatalln(err)
}
// save new configuration
err = config.Write(fc, cfg)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
loggerCmd.AddCommand(addLoggerCmd)
}