Skip to content

Commit

Permalink
修复日志问题
Browse files Browse the repository at this point in the history
  • Loading branch information
azhai committed Jun 15, 2023
2 parents 68cc816 + 9e4b25f commit 4ce35e7
Show file tree
Hide file tree
Showing 39 changed files with 1,312 additions and 571 deletions.
8 changes: 7 additions & 1 deletion cmd/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/azhai/xgen/config"
"github.com/k0kubun/pp"
"github.com/klauspost/cpuid/v2"
)

const (
VERSION = "1.6.0"
VERSION = "1.7.0"
MegaByte = 1024 * 1024
)

var (
Expand All @@ -37,6 +39,10 @@ type OptionConfig struct {
}

func init() {
// 压舱石,阻止频繁GC
ballast := make([]byte, 256*MegaByte)
runtime.KeepAlive(ballast)

if level := os.Getenv("GOAMD64"); level == "" {
level = fmt.Sprintf("v%d", cpuid.CPU.X64Level())
fmt.Printf("请设置环境变量 export GOAMD64=%s\n\n", level)
Expand Down
2 changes: 1 addition & 1 deletion config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (t *ArgList) Add(args []string, uniq bool) int {
if t.Convert != nil {
arg = t.Convert(arg)
}
if uniq { //去重不需要计数
if uniq { // 去重不需要计数
t.args[arg] = 1
} else if val, ok := t.args[arg]; ok {
t.args[arg] = val + 1
Expand Down
14 changes: 8 additions & 6 deletions config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (

reverse "github.com/azhai/xgen"
"github.com/azhai/xgen/dialect"
"github.com/azhai/xgen/utils"

"github.com/azhai/xgen/utils/logging"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsimple"
"go.uber.org/zap"
)

var (
settings *RootConfig
logger *utils.Logger
logger *zap.SugaredLogger
)

// RootConfig 顶层配置,包含其他配置块
Expand Down Expand Up @@ -53,13 +53,13 @@ func ReadConfigFile(options any) (*RootConfig, error) {
if len(adds) > 0 {
settings.Conns = append(settings.Conns, adds...)
}
settings.Repeats = []dialect.RepeatConfig{} //避免重复生成
settings.Repeats = []dialect.RepeatConfig{} // 避免重复生成
}
return settings, err
}

// GetConfigLogger 获取配置中的Logger
func GetConfigLogger() (*utils.Logger, error) {
func GetConfigLogger() (*zap.SugaredLogger, error) {
if logger != nil {
return logger, nil
}
Expand All @@ -69,5 +69,7 @@ func GetConfigLogger() (*utils.Logger, error) {
app := settings.App
level, dir = app.LogLevel, app.LogDir
}
return utils.NewLogger(level, dir), err
cfg := logging.NewDefaultConfig()
cfg.MinLevel = level
return logging.NewLogger(cfg, dir), err
}
3 changes: 1 addition & 2 deletions dialect/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/azhai/xgen/utils"
"github.com/azhai/xgen/xquery"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"xorm.io/xorm"
Expand Down Expand Up @@ -155,7 +154,7 @@ func (c ConnConfig) QuickConnect(logsql, verbose bool) *xorm.Engine {
if strings.Contains(logfile, "") {
logfile = strings.Replace(logfile, "$KEY", c.Key, 1)
}
logger := xquery.NewSqlLogger(logfile)
logger := xquery.NewXormLogger(logfile)
engine.SetLogger(logger)
}
return engine
Expand Down
2 changes: 1 addition & 1 deletion dialect/flashdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (FlashDB) QuoteIdent(ident string) string {

// ChangeDb 切换数据库
func (FlashDB) ChangeDb(database string) (bool, error) {
return false, nil //不支持
return false, nil // 不支持
}

// BuildDSN 生成DSN连接串
Expand Down
2 changes: 1 addition & 1 deletion dialect/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (Mysql) QuoteIdent(ident string) string {
// ChangeDb 切换数据库
func (d *Mysql) ChangeDb(database string) (bool, error) {
d.Database = database
return true, nil //成功
return true, nil // 成功
}

// BuildDSN 生成DSN连接串
Expand Down
22 changes: 9 additions & 13 deletions dialect/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dialect

import (
"fmt"
"strings"
)

const PGSQL_DEFAULT_PORT uint16 = 5432
Expand Down Expand Up @@ -36,30 +37,25 @@ func (Postgres) QuoteIdent(ident string) string {
// ChangeDb 切换数据库
func (d *Postgres) ChangeDb(database string) (bool, error) {
d.Database = database
return true, nil //成功
return true, nil // 成功
}

// BuildDSN 生成DSN连接串
func (d Postgres) BuildDSN() string {
dsn := "host=" + DIALECT_DEFAULT_HOST
addr := DIALECT_DEFAULT_HOST
if d.Host != "" {
dsn = "host=" + d.Host
}
if d.Port != 0 {
dsn += fmt.Sprintf(" port=%d", d.Port)
}
if d.Database != "" {
dsn += " dbname=" + d.Database
addr = GetAddr(d.Host, d.Port)
}
dsn := fmt.Sprintf("postgres://%s/%s?", addr, d.Database)
return dsn
}

// BuildFullDSN 生成带账号的完整DSN
func (d Postgres) BuildFullDSN(username, password string) string {
dsn := d.BuildDSN()
if dsn != "" {
dsn += "user=" + username
dsn += "password='" + password + "'"
dsn, head := d.BuildDSN(), "postgres://"
if strings.HasPrefix(dsn, head) {
account := GetAccount(username, password)
dsn = head + account + "@" + dsn[len(head):]
}
return dsn
}
4 changes: 2 additions & 2 deletions dialect/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (Redis) QuoteIdent(ident string) string {
func (d *Redis) ChangeDb(database string) (bool, error) {
db, err := strconv.Atoi(database)
if err != nil {
return false, err //失败
return false, err // 失败
}
d.Database = db
return true, nil //成功
return true, nil // 成功
}

// BuildDSN 生成DSN连接串
Expand Down
6 changes: 3 additions & 3 deletions dialect/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (Sqlite) QuoteIdent(ident string) string {

// ChangeDb 切换数据库
func (Sqlite) ChangeDb(database string) (bool, error) {
return false, nil //不支持
return false, nil // 不支持
}

// BuildDSN 生成DSN连接串
func (d Sqlite) BuildDSN() string {
if d.IsMemory() {
return "file::memory:?cache=shared&"
return "file::memory:?xm=shared&"
}
return "file:" + d.Path + "?cache=shared&mode=rwc&"
return "file:" + d.Path + "?xm=shared&mode=rwc&"
}

// BuildFullDSN 生成带账号的完整DSN
Expand Down
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module github.com/azhai/xgen

go 1.18
go 1.20

require (
github.com/arriqaaq/flashdb v0.1.6
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.7.1
github.com/gobwas/glob v0.2.3
github.com/gomodule/redigo v1.8.9
github.com/grsmv/inflect v0.0.0-20140723132642-a28d3de3b3ad
github.com/hashicorp/hcl/v2 v2.17.0
github.com/json-iterator/go v1.1.12
github.com/k0kubun/pp v3.0.1+incompatible
github.com/k0kubun/pp v2.4.0+incompatible
github.com/klauspost/cpuid/v2 v2.2.5
github.com/lib/pq v1.10.9
github.com/manifoldco/promptui v0.9.0
Expand All @@ -31,11 +32,13 @@ require (
github.com/arriqaaq/hash v0.1.2 // indirect
github.com/arriqaaq/set v0.1.2 // indirect
github.com/arriqaaq/zset v0.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.3 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
Expand All @@ -44,14 +47,13 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
xorm.io/builder v0.3.12 // indirect
)
Loading

0 comments on commit 4ce35e7

Please sign in to comment.