How to use initLogger method of cmd Package

Best Gauge code snippet using cmd.initLogger

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "flag"4 "fmt"5 "github.com/op/go-logging"6 "log"7 "os"8 "os/signal"9 "syscall"10 _ "unsafe"11 "x-ui/config"12 "x-ui/database"13 "x-ui/logger"14 "x-ui/v2ui"15 "x-ui/web"16 "x-ui/web/global"17 "x-ui/web/service"18)19func runWebServer() {20 log.Printf("%v %v", config.GetName(), config.GetVersion())21 switch config.GetLogLevel() {22 case config.Debug:23 logger.InitLogger(logging.DEBUG)24 case config.Info:25 logger.InitLogger(logging.INFO)26 case config.Warn:27 logger.InitLogger(logging.WARNING)28 case config.Error:29 logger.InitLogger(logging.ERROR)30 default:31 log.Fatal("unknown log level:", config.GetLogLevel())32 }33 err := database.InitDB(config.GetDBPath())34 if err != nil {35 log.Fatal(err)36 }37 var server *web.Server38 server = web.NewServer()39 global.SetWebServer(server)40 err = server.Start()41 if err != nil {42 log.Println(err)43 return44 }45 sigCh := make(chan os.Signal, 1)46 signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL)47 for {48 sig := <-sigCh49 switch sig {50 case syscall.SIGHUP:51 err := server.Stop()52 if err != nil {53 logger.Warning("stop server err:", err)54 }55 server = web.NewServer()56 global.SetWebServer(server)57 err = server.Start()58 if err != nil {59 log.Println(err)60 return61 }62 default:63 server.Stop()64 return65 }66 }67}68func resetSetting() {69 err := database.InitDB(config.GetDBPath())70 if err != nil {71 fmt.Println(err)72 return73 }74 settingService := service.SettingService{}75 err = settingService.ResetSettings()76 if err != nil {77 fmt.Println("reset setting failed:", err)78 } else {79 fmt.Println("reset setting success")80 }81}82func updateSetting(port int, username string, password string) {83 err := database.InitDB(config.GetDBPath())84 if err != nil {85 fmt.Println(err)86 return87 }88 settingService := service.SettingService{}89 if port > 0 {90 err := settingService.SetPort(port)91 if err != nil {92 fmt.Println("set port failed:", err)93 } else {94 fmt.Printf("set port %v success", port)95 }96 }97 if username != "" || password != "" {98 userService := service.UserService{}99 err := userService.UpdateFirstUser(username, password)100 if err != nil {101 fmt.Println("set username and password failed:", err)102 } else {103 fmt.Println("set username and password success")104 }105 }106}107func main() {108 if len(os.Args) < 2 {109 runWebServer()110 return111 }112 var showVersion bool113 flag.BoolVar(&showVersion, "v", false, "show version")114 runCmd := flag.NewFlagSet("run", flag.ExitOnError)115 v2uiCmd := flag.NewFlagSet("v2-ui", flag.ExitOnError)116 var dbPath string117 v2uiCmd.StringVar(&dbPath, "db", "/etc/v2-ui/v2-ui.db", "set v2-ui db file path")118 settingCmd := flag.NewFlagSet("setting", flag.ExitOnError)119 var port int120 var username string121 var password string122 var reset bool123 settingCmd.BoolVar(&reset, "reset", false, "reset all setting")124 settingCmd.IntVar(&port, "port", 0, "set panel port")125 settingCmd.StringVar(&username, "username", "", "set login username")126 settingCmd.StringVar(&password, "password", "", "set login password")127 oldUsage := flag.Usage128 flag.Usage = func() {129 oldUsage()130 fmt.Println()131 fmt.Println("Commands:")132 fmt.Println(" run run web panel")133 fmt.Println(" v2-ui migrate form v2-ui")134 fmt.Println(" setting set settings")135 }136 flag.Parse()137 if showVersion {138 fmt.Println(config.GetVersion())139 return140 }141 switch os.Args[1] {142 case "run":143 err := runCmd.Parse(os.Args[2:])144 if err != nil {145 fmt.Println(err)146 return147 }148 runWebServer()149 case "v2-ui":150 err := v2uiCmd.Parse(os.Args[2:])151 if err != nil {152 fmt.Println(err)153 return154 }155 err = v2ui.MigrateFromV2UI(dbPath)156 if err != nil {157 fmt.Println("migrate from v2-ui failed:", err)158 }159 case "setting":160 err := settingCmd.Parse(os.Args[2:])161 if err != nil {162 fmt.Println(err)163 return164 }165 if reset {166 resetSetting()167 } else {168 updateSetting(port, username, password)169 }170 default:171 fmt.Println("except 'run' or 'v2-ui' or 'setting' subcommands")172 fmt.Println()173 runCmd.Usage()174 fmt.Println()175 v2uiCmd.Usage()176 fmt.Println()177 settingCmd.Usage()178 }179}...

Full Screen

Full Screen

root.go

Source:root.go Github

copy

Full Screen

...33 }34}35func init() {36 viper.SetEnvPrefix(envPrefix)37 cobra.OnInitialize(initConfig, initLogger)38 RootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", cfgFileDefaultName, "config file (default is $HOME/.php-batch_server.yaml)")39 RootCmd.PersistentFlags().StringVar(&logLevel, "log.level", "Info", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]")40 envs := map[string]string{41 "LOG_LEVEL": "log.level",42 }43 mapEnvVars(envs, RootCmd)44}45// initConfig reads in config file and ENV variables if set.46func initConfig() {47 viper.SetConfigType("yaml")48 if cfgFile != "" {49 // Use config file from the flag.50 viper.SetConfigFile(cfgFile)51 } else {52 // Find home directory.53 home, err := homedir.Dir()54 if err != nil {55 fmt.Println(err)56 os.Exit(1)57 }58 // Search config in home directory with name ".php-fpm_exporter" (without extension).59 viper.AddConfigPath(".")60 viper.AddConfigPath("/etc/batch-server")61 viper.AddConfigPath(home)62 viper.SetConfigName(cfgFileDefaultName)63 }64 // If a config file is found, read it in.65 if err := viper.ReadInConfig(); err == nil {66 fmt.Println("Using config file:", viper.ConfigFileUsed())67 }68 viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))69 viper.AutomaticEnv() // read in environment variables that match70}71// initLogger configures the log level72func initLogger() {73 //fmt.Println("before init logger")74 logger.InitLogger()75 //server.SetLogger(log)76 //if value := os.Getenv("BATCH_SERVER_LOG_LEVEL"); value != "" {77 // logLevel = value78 //}79 //80 //lvl, err := logrus.ParseLevel(logLevel)81 //if err != nil {82 // lvl = logrus.InfoLevel83 // log.Fatalf("Could not set log level to '%v'.", logLevel)84 //}85 //86 //log.SetLevel(lvl)...

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1cmd := new(cmd)2cmd.initLogger()3cmd := new(cmd)4cmd.initLogger()5cmd := new(cmd)6cmd.initLogger()7cmd := new(cmd)8cmd.initLogger()9cmd := new(cmd)10cmd.initLogger()11cmd := new(cmd)12cmd.initLogger()13cmd := new(cmd)14cmd.initLogger()15cmd := new(cmd)16cmd.initLogger()17cmd := new(cmd)18cmd.initLogger()19cmd := new(cmd)20cmd.initLogger()21cmd := new(cmd)22cmd.initLogger()23cmd := new(cmd)24cmd.initLogger()25cmd := new(cmd)26cmd.initLogger()27cmd := new(cmd)28cmd.initLogger()29cmd := new(cmd)30cmd.initLogger()31cmd := new(cmd)32cmd.initLogger()33cmd := new(cmd)34cmd.initLogger()35cmd := new(cmd)36cmd.initLogger()37cmd := new(cmd)38cmd.initLogger()

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd.initLogger()4}5import (6func main() {7 cmd.initLogger()8}9import (10func main() {11 cmd.initLogger()12}13import (14func main() {15 cmd.initLogger()16}17import (18func main() {19 cmd.initLogger()20}21import (22func main() {23 cmd.initLogger()24}25import (26func main() {27 cmd.initLogger()28}29import (30func main() {31 cmd.initLogger()32}33import (34func main() {35 cmd.initLogger()36}37import (38func main() {39 cmd.initLogger()40}41import (42func main() {43 cmd.initLogger()44}45import (46func main() {47 cmd.initLogger()48}49import (50func main() {51 cmd.initLogger()52}53import (54func main() {

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 logs.Info("hello world")4}5import (6func main() {7 logs.Info("hello world")8}9import (10func main() {11 logs.Info("hello world")12}13import (14func main() {15 logs.Info("hello world")16}17import (18func main() {19 logs.Info("hello world")20}21import (22func main() {23 logs.Info("hello world")24}25import (26func main() {27 logs.Info("hello world")28}29import (30func main() {31 logs.Info("hello world")32}33import (34func main() {35 logs.Info("hello world")36}37import (38func main() {39 logs.Info("hello world")40}41import (

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd.InitLogger()4 log.Println("hello, world")5}6import (7func main() {8 cmd.InitLogger()9 log.Println("hello, world")10}11import (12func main() {13 cmd.InitLogger()14 log.Println("hello, world")15}16import (17func main() {18 cmd.InitLogger()19 log.Println("hello, world")20}21import (22func main() {23 cmd.InitLogger()24 log.Println("hello, world")25}26import (27func main() {28 cmd.InitLogger()29 log.Println("hello, world")30}31import (32func main() {33 cmd.InitLogger()34 log.Println("hello, world")35}36import (37func main() {38 cmd.InitLogger()39 log.Println("hello, world")40}41import (42func main() {43 cmd.InitLogger()44 log.Println("hello, world")45}46import (47func main() {48 cmd.InitLogger()49 log.Println("hello, world")50}51import (52func main() {53 cmd.InitLogger()54 log.Println("hello, world")

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1func main() {2 cmd.initLogger()3 cmd.Execute()4}5func initLogger() {6 logger, err := zap.NewProduction()7 if err != nil {8 log.Fatal(err)9 }10 zap.ReplaceGlobals(logger)11}12func initLogger() {13 logger, err := zap.NewProduction()14 if err != nil {15 log.Fatal(err)16 }17 zap.ReplaceGlobals(logger)18}19func initLogger() {20 logger, err := zap.NewProduction()21 if err != nil {22 log.Fatal(err)23 }24 zap.ReplaceGlobals(logger)25}26func initLogger() {27 logger, err := zap.NewProduction()28 if err != nil {29 log.Fatal(err)30 }31 zap.ReplaceGlobals(logger)32}33func initLogger() {34 logger, err := zap.NewProduction()35 if err != nil {36 log.Fatal(err)37 }38 zap.ReplaceGlobals(logger)39}40func initLogger() {41 logger, err := zap.NewProduction()42 if err != nil {43 log.Fatal(err)44 }45 zap.ReplaceGlobals(logger)46}47func initLogger() {48 logger, err := zap.NewProduction()49 if err != nil {50 log.Fatal(err)51 }52 zap.ReplaceGlobals(logger)53}54func initLogger() {55 logger, err := zap.NewProduction()56 if err != nil {57 log.Fatal(err)58 }59 zap.ReplaceGlobals(logger)60}61func initLogger() {62 logger, err := zap.NewProduction()63 if err != nil {64 log.Fatal(err)65 }66 zap.ReplaceGlobals(logger)67}68func initLogger() {69 logger, err := zap.NewProduction()70 if err != nil {71 log.Fatal(err)72 }73 zap.ReplaceGlobals(logger)74}

Full Screen

Full Screen

initLogger

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 log.Println("This is a log message")5}6import (7func main() {8 fmt.Println("Hello, playground")9 log.Println("This is a log message")10}11import (12type Cmd struct {13}14func (c *Cmd) InitLogger() {15 log.SetFlags(log.LstdFlags | log.Lshortfile)16 log.SetOutput(os.Stdout)17}18func (c *Cmd) Init() {19 c.InitLogger()20 log.Println("Init")21}22func (c *Cmd) Run() {23 log.Println("Run")24}25func (c *Cmd) Parse() {26 flag.Parse()27}28func (c *Cmd) Usage() {29 fmt.Println("Usage: go run 1.go")30}31func (c *Cmd) Main() {32 c.Init()33 c.Parse()34 c.Run()35}36import (37func main() {38 c := cmd.Cmd{}39 c.Main()40}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful