當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log4go.Critical函數代碼示例

本文整理匯總了Golang中code/google/com/p/log4go.Critical函數的典型用法代碼示例。如果您正苦於以下問題:Golang Critical函數的具體用法?Golang Critical怎麽用?Golang Critical使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Critical函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RemoveColumnIfExists

func (ss SqlStore) RemoveColumnIfExists(tableName string, columnName string) bool {
	count, err := ss.GetMaster().SelectInt(
		`SELECT 
		    COUNT(0) AS column_exists
		FROM
		    information_schema.COLUMNS
		WHERE
		    TABLE_SCHEMA = DATABASE()
		        AND TABLE_NAME = ?
		        AND COLUMN_NAME = ?`,
		tableName,
		columnName,
	)
	if err != nil {
		l4g.Critical("Failed to check if column exists %v", err)
		time.Sleep(time.Second)
		panic("Failed to check if column exists " + err.Error())
	}

	if count == 0 {
		return false
	}

	_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " DROP COLUMN " + columnName)
	if err != nil {
		l4g.Critical("Failed to drop column %v", err)
		time.Sleep(time.Second)
		panic("Failed to drop column " + err.Error())
	}

	return true
}
開發者ID:andrewcarreiro,項目名稱:platform,代碼行數:32,代碼來源:sql_store.go

示例2: RedisClient

func RedisClient() *redis.Client {

	if client == nil {

		addr := utils.Cfg.RedisSettings.DataSource

		client = redis.NewTCPClient(&redis.Options{
			Addr:     addr,
			Password: "",
			DB:       0,
			PoolSize: utils.Cfg.RedisSettings.MaxOpenConns,
		})

		l4g.Info("Pinging redis at '%v'", addr)
		pong, err := client.Ping().Result()

		if err != nil {
			l4g.Critical("Failed to open redis connection to '%v' err:%v", addr, err)
			time.Sleep(time.Second)
			panic("Failed to open redis connection " + err.Error())
		}

		if pong != "PONG" {
			l4g.Critical("Failed to ping redis connection to '%v' err:%v", addr, err)
			time.Sleep(time.Second)
			panic("Failed to open ping connection " + err.Error())
		}
	}

	return client
}
開發者ID:Dahlgren,項目名稱:platform,代碼行數:31,代碼來源:redis.go

示例3: CreateColumnIfNotExists

func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, mySqlColType string, postgresColType string, defaultValue string) bool {

	if ss.DoesColumnExist(tableName, columnName) {
		return false
	}

	if utils.Cfg.SqlSettings.DriverName == "postgres" {
		_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + postgresColType + " DEFAULT '" + defaultValue + "'")
		if err != nil {
			l4g.Critical("Failed to create column %v", err)
			time.Sleep(time.Second)
			panic("Failed to create column " + err.Error())
		}

		return true

	} else if utils.Cfg.SqlSettings.DriverName == "mysql" {
		_, err := ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + mySqlColType + " DEFAULT '" + defaultValue + "'")
		if err != nil {
			l4g.Critical("Failed to create column %v", err)
			time.Sleep(time.Second)
			panic("Failed to create column " + err.Error())
		}

		return true

	} else {
		l4g.Critical("Failed to create column because of missing driver")
		time.Sleep(time.Second)
		panic("Failed to create column because of missing driver")
	}
}
開發者ID:saitodisse,項目名稱:platform,代碼行數:32,代碼來源:sql_store.go

示例4: CreateColumnIfNotExists

func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool {
	count, err := ss.GetMaster().SelectInt(
		`SELECT 
		    COUNT(0) AS column_exists
		FROM
		    information_schema.COLUMNS
		WHERE
		    TABLE_SCHEMA = DATABASE()
		        AND TABLE_NAME = ?
		        AND COLUMN_NAME = ?`,
		tableName,
		columnName,
	)
	if err != nil {
		l4g.Critical("Failed to check if column exists %v", err)
		time.Sleep(time.Second)
		panic("Failed to check if column exists " + err.Error())
	}

	if count > 0 {
		return false
	}

	_, err = ss.GetMaster().Exec("ALTER TABLE " + tableName + " ADD " + columnName + " " + colType + " DEFAULT '" + defaultValue + "'" + " AFTER " + afterName)
	if err != nil {
		l4g.Critical("Failed to create column %v", err)
		time.Sleep(time.Second)
		panic("Failed to create column " + err.Error())
	}

	return true
}
開發者ID:andrewcarreiro,項目名稱:platform,代碼行數:32,代碼來源:sql_store.go

示例5: DoesColumnExist

func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
	if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
		count, err := ss.GetMaster().SelectInt(
			`SELECT COUNT(0)
			FROM   pg_attribute
			WHERE  attrelid = $1::regclass
			AND    attname = $2
			AND    NOT attisdropped`,
			strings.ToLower(tableName),
			strings.ToLower(columnName),
		)

		if err != nil {
			if err.Error() == "pq: relation \""+strings.ToLower(tableName)+"\" does not exist" {
				return false
			}

			l4g.Critical("Failed to check if column exists %v", err)
			time.Sleep(time.Second)
			panic("Failed to check if column exists " + err.Error())
		}

		return count > 0

	} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {

		count, err := ss.GetMaster().SelectInt(
			`SELECT
		    COUNT(0) AS column_exists
		FROM
		    information_schema.COLUMNS
		WHERE
		    TABLE_SCHEMA = DATABASE()
		        AND TABLE_NAME = ?
		        AND COLUMN_NAME = ?`,
			tableName,
			columnName,
		)

		if err != nil {
			l4g.Critical("Failed to check if column exists %v", err)
			time.Sleep(time.Second)
			panic("Failed to check if column exists " + err.Error())
		}

		return count > 0

	} else {
		l4g.Critical("Failed to check if column exists because of missing driver")
		time.Sleep(time.Second)
		panic("Failed to check if column exists because of missing driver")
	}

}
開發者ID:noahd1,項目名稱:platform,代碼行數:54,代碼來源:sql_store.go

示例6: createIndexIfNotExists

func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, fullText bool) {

	if utils.Cfg.SqlSettings.DriverName == "postgres" {
		_, err := ss.GetMaster().SelectStr("SELECT to_regclass($1)", indexName)
		// It should fail if the index does not exist
		if err == nil {
			return
		}

		query := ""
		if fullText {
			query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + columnName + "))"
		} else {
			query = "CREATE INDEX " + indexName + " ON " + tableName + " (" + columnName + ")"
		}

		_, err = ss.GetMaster().Exec(query)
		if err != nil {
			l4g.Critical("Failed to create index %v", err)
			time.Sleep(time.Second)
			panic("Failed to create index " + err.Error())
		}
	} else if utils.Cfg.SqlSettings.DriverName == "mysql" {

		count, err := ss.GetMaster().SelectInt("SELECT COUNT(0) AS index_exists FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() and table_name = ? AND index_name = ?", tableName, indexName)
		if err != nil {
			l4g.Critical("Failed to check index %v", err)
			time.Sleep(time.Second)
			panic("Failed to check index " + err.Error())
		}

		if count > 0 {
			return
		}

		fullTextIndex := ""
		if fullText {
			fullTextIndex = " FULLTEXT "
		}

		_, err = ss.GetMaster().Exec("CREATE " + fullTextIndex + " INDEX " + indexName + " ON " + tableName + " (" + columnName + ")")
		if err != nil {
			l4g.Critical("Failed to create index %v", err)
			time.Sleep(time.Second)
			panic("Failed to create index " + err.Error())
		}
	} else {
		l4g.Critical("Failed to create index because of missing driver")
		time.Sleep(time.Second)
		panic("Failed to create index because of missing driver")
	}
}
開發者ID:alphafeng,項目名稱:platform,代碼行數:52,代碼來源:sql_store.go

示例7: Start

// Finalizes Application configuration and starts the application webserver
func (a *Application) Start() error {
	http.HandleFunc("/", a.outerHandler)

	err := a.Server.ListenAndServe()
	log.Critical(err)
	return err
}
開發者ID:johnnadratowski,項目名稱:droplet,代碼行數:8,代碼來源:droplet.go

示例8: DoesColumnExist

func (ss SqlStore) DoesColumnExist(tableName string, columnName string) bool {
	// XXX TODO FIXME this should be removed after 0.6.0
	if utils.Cfg.SqlSettings.DriverName == "postgres" {
		return false
	}

	count, err := ss.GetMaster().SelectInt(
		`SELECT
		    COUNT(0) AS column_exists
		FROM
		    information_schema.COLUMNS
		WHERE
		    TABLE_SCHEMA = DATABASE()
		        AND TABLE_NAME = ?
		        AND COLUMN_NAME = ?`,
		tableName,
		columnName,
	)
	if err != nil {
		l4g.Critical("Failed to check if column exists %v", err)
		time.Sleep(time.Second)
		panic("Failed to check if column exists " + err.Error())
	}

	return count > 0
}
開發者ID:alphafeng,項目名稱:platform,代碼行數:26,代碼來源:sql_store.go

示例9: ListAntUsbDevices

func (ctx *AntUsbContext) ListAntUsbDevices() ([]*AntUsbDevice, error) {
	devs, err := ctx.usb.ListDevices(func(desc *usb.Descriptor) bool {
		log4go.Debug("Found %03d.%03d %s:%s %s\n", desc.Bus, desc.Address, desc.Vendor, desc.Product, usbid.Describe(desc))

		// The usbid package can be used to print out human readable information.
		log4go.Debug("  Protocol: %s\n", usbid.Classify(desc))

		// We are looking for the specific vendor and device
		if desc.Vendor == ANT_VENDOR_ID && desc.Product == ANT_PRODUCT_ID {
			log4go.Debug("This is an ANT device")

			// The configurations can be examined from the Descriptor, though they can only
			// be set once the device is opened.  All configuration references must be closed,
			// to free up the memory in libusb.
			for _, cfg := range desc.Configs {
				// This loop just uses more of the built-in and usbid pretty printing to list
				// the USB devices.
				log4go.Debug("  %s:\n", cfg)
				for _, alt := range cfg.Interfaces {
					log4go.Debug("    --------------\n")
					for _, iface := range alt.Setups {
						log4go.Debug("(iface)    %s\n", iface)
						log4go.Debug("(classify)      %s\n", usbid.Classify(iface))
						for _, end := range iface.Endpoints {
							log4go.Debug("(end)      %s\n", end)
							log4go.Debug("	number: %s\n", end.Number())
							log4go.Debug("	address: %s\n", end.Address)
							log4go.Debug("	sync: %s\n", end.SynchAddress)
						}
					}
				}
				log4go.Debug("    --------------\n")
			}

			return true
		}

		return false
	})

	// ListDevices can occaionally fail, so be sure to check its return value.
	if err != nil {
		log4go.Critical("list: %s", err)
		return nil, err
	}

	nDevices := len(devs)
	channels := make([]*AntUsbDevice, nDevices)
	for i := 0; i < len(devs); i++ {
		usbDevice := devs[i]
		channels[i], err = newAntUsbDevice(usbDevice)

		if err != nil {
			panic(err)
		}
	}
	return channels, nil
}
開發者ID:pjvds,項目名稱:antport,代碼行數:58,代碼來源:AntUsbContext.go

示例10: setupConnection

func setupConnection(con_type string, driver string, dataSource string, maxIdle int, maxOpen int, trace bool) *gorp.DbMap {

	charset := ""
	if strings.Index(dataSource, "?") > -1 {
		charset = "&charset=utf8mb4,utf8"
	} else {
		charset = "?charset=utf8mb4,utf8"
	}

	db, err := dbsql.Open(driver, dataSource+charset)
	if err != nil {
		l4g.Critical("Failed to open sql connection to '%v' err:%v", dataSource, err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection" + err.Error())
	}

	l4g.Info("Pinging sql %v database at '%v'", con_type, dataSource)
	err = db.Ping()
	if err != nil {
		l4g.Critical("Failed to ping db err:%v", err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection " + err.Error())
	}

	db.SetMaxIdleConns(maxIdle)
	db.SetMaxOpenConns(maxOpen)

	var dbmap *gorp.DbMap

	if driver == "sqlite3" {
		dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}}
	} else if driver == "mysql" {
		dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}}
	} else {
		l4g.Critical("Failed to create dialect specific driver")
		time.Sleep(time.Second)
		panic("Failed to create dialect specific driver " + err.Error())
	}

	if trace {
		dbmap.TraceOn("", sqltrace.New(os.Stdout, "sql-trace:", sqltrace.Lmicroseconds))
	}

	return dbmap
}
開發者ID:andrewcarreiro,項目名稱:platform,代碼行數:45,代碼來源:sql_store.go

示例11: DoesTableExist

func (ss SqlStore) DoesTableExist(tableName string) bool {
	if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
		count, err := ss.GetMaster().SelectInt(
			`SELECT count(relname) FROM pg_class WHERE relname=$1`,
			strings.ToLower(tableName),
		)

		if err != nil {
			l4g.Critical("Failed to check if table exists %v", err)
			time.Sleep(time.Second)
			panic("Failed to check if table exists " + err.Error())
		}

		return count > 0

	} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {

		count, err := ss.GetMaster().SelectInt(
			`SELECT
		    COUNT(0) AS table_exists
			FROM
			    information_schema.TABLES
			WHERE
			    TABLE_SCHEMA = DATABASE()
			        AND TABLE_NAME = ?
		    `,
			tableName,
		)

		if err != nil {
			l4g.Critical("Failed to check if table exists %v", err)
			time.Sleep(time.Second)
			panic("Failed to check if table exists " + err.Error())
		}

		return count > 0

	} else {
		l4g.Critical("Failed to check if column exists because of missing driver")
		time.Sleep(time.Second)
		panic("Failed to check if column exists because of missing driver")
	}

}
開發者ID:noahd1,項目名稱:platform,代碼行數:44,代碼來源:sql_store.go

示例12: Serve

func Serve(info *ServeInfo) {
	ctrl := info.promiseTicketController

	http.Handle("/", http.FileServer(http.Dir("static")))
	http.HandleFunc("/api/v1/promise", func(w http.ResponseWriter, r *http.Request) {
		ctrl.Handle(w, r)
	})

	log.Info("Serving at " + info.uri)
	log.Critical(http.ListenAndServe(info.uri, Log(http.DefaultServeMux)))
}
開發者ID:pjvds,項目名稱:promise,代碼行數:11,代碼來源:main.go

示例13: setupConnection

func setupConnection(con_type string, driver string, dataSource string, maxIdle int, maxOpen int, trace bool) *gorp.DbMap {

	db, err := dbsql.Open(driver, dataSource)
	if err != nil {
		l4g.Critical("Failed to open sql connection to err:%v", err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection" + err.Error())
	}

	l4g.Info("Pinging sql %v database", con_type)
	err = db.Ping()
	if err != nil {
		l4g.Critical("Failed to ping db err:%v", err)
		time.Sleep(time.Second)
		panic("Failed to open sql connection " + err.Error())
	}

	db.SetMaxIdleConns(maxIdle)
	db.SetMaxOpenConns(maxOpen)

	var dbmap *gorp.DbMap

	if driver == "sqlite3" {
		dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.SqliteDialect{}}
	} else if driver == model.DATABASE_DRIVER_MYSQL {
		//dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8MB4"}}
		dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.MySQLDialect{Engine: "MyISAM", Encoding: "UTF8"}}
	} else if driver == model.DATABASE_DRIVER_POSTGRES {
		dbmap = &gorp.DbMap{Db: db, TypeConverter: mattermConverter{}, Dialect: gorp.PostgresDialect{}}
	} else {
		l4g.Critical("Failed to create dialect specific driver")
		time.Sleep(time.Second)
		panic("Failed to create dialect specific driver " + err.Error())
	}

	if trace {
		dbmap.TraceOn("", sqltrace.New(os.Stdout, "sql-trace:", sqltrace.Lmicroseconds))
	}

	return dbmap
}
開發者ID:circuitbomb,項目名稱:platform,代碼行數:41,代碼來源:sql_store.go

示例14: main

func main() {
	flag.Parse()
	// Change to l4g.DEBUG to see *lots* of debugging information.
	l4g.AddFilter("stdout", l4g.WARNING, l4g.NewConsoleLogWriter())
	if len(flag.Args()) != 1 {
		fmt.Fprintf(os.Stderr, "Usage: %v <infohash>\n\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "Example infohash: d1c5676ae7ac98e8b19f63565905105e3c4c37a2\n")
		flag.PrintDefaults()
		os.Exit(1)
	}
	ih, err := dht.DecodeInfoHash(flag.Args()[0])
	if err != nil {
		l4g.Critical("DecodeInfoHash error: %v\n", err)
		os.Exit(1)
	}

	// This is a hint to the DHT of the minimum number of peers it will try to
	// find for the given node. This is not a reliable limit. In the future this
	// might be moved to "PeersRequest()", so the controlling client can have
	// different targets at different moments or for different infohashes.
	targetNumPeers := 5
	d, err := dht.NewDHTNode(dhtPortUDP, targetNumPeers, false)
	if err != nil {
		l4g.Critical("NewDHTNode error: %v", err)
		os.Exit(1)

	}
	// For debugging.
	go http.ListenAndServe(fmt.Sprintf(":%d", httpPortTCP), nil)

	go d.DoDHT()
	go drainresults(d)

	for {
		// Give the DHT some time to "warm-up" its routing table.
		time.Sleep(5 * time.Second)

		d.PeersRequest(string(ih), false)
	}
}
開發者ID:nhelke,項目名稱:dht,代碼行數:40,代碼來源:main.go

示例15: GetColumnDataType

func (ss SqlStore) GetColumnDataType(tableName, columnName string) string {
	dataType, err := ss.GetMaster().SelectStr("SELECT data_type FROM INFORMATION_SCHEMA.COLUMNS where table_name = :Tablename AND column_name = :Columnname", map[string]interface{}{
		"Tablename":  tableName,
		"Columnname": columnName,
	})
	if err != nil {
		l4g.Critical("Failed to get data type for column %s from table %s: %v", columnName, tableName, err.Error())
		time.Sleep(time.Second)
		panic("Failed to get get data type for column " + columnName + " from table " + tableName + ": " + err.Error())
	}

	return dataType
}
開發者ID:mf1389004071,項目名稱:platform,代碼行數:13,代碼來源:sql_store.go


注:本文中的code/google/com/p/log4go.Critical函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。