本文整理汇总了Golang中gopkg/in/inconshreveable/log15/v2.Logger类的典型用法代码示例。如果您正苦于以下问题:Golang Logger类的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
// Init ...
func (rthink *RethinkDBImpl) Init(conntype string, dbhost string, username string, password string, port int, dbname string, log log.Logger, hosts ...string) error {
var retErr error
if conntype == "cluster" {
session, err := r.Connect(r.ConnectOpts{
Addresses: hosts,
Database: dbname,
AuthKey: password,
})
retErr = err
if err != nil {
log.Crit("Got error when connect database, the error is '%v'", err)
return retErr
}
rthink.Session = session
} else {
session, err := r.Connect(r.ConnectOpts{
Address: dbhost,
Database: dbname,
AuthKey: password,
})
retErr = err
if err != nil {
log.Crit("Got error when connect database, the error is '%v'", err)
return retErr
}
rthink.Session = session
}
fmt.Println("Rethink Connected")
return nil
}
示例2: Logger
func Logger(inner http.Handler, name string, logger log.Logger) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
inner.ServeHTTP(w, r)
//fmt.Printf("%s\t%s\t%s\t%s", r.Method, r.RequestURI, name, time.Since(start))
logger.Info("Request", "method", r.Method, "uri", r.RequestURI, "name", name, "duration", time.Since(start))
})
}
示例3: loggerFn
func loggerFn(handler http.Handler, logger log.Logger, clientIP string, rw *hh.ResponseWriter, req *http.Request) {
start := time.Now()
handler.ServeHTTP(rw, req)
switch rw.Status() {
case 200, 307, 0: // 0 == 200 OK
default:
logger.Info("request completed", "method", req.Method, "path", req.URL.Path, "client_ip", clientIP, "status", rw.Status(), "duration", time.Since(start))
}
}
示例4: matchQuery
// matchQuery takes a MongoDB-like query object and returns wether or not
// the given document match the query.
// The document will be flattened before the checks, to handle the dot-notation.
func matchQuery(qLogger log.Logger, query, odoc map[string]interface{}) bool {
logger := qLogger.New("subquery", query, "doc", odoc)
ok := true
// Flatten the map to handle dot-notation handling
doc := flattenMap(odoc, "", ".")
for key, eval := range query {
switch key {
case "$or":
res := false
for _, iexpr := range eval.([]interface{}) {
expr := iexpr.(map[string]interface{})
res = res || matchQuery(qLogger, expr, doc)
}
if !res {
ok = false
}
case "$and":
res := true
for _, iexpr := range eval.([]interface{}) {
expr := iexpr.(map[string]interface{})
res = res && matchQuery(qLogger, expr, doc)
}
ok = res
default:
// TODO(ts) make this part cleaner
// (check orignal doc VS flattend doc)
val, check := doc[key]
oval, err := getPath(key, odoc)
if !check && err != nil {
logger.Debug("key not found")
return false
}
// `val` (the value of the queried doc) must be:
// - a standard type: nil, int, float64, string, bool
// - a []interface[}
// It can't ba `map[string]interface{}` since maps are flattened
switch vval := oval.(type) {
// If it's an array, the doc is returned if a lest one of the doc match the query
case []interface{}:
res := false
for _, li := range vval {
res = res || matchQueryValue(eval, li)
}
if res {
ok = ok && true
}
default:
ok = ok && matchQueryValue(eval, val)
}
}
// logger.Debug("subquery res", "ok", ok, "key", key, "eval", eval)
}
return ok
}
示例5: NewProxy
func NewProxy(c net.Conn, root log.Logger) *Proxy {
logger := root.New(
"remoteAddr", c.RemoteAddr(),
"localAddr", c.LocalAddr(),
)
ret := &Proxy{
remoteConn: c,
logger: logger,
errChan: make(chan struct{}),
}
return ret
}
示例6: setFilterHandler
func setFilterHandler(level string, logger log.Logger, handler log.Handler) error {
if level == "none" {
logger.SetHandler(log.DiscardHandler())
return nil
}
lvl, err := log.LvlFromString(level)
if err != nil {
return fmt.Errorf("Bad log level: %v", err)
}
logger.SetHandler(log.LvlFilterHandler(lvl, handler))
return nil
}
示例7: New
func New(logger log.Logger, kvStore client.KvStorer, blobStore client.BlobStorer) *DocStoreExt {
indexPath := filepath.Join(pathutil.VarDir(), "docstore.bleve")
index, err := openIndex(indexPath)
if err != nil {
// TODO(tsileo): returns an error instead
panic(err)
}
logger.Debug("Bleve index init", "index-path", indexPath)
return &DocStoreExt{
kvStore: kvStore,
blobStore: blobStore,
index: index,
logger: logger,
}
}
示例8: LogForRequest
func LogForRequest(l log.Logger, r *http.Request) log.Logger {
ctx := log.Ctx{
"method": r.Method,
"host": r.Host,
"url": r.URL,
"requesturi": r.RequestURI,
"remote": r.RemoteAddr,
"proto": r.Proto,
// "header": r.Header,
}
if val, ok := r.Header["X-Forwarded-For"]; ok {
ctx["x_forward_for"] = val
}
if val, ok := r.Header["X-Authenticated-User"]; ok {
ctx["x_authenticate_user"] = val
}
return l.New(ctx)
}
示例9: newMailer
func newMailer(conf ini.File, logger log.Logger) (Mailer, error) {
mailConf := conf.Section("mail")
if len(mailConf) == 0 {
return nil, nil
}
smtpAddr, ok := mailConf["smtp_server"]
if !ok {
return nil, errors.New("Missing mail -- smtp_server")
}
smtpPort, _ := mailConf["port"]
if smtpPort == "" {
smtpPort = "587"
}
fromAddr, ok := mailConf["from_address"]
if !ok {
return nil, errors.New("Missing mail -- from_address")
}
rootURL, ok := mailConf["root_url"]
if !ok {
return nil, errors.New("Missing mail -- root_url")
}
username, _ := mailConf["username"]
password, _ := mailConf["password"]
auth := smtp.PlainAuth("", username, password, smtpAddr)
logger = logger.New("module", "mail")
mailer := &SMTPMailer{
ServerAddr: smtpAddr + ":" + smtpPort,
Auth: auth,
From: fromAddr,
rootURL: rootURL,
logger: logger,
}
return mailer, nil
}
示例10: InitDataStore
// InitDataStore ...
func (datastore *DataStore) InitDataStore(storeType string, connDetails map[string]interface{}, log log.Logger) error {
var err error
datastore.StoreType = storeType
if storeType == "rdbms" {
rdbms := RDBMSImpl{}
err = rdbms.Init(connDetails["dbtype"].(string), connDetails["host"].(string), connDetails["username"].(string), connDetails["password"].(string), int(connDetails["port"].(float64)), connDetails["database"].(string), log)
if err != nil {
log.Crit("Got error when connect database, the error is '%v'", err)
}
datastore.RDBMS = rdbms
}
return err
}
示例11: exec
func (lua *LuaExt) exec(reqLogger log.Logger, app *LuaApp, appID, reqId, script string, w http.ResponseWriter, r *http.Request) int {
// FIXME(tsileo) a debug mode, with a defer/recover
// also parse the Lu error and show the bugging line!
start := time.Now()
httpClient := &http.Client{}
// Initialize internal Lua module written in Go
logger := loggerModule.New(reqLogger.New("ctx", "Lua"), start, reqId)
response := responseModule.New()
request := requestModule.New(r, reqId, lua.authFunc)
blobstore := blobstoreModule.New(lua.blobStore)
kvstore := kvstoreModule.New(lua.kvStore)
bewit := bewitModule.New(reqLogger.New("ctx", "Lua bewit module"), r)
template := templateModule.New()
// Initialize Lua state
L := luamod.NewState()
defer L.Close()
setCustomGlobals(L)
L.PreloadModule("request", request.Loader)
L.PreloadModule("response", response.Loader)
L.PreloadModule("logger", logger.Loader)
L.PreloadModule("blobstore", blobstore.Loader)
L.PreloadModule("kvstore", kvstore.Loader)
L.PreloadModule("bewit", bewit.Loader)
L.PreloadModule("template", template.Loader)
// TODO(tsileo) docstore module
// TODO(tsileo) cookies module
// TODO(tsileo) lru module
// TODO(tsileo) cache module => to cache response
// TODO(tsileo) load module from github directly?
// TODO(tsileo) ETag support
// 3rd party module
luajson.Preload(L)
L.PreloadModule("http", gluahttp.NewHttpModule(httpClient).Loader)
// Set some global variables
L.SetGlobal("reqID", luamod.LString(reqId))
L.SetGlobal("appID", luamod.LString(appID))
// Execute the code
if err := L.DoString(script); err != nil {
// FIXME better error, with debug mode?
panic(err)
}
// Apply the Response object to the actual response
response.WriteTo(w)
// TODO save the logRecords in the AppStats and find a way to serve them over Server-Sent Events
// keep them in memory with the ability to dump them in bulk as blob for later query
// logRecords := logger.Records()
for _, logRecord := range logger.Records() {
app.logs = append(app.logs, logRecord)
}
reqLogger.Info("Script executed", "response", response, "duration", time.Since(start))
return response.Status()
}
示例12: newRouter
func newRouter(fallback ldap.Backend, logger log.Logger) *ldap.RouteMux {
defaults := &DefaultsBackend{
Log: logger.New(log.Ctx{"type": "backend", "backend": "defaults"}),
}
//Create routes bindings
routes := ldap.NewRouteMux(logger)
// buildins
routes.Search(defaults).
BaseDn("").
Scope(ldap.SearchRequestScopeBaseObject).
Filter("(objectclass=*)").
Label("Search - ROOT DSE")
routes.Search(defaults).
BaseDn("o=Pronoc, c=Net").
Scope(ldap.SearchRequestScopeBaseObject).
Label("Search - Company Root")
routes.Extended(defaults).
RequestName(ldap.NoticeOfStartTLS).Label("StartTLS")
//default routes
routes.NotFound(fallback)
routes.Abandon(fallback)
routes.Compare(fallback)
routes.Delete(fallback)
routes.Modify(fallback)
routes.Extended(fallback).
RequestName(ldap.NoticeOfWhoAmI).Label("Ext - WhoAmI")
routes.Extended(fallback).Label("Ext - Generic")
routes.Add(fallback).Label("Default Add")
routes.Bind(fallback).Label("Default Bind")
routes.Search(fallback).Label("Default Search")
return routes
}
示例13: updateIssueReviewLabels
func updateIssueReviewLabels(client *github.Client, log log15.Logger, review ReviewRequest) error {
oldLabels := []string{}
newLabels := []string{review.CalculateAppropriateStatus()}
foundReviewLabel, incorrectReviewLabel := false, false
for _, l := range review.issue.Labels {
oldLabels = append(oldLabels, *l.Name)
switch *l.Name {
case WIPLabel, CakedLabel, AwaitingCakeLabel:
foundReviewLabel = true
if *l.Name != newLabels[0] {
incorrectReviewLabel = true
}
continue
default:
newLabels = append(newLabels, *l.Name)
}
}
var labelsNeedUpdating bool
switch {
case !foundReviewLabel:
labelsNeedUpdating = true
log.Info("could not find review label", "old_labels", oldLabels, "new_labels", newLabels)
case incorrectReviewLabel:
labelsNeedUpdating = true
log.Info("review label is incorrect", "old_labels", oldLabels, "new_labels", newLabels)
default:
log.Info("review label does not need updating", "labels", oldLabels)
}
if labelsNeedUpdating {
_, _, err := client.Issues.ReplaceLabelsForIssue(*review.repo.Owner.Login, *review.repo.Name, review.Number(), newLabels)
if err != nil {
log.Error("unable to update issue review label", "err", err)
return err
}
}
return nil
}
示例14: newPool
func newPool(conf ini.File, logger log.Logger) (*pgx.ConnPool, error) {
logger = logger.New("module", "pgx")
if level, ok := conf.Get("log", "pgx_level"); ok {
setFilterHandler(level, logger, log.StdoutHandler)
}
connConfig := pgx.ConnConfig{Logger: logger}
connConfig.Host, _ = conf.Get("database", "host")
if connConfig.Host == "" {
return nil, errors.New("Config must contain database.host but it does not")
}
if p, ok := conf.Get("database", "port"); ok {
n, err := strconv.ParseUint(p, 10, 16)
connConfig.Port = uint16(n)
if err != nil {
return nil, err
}
}
var ok bool
if connConfig.Database, ok = conf.Get("database", "database"); !ok {
return nil, errors.New("Config must contain database.database but it does not")
}
connConfig.User, _ = conf.Get("database", "user")
connConfig.Password, _ = conf.Get("database", "password")
poolConfig := pgx.ConnPoolConfig{
ConnConfig: connConfig,
MaxConnections: 10,
}
return pgx.NewConnPool(poolConfig)
}
示例15: ParentLogger
func (fsm *LogFSM) ParentLogger(parent log15.Logger) {
fsm.logger = parent.New("module", "fsm")
}