diff --git a/Abstractions/Configuration.go b/Abstractions/Configuration.go index 6147bc77..6c16797c 100644 --- a/Abstractions/Configuration.go +++ b/Abstractions/Configuration.go @@ -3,6 +3,7 @@ package Abstractions import ( "fmt" "github.com/spf13/viper" + "github.com/yoyofx/yoyogo/Utils" ) type Configuration struct { @@ -11,36 +12,24 @@ type Configuration struct { } func NewConfiguration(configContext *ConfigurationContext) *Configuration { + + configName := configContext.configName + "_" + configContext.profile + exists, _ := Utils.PathExists("./" + configName + "." + configContext.configType) + if !exists { + configName = configContext.configName + } + defaultConfig := viper.New() defaultConfig.AddConfigPath(".") - defaultConfig.SetConfigName(configContext.configName) + defaultConfig.SetConfigName(configName) defaultConfig.SetConfigType(configContext.configType) if err := defaultConfig.ReadInConfig(); err != nil { return nil } - profile := defaultConfig.Get("application.profile") - var profileConfig *viper.Viper - if profile != nil { - profileConfig = viper.New() - profileConfig.AddConfigPath(".") - configContext.profile = profile.(string) - profileConfig.SetConfigName(configContext.configName + "_" + configContext.profile) - profileConfig.SetConfigType(configContext.configType) - configs := defaultConfig.AllSettings() - // 将default中的配置全部以默认配置写入 - for k, v := range configs { - profileConfig.Set(k, v) - } - - if err := profileConfig.ReadInConfig(); err != nil { - profileConfig = defaultConfig - } - } - return &Configuration{ context: configContext, - config: profileConfig, + config: defaultConfig, } } @@ -50,12 +39,6 @@ func (c *Configuration) Get(name string) interface{} { func (c *Configuration) GetSection(name string) IConfiguration { section := c.config.Sub(name) - section.SetConfigName(c.context.configName + "_" + c.context.profile) - configs := c.config.AllSettings() - // 将default中的配置全部以默认配置写入 - for k, v := range configs { - section.Set(k, v) - } if section != nil { return &Configuration{config: section} @@ -69,3 +52,7 @@ func (c *Configuration) Unmarshal(obj interface{}) { fmt.Println("unmarshal config is failed, err:", err) } } + +func (c *Configuration) GetProfile() string { + return c.context.profile +} diff --git a/Abstractions/ConfigurationBuilder.go b/Abstractions/ConfigurationBuilder.go index d55e5e5d..00863131 100644 --- a/Abstractions/ConfigurationBuilder.go +++ b/Abstractions/ConfigurationBuilder.go @@ -28,7 +28,7 @@ func (builder *ConfigurationBuilder) AddEnvironment() *ConfigurationBuilder { func (builder *ConfigurationBuilder) AddYamlFile(name string) *ConfigurationBuilder { if builder.context.configType == "" { - builder.context.configType = "yaml" + builder.context.configType = "yml" builder.context.configName = name } return builder @@ -42,6 +42,7 @@ func (builder *ConfigurationBuilder) AddJsonFile(name string) *ConfigurationBuil return builder } -func (builder *ConfigurationBuilder) Build() *Configuration { +func (builder *ConfigurationBuilder) Build(env string) *Configuration { + builder.context.profile = env return NewConfiguration(builder.context) } diff --git a/Abstractions/Env/env.go b/Abstractions/Env/env.go new file mode 100644 index 00000000..bf37715e --- /dev/null +++ b/Abstractions/Env/env.go @@ -0,0 +1,7 @@ +package Env + +const ( + Dev = "dev" + Prod = "prod" + Test = "test" +) diff --git a/Abstractions/HostBuilder.go b/Abstractions/HostBuilder.go index a65fde46..46d8cd3f 100644 --- a/Abstractions/HostBuilder.go +++ b/Abstractions/HostBuilder.go @@ -2,7 +2,8 @@ package Abstractions import ( "fmt" - YoyoGo "github.com/yoyofx/yoyogo" + "github.com/yoyofx/yoyogo" + "github.com/yoyofx/yoyogo/Abstractions/Env" "github.com/yoyofx/yoyogo/Abstractions/configs" "github.com/yoyofx/yoyogo/DependencyInjection" "github.com/yoyofx/yoyogo/WebFramework/Context" @@ -35,6 +36,7 @@ func (host *HostBuilder) Configure(configure interface{}) *HostBuilder { func (host *HostBuilder) UseConfiguration(configuration IConfiguration) *HostBuilder { host.Context.Configuration = configuration + host.Context.HostingEnvironment.Profile = configuration.GetProfile() section := host.Context.Configuration.GetSection("application") if section != nil { config := &configs.HostConfig{} @@ -81,13 +83,13 @@ func getLocalIP() string { return localIp } -// RunningHostEnvironmentSetting ,get running env setting. +// RunningHostEnvironmentSetting ,get running Env setting. func RunningHostEnvironmentSetting(hostEnv *Context.HostEnvironment) { hostEnv.Host = getLocalIP() hostEnv.PID = os.Getpid() } -//buildingHostEnvironmentSetting build each configuration by init , such as file or env or args ... +//buildingHostEnvironmentSetting build each configuration by init , such as file or Env or args ... func buildingHostEnvironmentSetting(context *HostBuildContext) { hostEnv := context.HostingEnvironment hostEnv.Version = YoyoGo.Version @@ -98,16 +100,13 @@ func buildingHostEnvironmentSetting(context *HostBuildContext) { if config.Server.Address != "" { hostEnv.Addr = config.Server.Address } - if config.Profile != "" { - hostEnv.Profile = config.Profile - } } hostEnv.Port = strings.Replace(hostEnv.Addr, ":", "", -1) hostEnv.Args = os.Args if hostEnv.Profile == "" { - hostEnv.Profile = Context.Dev + hostEnv.Profile = Env.Dev } } diff --git a/Abstractions/IConfiguration.go b/Abstractions/IConfiguration.go index 23279a14..14a019f5 100644 --- a/Abstractions/IConfiguration.go +++ b/Abstractions/IConfiguration.go @@ -4,4 +4,5 @@ type IConfiguration interface { Get(name string) interface{} GetSection(name string) IConfiguration Unmarshal(interface{}) + GetProfile() string } diff --git a/Abstractions/IServiceHost.go b/Abstractions/IServiceHost.go index 3a73a425..709b0542 100644 --- a/Abstractions/IServiceHost.go +++ b/Abstractions/IServiceHost.go @@ -5,9 +5,9 @@ import ( "fmt" "github.com/yoyofx/yoyogo" "github.com/yoyofx/yoyogo/Abstractions/Platform/ConsoleColors" + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofx/yoyogo/Utils" "github.com/yoyofx/yoyogo/WebFramework/Context" - "log" "strconv" ) @@ -18,22 +18,22 @@ type IServiceHost interface { SetAppMode(mode string) } -func PrintLogo(l *log.Logger, env *Context.HostEnvironment) { +func PrintLogo(l xlog.ILogger, env *Context.HostEnvironment) { logo, _ := base64.StdEncoding.DecodeString(YoyoGo.Logo) fmt.Println(ConsoleColors.Blue(string(logo))) fmt.Printf("%s (%s)", ConsoleColors.Green(":: YoyoGo ::"), ConsoleColors.Blue(env.Version)) fmt.Println(" ") fmt.Println(" ") - l.Println(ConsoleColors.Green("Welcome to YoyoGo, starting application ...")) - l.Printf("yoyogo framework version : %s", ConsoleColors.Blue(env.Version)) - l.Printf("machine host ip : %s", ConsoleColors.Blue(env.Host)) - l.Printf("listening on port : %s", ConsoleColors.Blue(env.Port)) - l.Printf("application running pid : %s", ConsoleColors.Blue(strconv.Itoa(env.PID))) - l.Printf("application name : %s", ConsoleColors.Blue(env.ApplicationName)) - l.Printf("application environment : %s", ConsoleColors.Blue(env.Profile)) - l.Printf("application exec path : %s", ConsoleColors.Yellow(Utils.GetCurrentDirectory())) - l.Printf("running in %s mode , change (Dev,Test,Prod) mode by HostBuilder.SetEnvironment .", ConsoleColors.Blue(env.Profile)) - l.Println(ConsoleColors.Green("Starting HTTP server...")) + l.Debug(ConsoleColors.Green("Welcome to YoyoGo, starting application ...")) + l.Debug("yoyogo framework version : %s", ConsoleColors.Blue(env.Version)) + l.Debug("machine host ip : %s", ConsoleColors.Blue(env.Host)) + l.Debug("listening on port : %s", ConsoleColors.Blue(env.Port)) + l.Debug("application running pid : %s", ConsoleColors.Blue(strconv.Itoa(env.PID))) + l.Debug("application name : %s", ConsoleColors.Blue(env.ApplicationName)) + l.Debug("application environment : %s", ConsoleColors.Blue(env.Profile)) + l.Debug("application exec path : %s", ConsoleColors.Yellow(Utils.GetCurrentDirectory())) + l.Debug("running in %s mode , change (Dev,Test,Prod) mode by HostBuilder.SetEnvironment .", ConsoleColors.Blue(env.Profile)) + l.Debug(ConsoleColors.Green("Starting HTTP server...")) } diff --git a/Abstractions/configs/HostConfig.go b/Abstractions/configs/HostConfig.go index 04a73fe2..013ca3c6 100644 --- a/Abstractions/configs/HostConfig.go +++ b/Abstractions/configs/HostConfig.go @@ -3,6 +3,5 @@ package configs type HostConfig struct { Name string `mapstructure:"name"` Metadata string `mapstructure:"metadata"` - Profile string `mapstructure:"profile"` Server ServerConfig `mapstructure:"server"` } diff --git a/Abstractions/xlog/ILogger.go b/Abstractions/xlog/ILogger.go new file mode 100644 index 00000000..e4c8398e --- /dev/null +++ b/Abstractions/xlog/ILogger.go @@ -0,0 +1,11 @@ +package xlog + +type ILogger interface { + Debug(format string, a ...interface{}) + Info(format string, a ...interface{}) + Warning(format string, a ...interface{}) + Error(format string, a ...interface{}) + + SetCustomLogFormat(logFormatterFunc func(logInfo LogInfo) string) + SetDateFormat(format string) +} diff --git a/Abstractions/xlog/XLogger.go b/Abstractions/xlog/XLogger.go new file mode 100644 index 00000000..194cc794 --- /dev/null +++ b/Abstractions/xlog/XLogger.go @@ -0,0 +1,101 @@ +package xlog + +import ( + "fmt" + "github.com/yoyofx/yoyogo/Abstractions/Platform/ConsoleColors" + "log" + "os" + "time" +) + +type XLogger struct { + logger *log.Logger + dateFormat string + class string + logFormatter func(LogInfo) string +} + +var LoggerDefaultDateFormat = "2006/01/02 15:04:05.00" + +type LogLevel int + +// MessageLevel +const ( + NOTSET = iota + DEBUG = LogLevel(10 * iota) // DEBUG = 10 + INFO = LogLevel(10 * iota) // INFO = 20 + WARNING = LogLevel(10 * iota) // WARNING = 30 + ERROR = LogLevel(10 * iota) // ERROR = 40 +) + +var LevelString = map[LogLevel]string{ + DEBUG: "DEBUG", + INFO: "INFO", + WARNING: ConsoleColors.Yellow("WARNING"), + ERROR: ConsoleColors.Red("ERROR"), +} + +func defaultLogFormater(logInfo LogInfo) string { + outLog := fmt.Sprintf(ConsoleColors.Yellow("[yoyogo] ")+"[%s] [%s] [%s] [%s] , %s", + logInfo.StartTime, logInfo.Level, logInfo.Class, logInfo.Host, logInfo.Message) + return outLog +} + +func (log *XLogger) SetCustomLogFormat(logFormatterFunc func(logInfo LogInfo) string) { + log.logFormatter = logFormatterFunc +} + +func (log *XLogger) SetDateFormat(format string) { + log.dateFormat = format +} + +func NewXLogger() *XLogger { + logger := NewLoggerWith(log.New(os.Stdout, "", 0)) + return logger +} + +func NewLoggerWith(log *log.Logger) *XLogger { + logger := &XLogger{logger: log, dateFormat: LoggerDefaultDateFormat} + logger.SetCustomLogFormat(defaultLogFormater) + return logger +} + +func GetXLogger(class string) ILogger { + logger := NewXLogger() + logger.class = class + return logger +} + +func (log *XLogger) log(level LogLevel, format string, a ...interface{}) { + hostName, _ := os.Hostname() + message := format + if len(a[0].([]interface{})) > 0 { + message = fmt.Sprintf(format, a...) + } + + start := time.Now() + info := LogInfo{ + StartTime: start.Format(log.dateFormat), + Level: LevelString[level], + Class: log.class, + Host: hostName, + Message: message, + } + log.logger.Println(log.logFormatter(info)) +} + +func (log *XLogger) Debug(format string, a ...interface{}) { + log.log(DEBUG, format, a) +} + +func (log *XLogger) Info(format string, a ...interface{}) { + log.log(INFO, format, a) +} + +func (log *XLogger) Warning(format string, a ...interface{}) { + log.log(WARNING, format, a) +} + +func (log *XLogger) Error(format string, a ...interface{}) { + log.log(ERROR, format, a) +} diff --git a/Abstractions/xlog/logInfo.go b/Abstractions/xlog/logInfo.go new file mode 100644 index 00000000..5d845af4 --- /dev/null +++ b/Abstractions/xlog/logInfo.go @@ -0,0 +1,9 @@ +package xlog + +type LogInfo struct { + StartTime string + Level string + Class string + Host string + Message string +} diff --git a/Examples/SimpleWeb/config.yml b/Examples/SimpleWeb/config.yml deleted file mode 100644 index 2e241b9b..00000000 --- a/Examples/SimpleWeb/config.yml +++ /dev/null @@ -1,11 +0,0 @@ -application: - name: demo1 - metadata: "hello world" - profile: "dev" - server: - type: "fasthttp" - address: ":8080" - max_request_size: 2096157 - static: - patten: "/" - webroot: "./Static" diff --git a/Examples/SimpleWeb/config_dev.yml b/Examples/SimpleWeb/config_dev.yml index 1797bcf9..268acf0b 100644 --- a/Examples/SimpleWeb/config_dev.yml +++ b/Examples/SimpleWeb/config_dev.yml @@ -1,4 +1,10 @@ application: name: demo_dev + metadata: "develop" server: - address: ":8080" \ No newline at end of file + type: "fasthttp" + address: ":8080" + max_request_size: 2096157 + static: + patten: "/" + webroot: "./Static" diff --git a/Examples/SimpleWeb/config_prod.yml b/Examples/SimpleWeb/config_prod.yml index fbee0564..0185ecb0 100644 --- a/Examples/SimpleWeb/config_prod.yml +++ b/Examples/SimpleWeb/config_prod.yml @@ -1,4 +1,10 @@ application: name: demo_prod + metadata: "prod Env" server: - address: ":8081" \ No newline at end of file + type: "fasthttp" + address: ":8080" + max_request_size: 2096157 + static: + patten: "/" + webroot: "./Static" diff --git a/Examples/SimpleWeb/main.go b/Examples/SimpleWeb/main.go index 966d4301..4045ca0d 100644 --- a/Examples/SimpleWeb/main.go +++ b/Examples/SimpleWeb/main.go @@ -3,6 +3,8 @@ package main import ( "fmt" "github.com/yoyofx/yoyogo/Abstractions" + "github.com/yoyofx/yoyogo/Abstractions/Env" + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofx/yoyogo/DependencyInjection" "github.com/yoyofx/yoyogo/Examples/SimpleWeb/contollers" "github.com/yoyofx/yoyogo/Examples/SimpleWeb/models" @@ -32,8 +34,7 @@ func main() { //* Create the builder of Web host func CreateCustomBuilder() *Abstractions.HostBuilder { - configuration := Abstractions.NewConfigurationBuilder().AddYamlFile("config").Build() - + configuration := Abstractions.NewConfigurationBuilder().AddYamlFile("config").Build(Env.Prod) return YoyoGo.NewWebHostBuilder(). UseConfiguration(configuration). Configure(func(app *YoyoGo.WebApplicationBuilder) { @@ -110,7 +111,8 @@ func PostInfo(ctx *Context.HttpContext) { func getApplicationLifeEvent(life *Abstractions.ApplicationLife) { printDataEvent := func(event Abstractions.ApplicationEvent) { - fmt.Printf("[yoyogo] Topic: %s; Event: %v\n", event.Topic, event.Data) + xlog.GetXLogger("Application Life Event:").Debug(" Topic: %s; Event: %v\n", event.Topic, event.Data) + //fmt.Printf("[yoyogo] Topic: %s; Event: %v\n", event.Topic, event.Data) } for { diff --git a/Utils/ConsoleColor.go b/Utils/ConsoleColor.go deleted file mode 100644 index 36013897..00000000 --- a/Utils/ConsoleColor.go +++ /dev/null @@ -1 +0,0 @@ -package Utils diff --git a/Utils/Runtime.go b/Utils/Runtime.go index b21caabc..4effe462 100644 --- a/Utils/Runtime.go +++ b/Utils/Runtime.go @@ -14,3 +14,14 @@ func GetCurrentDirectory() string { } return strings.Replace(dir, "\\", "/", -1) //将\替换成/ } + +func PathExists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return false, err +} diff --git a/Version.go b/Version.go index 31ca9fd0..f91b6d5f 100644 --- a/Version.go +++ b/Version.go @@ -2,7 +2,7 @@ package YoyoGo const ( //Application Version, such as v1.x.x pre-release - Version = "v1.5.0.pre-release" + Version = "v1.5.1.release" //Application logo Logo = "IF8gICAgIF8gICAgICAgICAgICAgICAgICAgIF9fXyAgICAgICAgICAKKCApICAgKCApICAgICAgICAgICAgICAgICAgKCAgX2BcICAgICAgICAKYFxgXF8vJy8nXyAgICBfICAgXyAgICBfICAgfCAoIChfKSAgIF8gICAKICBgXCAvJy8nX2BcICggKSAoICkgLydfYFwgfCB8X19fICAvJ19gXCAKICAgfCB8KCAoXykgKXwgKF8pIHwoIChfKSApfCAoXywgKSggKF8pICkKICAgKF8pYFxfX18vJ2BcX18sIHxgXF9fXy8nKF9fX18vJ2BcX19fLycKICAgICAgICAgICAgICggKV98IHwgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgIGBcX19fLycgICAgICAgICAgICBMaWdodCBhbmQgZmFzdC4gIA==" ) diff --git a/WebFramework/Context/HostEnvironment.go b/WebFramework/Context/HostEnvironment.go index 845f3297..99ba9d90 100644 --- a/WebFramework/Context/HostEnvironment.go +++ b/WebFramework/Context/HostEnvironment.go @@ -1,10 +1,6 @@ package Context -const ( - Dev = "Dev" - Prod = "Prod" - Test = "Test" -) +import "github.com/yoyofx/yoyogo/Abstractions/Env" type HostEnvironment struct { ApplicationName string @@ -18,13 +14,13 @@ type HostEnvironment struct { } func (env HostEnvironment) IsDevelopment() bool { - return env.Profile == Dev + return env.Profile == Env.Dev } func (env HostEnvironment) IsStaging() bool { - return env.Profile == Test + return env.Profile == Env.Test } func (env HostEnvironment) IsProduction() bool { - return env.Profile == Prod + return env.Profile == Env.Prod } diff --git a/WebFramework/Endpoints/health_endpoint.go b/WebFramework/Endpoints/health_endpoint.go index 2efc9719..cf3d872b 100644 --- a/WebFramework/Endpoints/health_endpoint.go +++ b/WebFramework/Endpoints/health_endpoint.go @@ -1,11 +1,14 @@ package Endpoints import ( + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofx/yoyogo/WebFramework/Context" "github.com/yoyofx/yoyogo/WebFramework/Router" ) func UseHealth(router Router.IRouterBuilder) { + xlog.GetXLogger("Endpoint").Debug("loaded health endpoint.") + router.GET("/actuator/health", func(ctx *Context.HttpContext) { ctx.JSON(200, Context.M{ "status": "UP", diff --git a/WebFramework/Endpoints/pprof_endpoint.go b/WebFramework/Endpoints/pprof_endpoint.go index 0eac44c2..2c4a53e0 100644 --- a/WebFramework/Endpoints/pprof_endpoint.go +++ b/WebFramework/Endpoints/pprof_endpoint.go @@ -1,6 +1,7 @@ package Endpoints import ( + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofx/yoyogo/WebFramework" "github.com/yoyofx/yoyogo/WebFramework/Context" "github.com/yoyofx/yoyogo/WebFramework/Router" @@ -32,6 +33,8 @@ func WarpHandlerFunc(h func(w http.ResponseWriter, r *http.Request)) YoyoGo.Hand } func UsePprof(router Router.IRouterBuilder) { + xlog.GetXLogger("Endpoint").Debug("loaded pprof endpoint.") + for _, item := range debupApi { router.GET(item.Path, item.HandlerFunc) } diff --git a/WebFramework/Endpoints/prometheus_endpoint.go b/WebFramework/Endpoints/prometheus_endpoint.go index 9ca3cb14..d11620ea 100644 --- a/WebFramework/Endpoints/prometheus_endpoint.go +++ b/WebFramework/Endpoints/prometheus_endpoint.go @@ -2,10 +2,13 @@ package Endpoints import ( "github.com/prometheus/client_golang/prometheus/promhttp" - YoyoGo "github.com/yoyofx/yoyogo/WebFramework" + "github.com/yoyofx/yoyogo/Abstractions/xlog" + "github.com/yoyofx/yoyogo/WebFramework" "github.com/yoyofx/yoyogo/WebFramework/Router" ) func UsePrometheus(router Router.IRouterBuilder) { + xlog.GetXLogger("Endpoint").Debug("loaded prometheus endpoint.") + router.GET("/actuator/metrics", YoyoGo.WarpHttpHandlerFunc(promhttp.Handler())) } diff --git a/WebFramework/Endpoints/viz_endpoint.go b/WebFramework/Endpoints/viz_endpoint.go index c0c04e52..d649fe82 100644 --- a/WebFramework/Endpoints/viz_endpoint.go +++ b/WebFramework/Endpoints/viz_endpoint.go @@ -1,6 +1,7 @@ package Endpoints import ( + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofx/yoyogo/WebFramework/Context" "github.com/yoyofx/yoyogo/WebFramework/Router" "html/template" @@ -33,6 +34,8 @@ const ( var panicHTMLTemplate = template.Must(template.New("PanicPage").Parse(panicText)) func UseViz(router Router.IRouterBuilder) { + xlog.GetXLogger("Endpoint").Debug("loaded graphViz endpoint.") + router.GET("/actuator/graph", func(ctx *Context.HttpContext) { graphType := ctx.Input.QueryDefault("type", "data") graphString := ctx.RequiredServices.GetGraph() diff --git a/WebFramework/Middleware/LoggerMiddleware.go b/WebFramework/Middleware/LoggerMiddleware.go index 59b876d3..0a2fbfa9 100644 --- a/WebFramework/Middleware/LoggerMiddleware.go +++ b/WebFramework/Middleware/LoggerMiddleware.go @@ -5,7 +5,6 @@ import ( "github.com/yoyofx/yoyogo/Abstractions/Platform/ConsoleColors" "github.com/yoyofx/yoyogo/WebFramework/Context" "html/template" - "io/ioutil" "log" "net/http" "os" @@ -117,7 +116,7 @@ func (l *Logger) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpCon strBody := "" bodyFormat := "%s" if ctx.Input.Request.Method == "POST" { - body, _ := ioutil.ReadAll(ctx.Input.Request.Body) + body := ctx.Input.FormBody strBody = string(body[:]) bodyFormat = "\n%s" } diff --git a/WebFramework/Mvc/ControllerBuilder.go b/WebFramework/Mvc/ControllerBuilder.go index 2ad36656..863edaf7 100644 --- a/WebFramework/Mvc/ControllerBuilder.go +++ b/WebFramework/Mvc/ControllerBuilder.go @@ -1,6 +1,7 @@ package Mvc import ( + "github.com/yoyofx/yoyogo/Abstractions/xlog" "github.com/yoyofxteam/reflectx" "strings" ) @@ -17,6 +18,7 @@ func NewControllerBuilder() *ControllerBuilder { // add filter to mvc func (builder *ControllerBuilder) AddFilter(pattern string, actionFilter IActionFilter) { + xlog.GetXLogger("ControllerBuilder").Debug("add mvc filter: %s", pattern) chain := NewActionFilterChain(pattern, actionFilter) builder.mvcRouterHandler.ControllerFilters = append(builder.mvcRouterHandler.ControllerFilters, chain) } @@ -28,11 +30,18 @@ func (builder *ControllerBuilder) SetupOptions(configOption func(options Options // AddController add controller (ctor) to ioc. func (builder *ControllerBuilder) AddController(controllerCtor interface{}) { + logger := xlog.GetXLogger("ControllerBuilder") + controllerName, controllerType := reflectx.GetCtorFuncOutTypeName(controllerCtor) controllerName = strings.ToLower(controllerName) // Create Controller and Action descriptors descriptor := NewControllerDescriptor(controllerName, controllerType, controllerCtor) builder.mvcRouterHandler.ControllerDescriptors[controllerName] = descriptor + + logger.Debug("add mvc controller: %s", controllerName) + for _, desc := range descriptor.GetActionDescriptors() { + logger.Debug("add mvc controller action: %s", desc.ActionName) + } } // GetControllerDescriptorList is get controller descriptor array diff --git a/WebFramework/WebHost.go b/WebFramework/WebHost.go index aae12a85..de2a6dc6 100644 --- a/WebFramework/WebHost.go +++ b/WebFramework/WebHost.go @@ -1,11 +1,11 @@ package YoyoGo import ( + "fmt" "github.com/yoyofx/yoyogo/Abstractions" "github.com/yoyofx/yoyogo/Abstractions/Platform/ConsoleColors" "github.com/yoyofx/yoyogo/Abstractions/Platform/ExitHookSignals" - "log" - "os" + "github.com/yoyofx/yoyogo/Abstractions/xlog" ) type WebHost struct { @@ -19,17 +19,23 @@ func NewWebHost(server Abstractions.IServer, hostContext *Abstractions.HostBuild func (host WebHost) Run() { hostEnv := host.HostContext.HostingEnvironment - xlog := log.New(os.Stdout, ConsoleColors.Yellow("[yoyogo] "), 1) - + logger := xlog.GetXLogger("Application") + logger.SetCustomLogFormat(logFormater) Abstractions.RunningHostEnvironmentSetting(hostEnv) - Abstractions.PrintLogo(xlog, hostEnv) + Abstractions.PrintLogo(logger, hostEnv) ExitHookSignals.HookSignals(host) _ = host.webServer.Run(host.HostContext) } +func logFormater(logInfo xlog.LogInfo) string { + outLog := fmt.Sprintf(ConsoleColors.Yellow("[yoyogo] ")+"[%s] %s", + logInfo.StartTime, logInfo.Message) + return outLog +} + func (host WebHost) StopApplicationNotify() { host.HostContext.ApplicationCycle.StopApplication() } diff --git a/build.sh b/build.sh index 3c66ba01..65d603b8 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/Env bash osArray=("linux" "darwin" "freebsd" "windows") archs=("amd64" "386") version=${1-"0.0.1-preview1"}