本文整理匯總了Golang中github.com/inconshreveable/log15.Logger.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Error方法的具體用法?Golang Logger.Error怎麽用?Golang Logger.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/inconshreveable/log15.Logger
的用法示例。
在下文中一共展示了Logger.Error方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mineBlock
func mineBlock(status MiningStatus, srv *context.T, log log15.Logger, previousBlockHash types.Hash, transactions []*transaction.Envelope) {
if bat := prepareBAT(srv, log); bat != nil {
blk, err := block.NewBlock(previousBlockHash, targetBits(), append(transactions, bat))
if err != nil {
log.Error("error while creating a new block", "err", err)
} else {
// send off the new pool
for i := range status.Miners {
status.Miners[i].signallingChannel <- blk
status.Miners[i].Block = blk
status.Miners[i].StartTime = time.Now()
}
}
}
}
示例2: processPendingAllocations
func processPendingAllocations(srv *context.T, log log15.Logger) {
pending := srv.DB.ListPendingRepositories()
for i := range pending {
r, err := srv.DB.GetRepository(pending[i])
if err != nil {
log.Error("error while processing pending repository", "repo", pending[i], "err", err)
}
c, err := srv.DB.GetTransactionConfirmations(r.NameAllocationTx)
if err != nil {
log.Error("error while calculating pending repository's allocation confirmations",
"repo", pending[i], "txn", r.NameAllocationTx, "err", err)
}
if c >= ALLOCATION_CONFIRMATIONS_REQUIRED {
r.Status = repository.ACTIVE
srv.DB.PutRepository(r)
log.Info("activated repository", "repo", pending[i], "alloc_txn", r.NameAllocationTx)
}
}
}
示例3: InfoHandler
func InfoHandler(srv *context.T, log log15.Logger) func(http.ResponseWriter, *http.Request) {
return func(resp http.ResponseWriter, req *http.Request) {
log := log.New("http")
lastBlock, err := srv.DB.GetLastBlock()
if err != nil {
log.Error("error serving /info", "err", err)
}
info := Info{
Mining: server.GetMiningStatus(),
LastBlock: lastBlock,
}
info.Debug.NumGoroutine = runtime.NumGoroutine()
json, err := json.Marshal(info)
if err != nil {
log.Error("error serving /info", "err", err)
}
resp.Header().Add("Content-Type", "application/json")
resp.Write(json)
}
}
示例4: WebsocketHandler
func WebsocketHandler(srv *context.T, log log15.Logger) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
log := log.New("cmp", "websocket")
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Error("error upgrading websocket connetion", "err", err)
return
}
ch := srv.Router.Sub("/block")
defer srv.Router.Unsub(ch)
loop:
select {
case blki := <-ch:
if blk, ok := blki.(*block.Block); ok {
encoded, err := json.Marshal(blk)
if err != nil {
log.Error("error encoding block", "err", err)
return
}
if err = conn.WriteMessage(websocket.TextMessage, encoded); err != nil {
log.Error("error sending data", "err", err)
return
}
}
}
goto loop
}
}
示例5: listenAndServer
func listenAndServer(log log15.Logger, addr string, handler http.Handler) error {
conf, err := config.GetConfig()
if err != nil {
return err
}
conf.Endless.DefaultHammerTime = strings.TrimSpace(conf.Endless.DefaultHammerTime)
if conf.Endless.DefaultHammerTime != "" {
duration, err := time.ParseDuration(conf.Endless.DefaultHammerTime)
if err == nil {
endless.DefaultHammerTime = duration
} else {
log.Error("Bad format", log15.Ctx{"module": "Endless", "DefaultHammerTime": conf.Endless.DefaultHammerTime, "error": err})
}
}
var terminated int32
srv := endless.NewServer(addr, handler)
preHookFunc := func() {
atomic.StoreInt32(&terminated, 1)
}
srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGHUP, preHookFunc)
srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGINT, preHookFunc)
srv.RegisterSignalHook(endless.PRE_SIGNAL, syscall.SIGTERM, preHookFunc)
log.Info("Launching server")
err = srv.ListenAndServe()
if atomic.LoadInt32(&terminated) == 0 {
if err != nil {
log.Error("During startup, error has occurred", "error", err)
}
return err
} else {
log.Info("Server is going to shutdown")
return nil
}
}
示例6: prepareBAT
func prepareBAT(srv *context.T, log log15.Logger) *transaction.Envelope {
key, err := srv.DB.GetMainKey()
if err != nil {
log.Error("error while attempting to retrieve main key", "err", err)
}
if key != nil {
bat, err := transaction.NewBlockAttribution()
if err != nil {
log.Error("error while creating a BAT", "err", err)
} else {
hash, err := srv.DB.GetPreviousEnvelopeHashForPublicKey(&key.PublicKey)
if err != nil {
log.Error("error while creating a BAT", "err", err)
}
bate := transaction.NewEnvelope(hash, bat)
bate.Sign(key)
return bate
}
}
return nil
}
示例7: SetupGitRoutes
func SetupGitRoutes(r *mux.Router, srv *context.T, log log15.Logger) {
log = log.New("cmp", "git")
// Git Server
r.Methods("POST").Path("/{repository:.+}/git-upload-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
log := log.New("cmp", "git-upload-pack")
dec := pktline.NewDecoder(req.Body)
resp.Header().Add("Cache-Control", "no-cache")
resp.Header().Add("Content-Type", "application/x-git-upload-pack-result")
enc := pktline.NewEncoder(resp)
var wants, haves, common []git.Hash
var objects []git.Object
wantsRcvd := false
for {
var pktline []byte
if err := dec.Decode(&pktline); err != nil {
log.Error("error while decoding pkt-line", "err", err)
return
}
switch {
case pktline == nil:
switch {
case !wantsRcvd:
wantsRcvd = true
case wantsRcvd:
for i := range haves {
_, err := readObject(srv, haves[i])
if err == nil {
enc.Encode([]byte(fmt.Sprintf("ACK %x common\n", haves[i])))
common = append(common, haves[i])
} else {
enc.Encode([]byte("NAK\n"))
}
}
haves = make([]git.Hash, 0)
}
case bytes.Compare(pktline, []byte("done\n")) == 0:
if len(common) == 0 {
enc.Encode([]byte("NAK\n"))
}
goto done
default:
line := bytes.Split(pktline, []byte{' '})
h := bytes.TrimSuffix(line[1], []byte{10})
hash, err := hex.DecodeString(string(h))
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("error parsing hash %s: %v\n", line[1], err))...))
return
}
if string(line[0]) == "want" {
wants = append(wants, hash)
}
if string(line[0]) == "have" {
haves = append(haves, hash)
}
}
}
done:
var err error
for i := range wants {
var objs []git.Object
objs, err = processCommit(srv, wants[i], common)
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("%s", err))...))
return
}
objects = append(objects, objs...)
}
// filter out duplicates
seen := make(map[string]bool)
filteredObjects := make([]git.Object, 0)
for i := range objects {
hash := string(objects[i].Hash())
if !seen[hash] {
seen[hash] = true
filteredObjects = append(filteredObjects, objects[i])
}
}
//
packfile := git.NewPackfile(filteredObjects)
err = git.WritePackfile(&sideband64Writer{writer: &pktlineWriter{encoder: enc}, band: 1}, packfile)
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("%s", err))...))
return
}
enc.Encode(append([]byte{1}, pktlineToBytes(nil)...))
enc.Encode(nil)
})
r.Methods("POST").Path("/{repository:.+}/git-receive-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
reponame := mux.Vars(req)["repository"]
var lines [][]byte
dec := pktline.NewDecoder(req.Body)
dec.DecodeUntilFlush(&lines)
resp.Header().Add("Cache-Control", "no-cache")
resp.Header().Add("Content-Type", "application/x-git-receive-pack-result")
//.........這裏部分代碼省略.........
示例8: listenAndServer
func listenAndServer(log log15.Logger, addr string, handler http.Handler) error {
log.Info("Launching server")
err := http.ListenAndServe(addr, handler)
log.Error("During startup, error has occurred", "error", err)
return err
}