本文整理汇总了Golang中github.com/ngaut/log.SetLevelByString函数的典型用法代码示例。如果您正苦于以下问题:Golang SetLevelByString函数的具体用法?Golang SetLevelByString怎么用?Golang SetLevelByString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetLevelByString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitLog
func InitLog(runmode, path string) {
log.SetLevelByString("info")
if runmode == "dev" {
log.SetLevelByString("debug")
}
log.SetOutputByName(path)
}
示例2: main
func main() {
flag.Parse()
log.SetLevelByString(*logLevel)
cfg := &server.Config{
Addr: *addr,
ZKAddr: *zk,
RootPath: *rootPath,
SaveInterval: *interval,
}
oracle, err := server.NewTimestampOracle(cfg)
if err != nil {
log.Fatal(err)
}
go http.ListenAndServe(":5555", nil)
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
log.Infof("Got signal [%d] to exit.", sig)
oracle.Close()
os.Exit(0)
}()
oracle.Run()
}
示例3: SetUpSuite
func (s *testBinlogSuite) SetUpSuite(c *C) {
logLevel := os.Getenv("log_level")
log.SetLevelByString(logLevel)
store, err := tikv.NewMockTikvStore()
c.Assert(err, IsNil)
s.store = store
tidb.SetSchemaLease(0)
s.unixFile = "/tmp/mock-binlog-pump"
os.Remove(s.unixFile)
l, err := net.Listen("unix", s.unixFile)
c.Assert(err, IsNil)
s.serv = grpc.NewServer()
s.pump = new(mockBinlogPump)
binlog.RegisterPumpServer(s.serv, s.pump)
go s.serv.Serve(l)
opt := grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
})
clientCon, err := grpc.Dial(s.unixFile, opt, grpc.WithInsecure())
c.Assert(err, IsNil)
c.Assert(clientCon, NotNil)
binloginfo.PumpClient = binlog.NewPumpClient(clientCon)
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
domain := sessionctx.GetDomain(s.tk.Se.(context.Context))
s.ddl = domain.DDL()
}
示例4: SetUpTest
func (s *testStmtSuite) SetUpTest(c *C) {
log.SetLevelByString("error")
s.dbName = "teststmts"
var err error
s.testDB, err = sql.Open(tidb.DriverName, tidb.EngineGoLevelDBMemory+"/"+s.dbName+"/"+s.dbName)
c.Assert(err, IsNil)
// create db
s.createDBSql = fmt.Sprintf("create database if not exists %s;", s.dbName)
s.dropDBSql = fmt.Sprintf("drop database if exists %s;", s.dbName)
s.useDBSql = fmt.Sprintf("use %s;", s.dbName)
s.createTableSql = `
CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));
CREATE TABLE test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name));
CREATE TABLE test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));`
s.selectSql = `SELECT * from test limit 2;`
mustExec(c, s.testDB, s.createDBSql)
mustExec(c, s.testDB, s.useDBSql)
s.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
s.createUserTableSQL = tidb.CreateUserTable
mustExec(c, s.testDB, s.createSystemDBSQL)
mustExec(c, s.testDB, s.createUserTableSQL)
}
示例5: SetUpTest
func (t *testPrivilegeSuite) SetUpTest(c *C) {
log.SetLevelByString("error")
t.dbName = "test"
t.store = newStore(c, t.dbName)
se := newSession(c, t.store, t.dbName)
t.createDBSQL = fmt.Sprintf("create database if not exists %s;", t.dbName)
t.createDB1SQL = fmt.Sprintf("create database if not exists %s1;", t.dbName)
t.dropDBSQL = fmt.Sprintf("drop database if exists %s;", t.dbName)
t.useDBSQL = fmt.Sprintf("use %s;", t.dbName)
t.createTableSQL = `CREATE TABLE test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));`
mustExec(c, se, t.createDBSQL)
mustExec(c, se, t.createDB1SQL) // create database test1
mustExec(c, se, t.useDBSQL)
mustExec(c, se, t.createTableSQL)
t.createSystemDBSQL = fmt.Sprintf("create database if not exists %s;", mysql.SystemDB)
t.createUserTableSQL = tidb.CreateUserTable
t.createDBPrivTableSQL = tidb.CreateDBPrivTable
t.createTablePrivTableSQL = tidb.CreateTablePrivTable
t.createColumnPrivTableSQL = tidb.CreateColumnPrivTable
mustExec(c, se, t.createSystemDBSQL)
mustExec(c, se, t.createUserTableSQL)
mustExec(c, se, t.createDBPrivTableSQL)
mustExec(c, se, t.createTablePrivTableSQL)
mustExec(c, se, t.createColumnPrivTableSQL)
}
示例6: main
func main() {
flag.Parse()
if *lease < 0 {
log.Fatalf("invalid lease seconds %d", *lease)
}
tidb.SetSchemaLease(time.Duration(*lease) * time.Second)
log.SetLevelByString(*logLevel)
store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
if err != nil {
log.Fatal(err)
}
var driver relay.IDriver
driver = relay.NewTiDBDriver(store)
replayer, err := relay.NewReplayer(driver, *relayPath, *check)
if err != nil {
log.Fatal(err)
}
replayer.OnRecordRead = func(rec *relay.Record) {
fmt.Printf("%s\n", rec)
}
err = replayer.Run()
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
}
示例7: OpenDB
// OpenDB opens the database in the given directory; if required, the database
// will be initialized.
func OpenDB(dir string) (err error) {
log.SetLevelByString("error")
dir = filepath.Join(dir, "tidb")
_, err = os.Stat(dir)
init := os.IsNotExist(err)
name := "tidb"
db, err = sqlx.Open("tidb", "goleveldb://"+dir+"/"+name)
if err != nil {
return fmt.Errorf("db open failed: %s", err)
}
if err := db.Ping(); err != nil {
return fmt.Errorf("db ping failed: %s", err)
}
if init {
// b, err := ioutil.ReadFile(filepath.Join("data", "schema.sql"))
// if err != nil {
// return fmt.Errorf("read schema file failed: %s", err)
// }
// if _, err = db.Exec(string(b)); err != nil {
if _, err = db.Exec(schemasql); err != nil {
return fmt.Errorf("exec schema failed: %s", err)
}
if err = insertCards(); err != nil {
return fmt.Errorf("insert cards failed: %s", err)
}
}
return nil
}
示例8: main
func main() {
tidb.RegisterLocalStore("boltdb", boltdb.Driver{})
tidb.RegisterStore("tikv", tikv.Driver{})
metric.RunMetric(3 * time.Second)
printer.PrintTiDBInfo()
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *lease < 0 {
log.Fatalf("invalid lease seconds %d", *lease)
}
tidb.SetSchemaLease(time.Duration(*lease) * time.Second)
cfg := &server.Config{
Addr: fmt.Sprintf(":%s", *port),
LogLevel: *logLevel,
StatusAddr: fmt.Sprintf(":%s", *statusPort),
Socket: *socket,
}
log.SetLevelByString(cfg.LogLevel)
store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
// Create a session to load information schema.
se, err := tidb.CreateSession(store)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
se.Close()
var driver server.IDriver
driver = server.NewTiDBDriver(store)
var svr *server.Server
svr, err = server.NewServer(cfg, driver)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
log.Infof("Got signal [%d] to exit.", sig)
svr.Close()
os.Exit(0)
}()
log.Error(svr.Run())
}
示例9: SetUpSuite
func (s *testTableRsetSuite) SetUpSuite(c *C) {
log.SetLevelByString("error")
s.dbName = "rset_test"
s.tableName = "rset_table"
s.createTableSql = fmt.Sprintf("create table if not exists %s(id int);", s.tableName)
s.querySql = fmt.Sprintf("select * from %s;", s.tableName)
}
示例10: main
func main() {
log.SetLevelByString(*logLevel)
createTable(forceDrop)
{
timing("insert test data", func() {
insertTestData(*concurrent)
})
}
}
示例11: SetUpSuite
func (s *testKVSuite) SetUpSuite(c *C) {
store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
c.Assert(err, IsNil)
s.s = store
cacheS, _ := tidb.NewStore(fmt.Sprintf("%s://%s", *testStore, *testStorePath))
c.Assert(cacheS, Equals, store)
log.SetLevelByString("warn")
}
示例12: main
func main() {
log.SetLevelByString(*logLevel)
timing("create table", func() {
createTable()
})
timing("insert test data", func() {
insertTestData(*rows, *concurrent)
})
}
示例13: main
func main() {
flag.Parse()
log.SetLevelByString("warn")
go http.ListenAndServe(":9191", nil)
value := make([]byte, *valueSize)
t := time.Now()
batchRawPut(value)
fmt.Printf("\nelapse:%v, total %v\n", time.Since(t), *dataCnt)
}
示例14: SetUpSuite
func (s *testMainSuite) SetUpSuite(c *C) {
s.dbName = "test_main_db"
s.createDBSQL = fmt.Sprintf("create database if not exists %s;", s.dbName)
s.dropDBSQL = fmt.Sprintf("drop database %s;", s.dbName)
s.useDBSQL = fmt.Sprintf("use %s;", s.dbName)
s.createTableSQL = `
CREATE TABLE tbl_test(id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));
CREATE TABLE tbl_test1(id INT NOT NULL DEFAULT 2, name varchar(255), PRIMARY KEY(id), INDEX name(name));
CREATE TABLE tbl_test2(id INT NOT NULL DEFAULT 3, name varchar(255), PRIMARY KEY(id));`
s.selectSQL = `SELECT * from tbl_test;`
runtime.GOMAXPROCS(runtime.NumCPU())
log.SetLevelByString("error")
}
示例15: main
func main() {
metric.RunMetric(3 * time.Second)
printer.PrintTiDBInfo()
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *lease <= 0 {
log.Fatalf("invalid lease seconds %d", *lease)
}
tidb.SetSchemaLease(time.Duration(*lease) * time.Second)
cfg := &server.Config{
Addr: fmt.Sprintf(":%s", *port),
LogLevel: *logLevel,
}
log.SetLevelByString(cfg.LogLevel)
store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
if err != nil {
log.Fatal(err)
}
var driver server.IDriver
driver = server.NewTiDBDriver(store)
var svr *server.Server
svr, err = server.NewServer(cfg, driver)
if err != nil {
log.Fatal(err)
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
log.Infof("Got signal [%d] to exit.", sig)
svr.Close()
os.Exit(0)
}()
log.Error(svr.Run())
}