本文整理汇总了Golang中n.Log函数的典型用法代码示例。如果您正苦于以下问题:Golang Log函数的具体用法?Golang Log怎么用?Golang Log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (self *sqlTests) Run(runner SqlTestRunner, T *testing.T) (rtn bool) {
// Shortcut; stop if we're not in testing mode
if !RUN_DRIVER_TESTS {
return true
}
var current = "None"
defer func() {
var e = recover()
if e != nil {
n.Log("Failed while running test \"%s\": %s", current, e)
n.Log("%s", debug.Stack())
rtn = false
}
}()
var tt = reflect.TypeOf(self)
var tv = reflect.ValueOf(self)
var mc = tt.NumMethod()
for i := 0; i < mc; i++ {
var test_method = tt.Method(i)
var test_name = test_method.Name
if strings.HasPrefix(test_name, "Test_") {
current = test_name
var test_method_instance = tv.Method(i)
var test_method_args = []reflect.Value{reflect.ValueOf(runner), reflect.ValueOf(T)}
test_method_instance.Call(test_method_args)
}
}
return true
}
示例2: Next
// Get the next row, return nil when none left
func (self *Rowset) Next() map[string]interface{} {
var rtn map[string]interface{} = nil
if self.Rows != nil {
var cols, cerr = self.Rows.Columns()
if cerr != nil {
n.Log("Failed to query column list on db rows: %s", cerr.Error())
} else if len(cols) == 0 {
n.Log("Failed to query column list on db rows: No columns in result set")
} else {
if self.Rows.Next() {
rtn = Scan(self.Rows)
self.Worker.ApplySchema(self, rtn)
}
}
return rtn
}
// No rows? Ok! Return a value
var tmp = self.Values.Front()
if tmp != nil {
self.Values.Remove(tmp)
rtn = tmp.Value.(map[string]interface{})
self.Worker.ApplySchema(self, rtn)
}
return rtn
}
示例3: Int64
// Return an int64 url value
func (self *url) Int64(id string) int64 {
var rtn int64 = 0
var raw, found = self.c.vars[id]
if found {
var _, err = fmt.Sscanf(raw, "%d", &rtn)
if err != nil {
n.Log("Failed reading incoming url param: %s is not int64", raw[0])
n.Log(err.Error())
}
}
return rtn
}
示例4: Setup
func (self *sqlTestRunner) Setup(T *testing.T) (test.Assert, nsql.Sql) {
var assert = test.New.Assert(T)
var instance = New.Sql(TEST_ROOT_URI)
var _, err = instance.Raw("CREATE DATABASE testing")
if err != nil {
// n.Log("Failed to create database: %s", err.Error())
}
instance.Close()
instance = New.Sql(TEST_URI)
instance.Raw("DROP TABLE IF EXISTS " + self.Table())
_, err = instance.Raw("CREATE TABLE " + self.Table() + ` (
id SERIAL,
string_value VARCHAR(100),
int_value INT,
long_value INT,
double_value DOUBLE PRECISION,
bool_value BOOL,
datetime_value TIMESTAMP,
text_value TEXT,
PRIMARY KEY (id)
)`)
if err != nil {
n.Log("Failed to create table: %s", err.Error())
}
return assert, instance
}
示例5: Delete
// Arbitrary limit; max of 100 index or we're doing something weird.
func (self *index) Delete(id int64) {
var items, err = self.db.All("worker.Index", 0, 100)
if err != nil {
n.Log("Failed to remove index: %s", err.Error())
}
for _, v := range items {
var index = v.(*model.Index)
var tmp = make([]int64, index.Size, index.Size)
var update = false
var offset = 0
for j := 0; j < index.Size; j++ {
if index.Ids[j] != id {
tmp[offset] = index.Ids[j]
offset++
} else {
update = true
}
}
if update {
index.Ids = tmp
self.set(index)
}
}
}
示例6: scan
// Scan values from the database
func scan(cols []string, rows *sql.Rows) map[string]interface{} {
var rtn = map[string]interface{}{}
// Create scanner array
var values []interface{}
var generic = reflect.TypeOf(values).Elem()
for i := 0; i < len(cols); i++ {
values = append(values, reflect.New(generic).Interface())
}
// Scan!
var err = rows.Scan(values...)
if err != nil {
n.Log("Driver failed to scan values: %s", err.Error())
return nil
}
// Convert into native types
for i := 0; i < len(cols); i++ {
var raw_value = *(values[i].(*interface{}))
var raw_type = reflect.TypeOf(raw_value)
switch {
case raw_type == reflect.TypeOf(int64(0)):
rtn[cols[i]] = raw_value.(int64)
}
}
return rtn
}
示例7: Init
// Init stuff
func (self *recordSet) Init() error {
var err = os.MkdirAll(self.RecordsPath(), 0755)
if err != nil {
n.Log("Error creating record set: %s", err)
}
return err
}
示例8: Keys
func (self *recordSet) Keys(offset int, count int) []int64 {
_ = self.Init()
var sofar = 0
var hits = 0
var all = make([]int64, count)
filepath.Walk(self.RecordsPath(), func(path string, info os.FileInfo, err error) error {
if err != nil {
n.Log("Error walking record set: %s", err)
}
if info != nil {
if !info.IsDir() {
if strings.Count(info.Name(), ".") == 1 {
if sofar >= offset {
var _, file = filepath.Split(path)
var key int64
var _, err = fmt.Sscanf(file, "R%d.json", &key)
if err == nil && hits < count {
all[hits] = key
hits++
}
}
sofar++
}
}
}
return nil
})
all = all[:hits]
return all
}
示例9: Scan
// The sql api isn't very friendly; this function reads a single row from
// the database and converts it into native driver types.
//
// You may want to extend this to provide complex type mapping like
// DATETIME for sqlite, etc.
//
// Pass in a rows() that already has had next called on it; this function
// does not invoke Next().
//
// If unable to process the given rowset, the return is nil.
func Scan(rows *sql.Rows) map[string]interface{} {
var rtn map[string]interface{} = nil
if rows != nil {
var cols, cerr = rows.Columns()
if cerr != nil {
n.Log("Failed to query column list on db rows: %s", cerr.Error())
} else if len(cols) == 0 {
n.Log("Failed to query column list on db rows: No columns in result set")
} else {
rtn = scan(cols, rows)
}
} else {
n.Log("Invalid row set: nil")
}
return rtn
}
示例10: View
// Render a template with a layout file.
// Use {{define ""}} .. {{end}} in the template.
func (self *ControllerBase) View(templates []string, data map[string]interface{}, w http.ResponseWriter) {
self.templates = nil
for _, v := range templates {
var err = self.loadTemplate(v, v)
if err != nil {
return
}
}
var ee = self.templates.Execute(w, data)
if ee != nil {
// TODO: Controller common error handling.
n.Log("\nError: failed executing templates: %s", templates[0])
n.Log("%s", ee.Error())
}
}
示例11: RecordsPath
// Return path for a records
func (self *recordSet) RecordsPath() string {
var root, err = filepath.Abs("data")
if err != nil {
n.Log("Failed to resolve base path: %s", err)
}
var rtn = filepath.Join(root, self.Type.Name())
return rtn
}
示例12: newSql
func newSql(uri string) nsql.Sql {
var db, err = gsql.Open("mysql", uri)
if err != nil {
n.Log("Failed to open database connection: %s", err.Error())
return nil
}
return &sql{
db: db,
factory: newSqlFactory(),
}
}
示例13: Validate
func (self *configBase) Validate() bool {
var failed = false
for k, _ := range self.requires {
if !self.Has(k) {
var _, found = self.defaults[k]
if !found {
n.Log("Missing config key: %s", k)
failed = true
}
}
}
return !failed
}
示例14: newStore
func newStore(drivers ...interface{} /* Driver */) (out Store) {
defer func() {
var f = recover()
if f != nil {
n.Log("Failed to create Store: %s", f)
out = nil
}
}()
// Try resolving a driver if one isn't provided
var raw = n.Resolve(rf.TypeOf((*Driver)(nil)), 0, drivers...)
if raw == nil {
n.Log("Failed to create Store: No binding for Driver found")
return nil
}
var rtn = &store{
types: make(map[string]rf.Type),
driver: raw.(Driver),
}
return rtn
}
示例15: Resolve
// Invoke action on controller
func Resolve(controller string, action string, vars map[string]string, w http.ResponseWriter, r *http.Request) {
var binding, found = actions[controller]
if found {
var handler, found = binding.Map[action]
if found {
var c = web.New.Context(w, r, vars)
var v = rf.ValueOf(handler)
var args = []rf.Value{rf.ValueOf(binding.Instance), rf.ValueOf(c)}
v.Call(args)
return
}
}
fmt.Fprintf(w, "Not found")
n.Log(": No match for %s::%s", controller, action)
}