mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
prune util/log and user logger (#1237)
* prune util/log and user logger Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * plaintext logger Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * add newline Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
ceed8942fc
commit
117f56ebf7
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/micro/go-micro/v2/agent/input"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type discordConn struct {
|
||||
@ -74,7 +74,7 @@ func (dc *discordConn) Send(e *input.Event) error {
|
||||
fields := strings.Split(e.To, ":")
|
||||
_, err := dc.master.session.ChannelMessageSend(fields[0], string(e.Data))
|
||||
if err != nil {
|
||||
log.Log("[bot][loop][send]", err)
|
||||
log.Error("[bot][loop][send]", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/forestgiant/sliceutil"
|
||||
"github.com/micro/go-micro/v2/agent/input"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
tgbotapi "gopkg.in/telegram-bot-api.v4"
|
||||
)
|
||||
|
||||
@ -104,7 +104,7 @@ func (tc *telegramConn) Send(event *input.Event) error {
|
||||
|
||||
if err != nil {
|
||||
// probably it could be because of nested HTML tags -- telegram doesn't allow nested tags
|
||||
log.Log("[telegram][Send] error:", err)
|
||||
log.Error("[telegram][Send] error:", err)
|
||||
msgConfig.Text = "This bot couldn't send the response (Internal error)"
|
||||
tc.input.api.Send(msgConfig)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/micro/go-micro/v2/api/handler"
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -136,7 +136,7 @@ func (c *conn) writeLoop() {
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
log.Log(err.Error())
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ func (b *brokerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ws, err := b.u.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
log.Log(err.Error())
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package certmagic
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -21,6 +22,9 @@ func TestCertMagic(t *testing.T) {
|
||||
}
|
||||
l, err := NewProvider().Listen()
|
||||
if err != nil {
|
||||
if _, ok := err.(*net.OpError); ok {
|
||||
t.Skip("Run under non privileged user")
|
||||
}
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
l.Close()
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/micro/go-micro/v2/api/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type httpServer struct {
|
||||
@ -65,7 +65,7 @@ func (s *httpServer) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Logf("HTTP API Listening on %s", l.Addr().String())
|
||||
log.Infof("HTTP API Listening on %s", l.Addr().String())
|
||||
|
||||
s.mtx.Lock()
|
||||
s.address = l.Addr().String()
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/codec/json"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
nats "github.com/nats-io/nats.go"
|
||||
)
|
||||
@ -167,7 +167,7 @@ func (n *natsBroker) serve(exit chan bool) error {
|
||||
for _, node := range service.Nodes {
|
||||
u, err := url.Parse("nats://" + node.Address)
|
||||
if err != nil {
|
||||
log.Log(err)
|
||||
log.Info(err)
|
||||
continue
|
||||
}
|
||||
// append to the cluster routes
|
||||
@ -242,7 +242,7 @@ func (n *natsBroker) serve(exit chan bool) error {
|
||||
select {
|
||||
case err := <-n.closeCh:
|
||||
if err != nil {
|
||||
log.Log(err)
|
||||
log.Info(err)
|
||||
}
|
||||
case <-exit:
|
||||
// deregister on exit
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/codec/json"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"github.com/nats-io/nats-server/v2/server"
|
||||
nats "github.com/nats-io/nats.go"
|
||||
)
|
||||
@ -164,7 +164,7 @@ func (n *natsBroker) serve(exit chan bool) error {
|
||||
for _, node := range service.Nodes {
|
||||
u, err := url.Parse("nats://" + node.Address)
|
||||
if err != nil {
|
||||
log.Log(err)
|
||||
log.Error(err)
|
||||
continue
|
||||
}
|
||||
// append to the cluster routes
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
pb "github.com/micro/go-micro/v2/broker/service/proto"
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type serviceBroker struct {
|
||||
|
@ -3,7 +3,7 @@ package service
|
||||
import (
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
pb "github.com/micro/go-micro/v2/broker/service/proto"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type serviceSub struct {
|
||||
|
@ -12,12 +12,12 @@ import (
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/client/selector"
|
||||
"github.com/micro/go-micro/v2/debug/trace"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/store"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
|
||||
// clients
|
||||
cgrpc "github.com/micro/go-micro/v2/client/grpc"
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/config/source"
|
||||
proto "github.com/micro/go-micro/v2/config/source/service/proto"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
|
123
debug/log/os.go
123
debug/log/os.go
@ -1,13 +1,7 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/v2/util/ring"
|
||||
@ -25,106 +19,10 @@ type osLog struct {
|
||||
|
||||
type osStream struct {
|
||||
stream chan Record
|
||||
stop chan bool
|
||||
}
|
||||
|
||||
// watch io stream
|
||||
func (o *osLog) run() {
|
||||
// save outputs
|
||||
stdout := *os.Stdout
|
||||
stderr := *os.Stderr
|
||||
|
||||
// new os pipe
|
||||
r, w := io.Pipe()
|
||||
|
||||
// create new iopipes
|
||||
r1, w1, _ := os.Pipe()
|
||||
r2, w2, _ := os.Pipe()
|
||||
|
||||
// create tea readers
|
||||
tee1 := io.TeeReader(r1, &stdout)
|
||||
tee2 := io.TeeReader(r2, &stderr)
|
||||
|
||||
// start copying
|
||||
go io.Copy(w, tee1)
|
||||
go io.Copy(w, tee2)
|
||||
|
||||
// set default go log output
|
||||
//log.SetOutput(w2)
|
||||
|
||||
// replace os stdout and os stderr
|
||||
*os.Stdout = *w1
|
||||
*os.Stderr = *w2
|
||||
|
||||
// this should short circuit everything
|
||||
defer func() {
|
||||
// reset stdout and stderr
|
||||
*os.Stdout = stdout
|
||||
*os.Stderr = stderr
|
||||
//log.SetOutput(stderr)
|
||||
|
||||
// close all the outputs
|
||||
r.Close()
|
||||
r1.Close()
|
||||
r2.Close()
|
||||
w.Close()
|
||||
w1.Close()
|
||||
w2.Close()
|
||||
}()
|
||||
|
||||
// read from standard error
|
||||
scanner := bufio.NewReader(r)
|
||||
|
||||
for {
|
||||
// read the line
|
||||
line, err := scanner.ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// check if the line exists
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
// parse the record
|
||||
var r Record
|
||||
if line[0] == '{' {
|
||||
json.Unmarshal([]byte(line), &r)
|
||||
} else {
|
||||
r = Record{
|
||||
Timestamp: time.Now(),
|
||||
Message: strings.TrimSuffix(line, "\n"),
|
||||
Metadata: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
o.Lock()
|
||||
|
||||
// write to the buffer
|
||||
o.buffer.Put(r)
|
||||
|
||||
// check subs and send to stream
|
||||
for id, sub := range o.subs {
|
||||
// send to stream
|
||||
select {
|
||||
case <-sub.stop:
|
||||
delete(o.subs, id)
|
||||
case sub.stream <- r:
|
||||
// send to stream
|
||||
default:
|
||||
// do not block
|
||||
}
|
||||
}
|
||||
|
||||
o.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// Read reads log entries from the logger
|
||||
func (o *osLog) Read(...ReadOption) ([]Record, error) {
|
||||
o.once.Do(func() {
|
||||
go o.run()
|
||||
})
|
||||
|
||||
var records []Record
|
||||
|
||||
// read the last 100 records
|
||||
@ -137,29 +35,18 @@ func (o *osLog) Read(...ReadOption) ([]Record, error) {
|
||||
|
||||
// Write writes records to log
|
||||
func (o *osLog) Write(r Record) error {
|
||||
o.once.Do(func() {
|
||||
go o.run()
|
||||
})
|
||||
|
||||
// generate output
|
||||
out := o.format(r) + "\n"
|
||||
_, err := os.Stderr.Write([]byte(out))
|
||||
return err
|
||||
o.buffer.Put(r)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stream log records
|
||||
func (o *osLog) Stream() (Stream, error) {
|
||||
o.once.Do(func() {
|
||||
go o.run()
|
||||
})
|
||||
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
|
||||
// create stream
|
||||
st := &osStream{
|
||||
stream: make(chan Record, 128),
|
||||
stop: make(chan bool),
|
||||
}
|
||||
|
||||
// save stream
|
||||
@ -173,12 +60,6 @@ func (o *osStream) Chan() <-chan Record {
|
||||
}
|
||||
|
||||
func (o *osStream) Stop() error {
|
||||
select {
|
||||
case <-o.stop:
|
||||
return nil
|
||||
default:
|
||||
close(o.stop)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,11 @@ package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
dlog "github.com/micro/go-micro/v2/debug/log"
|
||||
)
|
||||
|
||||
type defaultLogger struct {
|
||||
@ -36,44 +37,57 @@ func (l *defaultLogger) Error(err error) Logger {
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||
// TODO decide does we need to write message if log level not used?
|
||||
if !l.opts.Level.Enabled(level) {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprint(v...)
|
||||
|
||||
fields := l.opts.Fields
|
||||
fields["level"] = level.String()
|
||||
fields["message"] = msg
|
||||
if l.err != nil {
|
||||
fields["error"] = l.err.Error()
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(l.opts.Out)
|
||||
|
||||
if err := enc.Encode(fields); err != nil {
|
||||
log.Fatal(err)
|
||||
rec := dlog.Record{
|
||||
Timestamp: time.Now(),
|
||||
Message: fmt.Sprint(v...),
|
||||
Metadata: make(map[string]string),
|
||||
}
|
||||
for k, v := range fields {
|
||||
rec.Metadata[k] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
|
||||
dlog.DefaultLog.Write(rec)
|
||||
|
||||
t := rec.Timestamp.Format("2006-01-02 15:04:05")
|
||||
fmt.Printf("%s %v\n", t, rec.Message)
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
|
||||
// TODO decide does we need to write message if log level not used?
|
||||
if level < l.opts.Level {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf(format, v...)
|
||||
|
||||
fields := l.opts.Fields
|
||||
fields["level"] = level.String()
|
||||
fields["message"] = msg
|
||||
if l.err != nil {
|
||||
fields["error"] = l.err.Error()
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(l.opts.Out)
|
||||
|
||||
if err := enc.Encode(fields); err != nil {
|
||||
log.Fatal(err)
|
||||
rec := dlog.Record{
|
||||
Timestamp: time.Now(),
|
||||
Message: fmt.Sprintf(format, v...),
|
||||
Metadata: make(map[string]string),
|
||||
}
|
||||
for k, v := range fields {
|
||||
rec.Metadata[k] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
|
||||
dlog.DefaultLog.Write(rec)
|
||||
|
||||
t := rec.Timestamp.Format("2006-01-02 15:04:05")
|
||||
fmt.Printf("%s %v\n", t, rec.Message)
|
||||
}
|
||||
|
||||
func (n *defaultLogger) Options() Options {
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
cmucp "github.com/micro/go-micro/v2/client/mucp"
|
||||
rtr "github.com/micro/go-micro/v2/client/selector/router"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/network/resolver/dns"
|
||||
pbNet "github.com/micro/go-micro/v2/network/service/proto"
|
||||
"github.com/micro/go-micro/v2/proxy"
|
||||
@ -27,7 +28,6 @@ import (
|
||||
bun "github.com/micro/go-micro/v2/tunnel/broker"
|
||||
tun "github.com/micro/go-micro/v2/tunnel/transport"
|
||||
"github.com/micro/go-micro/v2/util/backoff"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
pbUtil "github.com/micro/go-micro/v2/util/proto"
|
||||
)
|
||||
|
||||
|
@ -15,11 +15,11 @@ import (
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
"github.com/micro/go-micro/v2/codec/bytes"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/proxy"
|
||||
"github.com/micro/go-micro/v2/router"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
// Proxy will transparently proxy requests to an endpoint.
|
||||
|
6
registry/cache/cache.go
vendored
6
registry/cache/cache.go
vendored
@ -7,8 +7,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
log "github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
// Cache is the registry cache interface
|
||||
@ -339,7 +339,7 @@ func (c *cache) run() {
|
||||
c.setStatus(err)
|
||||
|
||||
if a > 3 {
|
||||
log.Log("rcache: ", err, " backing off ", d)
|
||||
log.Info("rcache: ", err, " backing off ", d)
|
||||
a = 0
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ func (c *cache) run() {
|
||||
c.setStatus(err)
|
||||
|
||||
if b > 3 {
|
||||
log.Log("rcache: ", err, " backing off ", d)
|
||||
log.Info("rcache: ", err, " backing off ", d)
|
||||
b = 0
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/clientv3"
|
||||
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
hash "github.com/mitchellh/hashstructure"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/kubernetes/client"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type k8sWatcher struct {
|
||||
@ -132,7 +132,7 @@ func (k *k8sWatcher) buildPodResults(pod *client.Pod, cache *client.Pod) []*regi
|
||||
func (k *k8sWatcher) handleEvent(event client.Event) {
|
||||
var pod client.Pod
|
||||
if err := json.Unmarshal([]byte(event.Object), &pod); err != nil {
|
||||
log.Log("K8s Watcher: Couldnt unmarshal event object from pod")
|
||||
log.Info("K8s Watcher: Couldnt unmarshal event object from pod")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -357,14 +357,14 @@ func (r *router) advertiseEvents() error {
|
||||
// routing table watcher
|
||||
w, err = r.Watch()
|
||||
if err != nil {
|
||||
log.Logf("Error creating watcher: %v", err)
|
||||
log.Errorf("Error creating watcher: %v", err)
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := r.watchTable(w); err != nil {
|
||||
log.Logf("Error watching table: %v", err)
|
||||
log.Errorf("Error watching table: %v", err)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
@ -538,14 +538,14 @@ func (r *router) Start() error {
|
||||
if w == nil {
|
||||
w, err = r.options.Registry.Watch()
|
||||
if err != nil {
|
||||
log.Logf("failed creating registry watcher: %v", err)
|
||||
log.Errorf("failed creating registry watcher: %v", err)
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := r.watchRegistry(w); err != nil {
|
||||
log.Logf("Error watching the registry: %v", err)
|
||||
log.Errorf("Error watching the registry: %v", err)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
@ -602,7 +602,7 @@ func (r *router) Advertise() (<-chan *Advert, error) {
|
||||
return
|
||||
default:
|
||||
if err := r.advertiseEvents(); err != nil {
|
||||
log.Logf("Error adveritising events: %v", err)
|
||||
log.Errorf("Error adveritising events: %v", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry/memory"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
func routerTestSetup() Router {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type runtime struct {
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/micro/go-micro/v2/util/kubernetes/client"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
// action to take on runtime service
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/micro/go-micro/v2/util/kubernetes/api"
|
||||
"github.com/micro/go-micro/v2/util/kubernetes/client"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/runtime/local/build"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type Builder struct {
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/runtime/local/build"
|
||||
"github.com/micro/go-micro/v2/runtime/local/process"
|
||||
proc "github.com/micro/go-micro/v2/runtime/local/process/os"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
|
@ -17,12 +17,12 @@ import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
meta "github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
mgrpc "github.com/micro/go-micro/v2/util/grpc"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
mnet "github.com/micro/go-micro/v2/util/net"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
@ -356,8 +356,8 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service,
|
||||
fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Logf(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
@ -656,7 +656,7 @@ func (g *grpcServer) Register() error {
|
||||
g.Unlock()
|
||||
|
||||
if !registered {
|
||||
log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
||||
log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
||||
}
|
||||
|
||||
// create registry options
|
||||
@ -691,7 +691,7 @@ func (g *grpcServer) Register() error {
|
||||
opts = append(opts, broker.DisableAutoAck())
|
||||
}
|
||||
|
||||
log.Logf("Subscribing to topic: %s", sb.Topic())
|
||||
log.Infof("Subscribing to topic: %s", sb.Topic())
|
||||
sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -743,7 +743,7 @@ func (g *grpcServer) Deregister() error {
|
||||
Nodes: []*registry.Node{node},
|
||||
}
|
||||
|
||||
log.Logf("Deregistering node: %s", node.Id)
|
||||
log.Infof("Deregistering node: %s", node.Id)
|
||||
if err := config.Registry.Deregister(service); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -759,7 +759,7 @@ func (g *grpcServer) Deregister() error {
|
||||
|
||||
for sb, subs := range g.subscribers {
|
||||
for _, sub := range subs {
|
||||
log.Logf("Unsubscribing from topic: %s", sub.Topic())
|
||||
log.Infof("Unsubscribing from topic: %s", sub.Topic())
|
||||
sub.Unsubscribe()
|
||||
}
|
||||
g.subscribers[sb] = nil
|
||||
@ -799,7 +799,7 @@ func (g *grpcServer) Start() error {
|
||||
}
|
||||
}
|
||||
|
||||
log.Logf("Server [grpc] Listening on %s", ts.Addr().String())
|
||||
log.Infof("Server [grpc] Listening on %s", ts.Addr().String())
|
||||
g.Lock()
|
||||
g.opts.Address = ts.Addr().String()
|
||||
g.Unlock()
|
||||
@ -811,18 +811,18 @@ func (g *grpcServer) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Logf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address())
|
||||
log.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address())
|
||||
}
|
||||
|
||||
// announce self to the world
|
||||
if err := g.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
log.Errorf("Server register error: ", err)
|
||||
}
|
||||
|
||||
// micro: go ts.Accept(s.accept)
|
||||
go func() {
|
||||
if err := g.srv.Serve(ts); err != nil {
|
||||
log.Log("gRPC Server start error: ", err)
|
||||
log.Errorf("gRPC Server start error: ", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -844,7 +844,7 @@ func (g *grpcServer) Start() error {
|
||||
// register self on interval
|
||||
case <-t.C:
|
||||
if err := g.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
log.Error("Server register error: ", err)
|
||||
}
|
||||
// wait for exit
|
||||
case ch = <-g.exit:
|
||||
@ -854,7 +854,7 @@ func (g *grpcServer) Start() error {
|
||||
|
||||
// deregister self
|
||||
if err := g.Deregister(); err != nil {
|
||||
log.Log("Server deregister error: ", err)
|
||||
log.Error("Server deregister error: ", err)
|
||||
}
|
||||
|
||||
// wait for waitgroup
|
||||
@ -879,7 +879,7 @@ func (g *grpcServer) Start() error {
|
||||
// close transport
|
||||
ch <- nil
|
||||
|
||||
log.Logf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address())
|
||||
log.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address())
|
||||
// disconnect broker
|
||||
config.Broker.Disconnect()
|
||||
}()
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -86,7 +86,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
replyType = mtype.In(3)
|
||||
contextType = mtype.In(1)
|
||||
default:
|
||||
log.Log("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
||||
log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
// check stream type
|
||||
streamType := reflect.TypeOf((*server.Stream)(nil)).Elem()
|
||||
if !argType.Implements(streamType) {
|
||||
log.Log(mname, "argument does not implement Streamer interface:", argType)
|
||||
log.Error(mname, "argument does not implement Streamer interface:", argType)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
@ -102,30 +102,30 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
|
||||
// First arg need not be a pointer.
|
||||
if !isExportedOrBuiltinType(argType) {
|
||||
log.Log(mname, "argument type not exported:", argType)
|
||||
log.Error(mname, "argument type not exported:", argType)
|
||||
return nil
|
||||
}
|
||||
|
||||
if replyType.Kind() != reflect.Ptr {
|
||||
log.Log("method", mname, "reply type not a pointer:", replyType)
|
||||
log.Error("method", mname, "reply type not a pointer:", replyType)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reply type must be exported.
|
||||
if !isExportedOrBuiltinType(replyType) {
|
||||
log.Log("method", mname, "reply type not exported:", replyType)
|
||||
log.Error("method", mname, "reply type not exported:", replyType)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Endpoint() needs one out.
|
||||
if mtype.NumOut() != 1 {
|
||||
log.Log("method", mname, "has wrong number of outs:", mtype.NumOut())
|
||||
log.Error("method", mname, "has wrong number of outs:", mtype.NumOut())
|
||||
return nil
|
||||
}
|
||||
// The return type of the method must be error.
|
||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||
log.Log("method", mname, "returns", returnType.String(), "not error")
|
||||
log.Error("method", mname, "returns", returnType.String(), "not error")
|
||||
return nil
|
||||
}
|
||||
return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream}
|
||||
@ -146,7 +146,7 @@ func (server *rServer) register(rcvr interface{}) error {
|
||||
}
|
||||
if !isExported(sname) {
|
||||
s := "rpc Register: type " + sname + " is not exported"
|
||||
log.Log(s)
|
||||
log.Error(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
if _, present := server.serviceMap[sname]; present {
|
||||
@ -165,7 +165,7 @@ func (server *rServer) register(rcvr interface{}) error {
|
||||
|
||||
if len(s.method) == 0 {
|
||||
s := "rpc Register: type " + sname + " has no exported methods of suitable type"
|
||||
log.Log(s)
|
||||
log.Error(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
server.serviceMap[s.name] = s
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -171,8 +171,8 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Logf(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
merrors "github.com/micro/go-micro/v2/errors"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -141,7 +141,7 @@ func prepareMethod(method reflect.Method) *methodType {
|
||||
replyType = mtype.In(3)
|
||||
contextType = mtype.In(1)
|
||||
default:
|
||||
log.Log("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
||||
log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ func prepareMethod(method reflect.Method) *methodType {
|
||||
// check stream type
|
||||
streamType := reflect.TypeOf((*Stream)(nil)).Elem()
|
||||
if !argType.Implements(streamType) {
|
||||
log.Log(mname, "argument does not implement Stream interface:", argType)
|
||||
log.Error(mname, "argument does not implement Stream interface:", argType)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
@ -157,30 +157,30 @@ func prepareMethod(method reflect.Method) *methodType {
|
||||
|
||||
// First arg need not be a pointer.
|
||||
if !isExportedOrBuiltinType(argType) {
|
||||
log.Log(mname, "argument type not exported:", argType)
|
||||
log.Error(mname, "argument type not exported:", argType)
|
||||
return nil
|
||||
}
|
||||
|
||||
if replyType.Kind() != reflect.Ptr {
|
||||
log.Log("method", mname, "reply type not a pointer:", replyType)
|
||||
log.Error("method", mname, "reply type not a pointer:", replyType)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reply type must be exported.
|
||||
if !isExportedOrBuiltinType(replyType) {
|
||||
log.Log("method", mname, "reply type not exported:", replyType)
|
||||
log.Error("method", mname, "reply type not exported:", replyType)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Method needs one out.
|
||||
if mtype.NumOut() != 1 {
|
||||
log.Log("method", mname, "has wrong number of outs:", mtype.NumOut())
|
||||
log.Error("method", mname, "has wrong number of outs:", mtype.NumOut())
|
||||
return nil
|
||||
}
|
||||
// The return type of the method must be error.
|
||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||
log.Log("method", mname, "returns", returnType.String(), "not error")
|
||||
log.Error("method", mname, "returns", returnType.String(), "not error")
|
||||
return nil
|
||||
}
|
||||
return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream}
|
||||
@ -509,8 +509,8 @@ func (router *router) ProcessMessage(ctx context.Context, msg Message) (err erro
|
||||
defer func() {
|
||||
// recover any panics
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Log(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
err = merrors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
|
@ -15,11 +15,11 @@ import (
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
raw "github.com/micro/go-micro/v2/codec/bytes"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
log "github.com/micro/go-micro/v2/util/log"
|
||||
mnet "github.com/micro/go-micro/v2/util/net"
|
||||
"github.com/micro/go-micro/v2/util/socket"
|
||||
)
|
||||
@ -158,8 +158,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) {
|
||||
|
||||
// recover any panics
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Log(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
@ -377,8 +377,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) {
|
||||
|
||||
// recover any panics for outbound process
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Log(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
@ -409,8 +409,8 @@ func (s *rpcServer) ServeConn(sock transport.Socket) {
|
||||
|
||||
// recover any panics for call handler
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Log(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
|
||||
@ -608,7 +608,7 @@ func (s *rpcServer) Register() error {
|
||||
s.RUnlock()
|
||||
|
||||
if !registered {
|
||||
log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
||||
log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
||||
}
|
||||
|
||||
// create registry options
|
||||
@ -654,7 +654,7 @@ func (s *rpcServer) Register() error {
|
||||
opts = append(opts, broker.DisableAutoAck())
|
||||
}
|
||||
|
||||
log.Logf("Subscribing to topic: %s", sub.Topic())
|
||||
log.Infof("Subscribing to topic: %s", sub.Topic())
|
||||
sub, err := config.Broker.Subscribe(sb.Topic(), s.HandleEvent, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -712,7 +712,7 @@ func (s *rpcServer) Deregister() error {
|
||||
Nodes: []*registry.Node{node},
|
||||
}
|
||||
|
||||
log.Logf("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id)
|
||||
log.Infof("Registry [%s] Deregistering node: %s", config.Registry.String(), node.Id)
|
||||
if err := config.Registry.Deregister(service); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -734,7 +734,7 @@ func (s *rpcServer) Deregister() error {
|
||||
|
||||
for sb, subs := range s.subscribers {
|
||||
for _, sub := range subs {
|
||||
log.Logf("Unsubscribing %s from topic: %s", node.Id, sub.Topic())
|
||||
log.Infof("Unsubscribing %s from topic: %s", node.Id, sub.Topic())
|
||||
sub.Unsubscribe()
|
||||
}
|
||||
s.subscribers[sb] = nil
|
||||
@ -760,7 +760,7 @@ func (s *rpcServer) Start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Logf("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr())
|
||||
log.Infof("Transport [%s] Listening on %s", config.Transport.String(), ts.Addr())
|
||||
|
||||
// swap address
|
||||
s.Lock()
|
||||
@ -775,15 +775,15 @@ func (s *rpcServer) Start() error {
|
||||
|
||||
bname := config.Broker.String()
|
||||
|
||||
log.Logf("Broker [%s] Connected to %s", bname, config.Broker.Address())
|
||||
log.Infof("Broker [%s] Connected to %s", bname, config.Broker.Address())
|
||||
|
||||
// use RegisterCheck func before register
|
||||
if err = s.opts.RegisterCheck(s.opts.Context); err != nil {
|
||||
log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err)
|
||||
} else {
|
||||
// announce self to the world
|
||||
if err = s.Register(); err != nil {
|
||||
log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,7 +804,7 @@ func (s *rpcServer) Start() error {
|
||||
// check the error and backoff
|
||||
default:
|
||||
if err != nil {
|
||||
log.Logf("Accept error: %v", err)
|
||||
log.Errorf("Accept error: %v", err)
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
@ -837,17 +837,17 @@ func (s *rpcServer) Start() error {
|
||||
s.RUnlock()
|
||||
rerr := s.opts.RegisterCheck(s.opts.Context)
|
||||
if rerr != nil && registered {
|
||||
log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err)
|
||||
// deregister self in case of error
|
||||
if err := s.Deregister(); err != nil {
|
||||
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
} else if rerr != nil && !registered {
|
||||
log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s register check error: %s", config.Name, config.Id, err)
|
||||
continue
|
||||
}
|
||||
if err := s.Register(); err != nil {
|
||||
log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s register error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
// wait for exit
|
||||
case ch = <-s.exit:
|
||||
@ -863,7 +863,7 @@ func (s *rpcServer) Start() error {
|
||||
if registered {
|
||||
// deregister self
|
||||
if err := s.Deregister(); err != nil {
|
||||
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
log.Errorf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -879,7 +879,7 @@ func (s *rpcServer) Start() error {
|
||||
// close transport listener
|
||||
ch <- ts.Close()
|
||||
|
||||
log.Logf("Broker [%s] Disconnected from %s", bname, config.Broker.Address())
|
||||
log.Infof("Broker [%s] Disconnected from %s", bname, config.Broker.Address())
|
||||
// disconnect the broker
|
||||
config.Broker.Disconnect()
|
||||
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/v2/codec"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
log "github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
// Server is a simple micro server abstraction
|
||||
@ -200,7 +200,7 @@ func Run() error {
|
||||
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT)
|
||||
log.Logf("Received signal %s", <-ch)
|
||||
log.Infof("Received signal %s", <-ch)
|
||||
|
||||
return Stop()
|
||||
}
|
||||
@ -208,13 +208,13 @@ func Run() error {
|
||||
// Start starts the default server
|
||||
func Start() error {
|
||||
config := DefaultServer.Options()
|
||||
log.Logf("Starting server %s id %s", config.Name, config.Id)
|
||||
log.Infof("Starting server %s id %s", config.Name, config.Id)
|
||||
return DefaultServer.Start()
|
||||
}
|
||||
|
||||
// Stop stops the default server
|
||||
func Stop() error {
|
||||
log.Logf("Stopping server")
|
||||
log.Infof("Stopping server")
|
||||
return DefaultServer.Stop()
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@ import (
|
||||
"github.com/micro/go-micro/v2/debug/service/handler"
|
||||
"github.com/micro/go-micro/v2/debug/stats"
|
||||
"github.com/micro/go-micro/v2/debug/trace"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/plugin"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"github.com/micro/go-micro/v2/util/wrapper"
|
||||
)
|
||||
|
||||
@ -202,7 +202,7 @@ func (s *service) Run() error {
|
||||
defer profiler.Stop()
|
||||
}
|
||||
|
||||
log.Logf("Starting [service] %s", s.Name())
|
||||
log.Infof("Starting [service] %s", s.Name())
|
||||
|
||||
if err := s.Start(); err != nil {
|
||||
return err
|
||||
|
@ -7,10 +7,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/micro/go-micro/v2/client"
|
||||
"github.com/micro/go-micro/v2/debug/log/noop"
|
||||
proto "github.com/micro/go-micro/v2/debug/service/proto"
|
||||
"github.com/micro/go-micro/v2/registry/memory"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"github.com/micro/go-micro/v2/util/test"
|
||||
)
|
||||
|
||||
@ -24,9 +22,6 @@ func testShutdown(wg *sync.WaitGroup, cancel func()) {
|
||||
}
|
||||
|
||||
func testService(ctx context.Context, wg *sync.WaitGroup, name string) Service {
|
||||
// set no op logger
|
||||
log.SetLogger(noop.NewLog())
|
||||
|
||||
// add self
|
||||
wg.Add(1)
|
||||
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/lib/pq"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/store"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/sync/leader/etcd"
|
||||
"github.com/micro/go-micro/v2/sync/task"
|
||||
"github.com/micro/go-micro/v2/sync/task/local"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type syncCron struct {
|
||||
@ -35,7 +35,7 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error {
|
||||
// leader election
|
||||
e, err := c.opts.Leader.Elect(id)
|
||||
if err != nil {
|
||||
log.Logf("[cron] leader election error: %v", err)
|
||||
log.Errorf("[cron] leader election error: %v", err)
|
||||
time.Sleep(backoff(i))
|
||||
i++
|
||||
continue
|
||||
@ -55,9 +55,9 @@ func (c *syncCron) Schedule(s task.Schedule, t task.Command) error {
|
||||
break Tick
|
||||
}
|
||||
|
||||
log.Logf("[cron] executing command %s", t.Name)
|
||||
log.Infof("[cron] executing command %s", t.Name)
|
||||
if err := c.opts.Task.Run(t); err != nil {
|
||||
log.Logf("[cron] error executing command %s: %v", t.Name, err)
|
||||
log.Errorf("[cron] error executing command %s: %v", t.Name, err)
|
||||
}
|
||||
// leader revoked
|
||||
case <-r:
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
pb "github.com/micro/go-micro/v2/transport/grpc/proto"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
|
||||
@ -30,7 +30,7 @@ func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) {
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Log(r, string(debug.Stack()))
|
||||
log.Error(r, string(debug.Stack()))
|
||||
sock.Close()
|
||||
err = errors.InternalServerError("go.micro.transport", "panic recovered: %v", r)
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -949,7 +949,7 @@ func (t *tun) connect() error {
|
||||
|
||||
// still connected but the tunnel died
|
||||
if err != nil && t.connected {
|
||||
log.Logf("Tunnel listener died: %v", err)
|
||||
log.Errorf("Tunnel listener died: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
type link struct {
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
)
|
||||
|
||||
type tunListener struct {
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/transport"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
// session is our pseudo session for transport.Socket
|
||||
|
@ -12,8 +12,8 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/util/kubernetes/api"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -1,15 +0,0 @@
|
||||
# Log
|
||||
|
||||
This is the global logger for all micro based libraries.
|
||||
|
||||
## Set Logger
|
||||
|
||||
Set the logger for micro libraries
|
||||
|
||||
```go
|
||||
// import go-micro/util/log
|
||||
import "github.com/micro/go-micro/util/log"
|
||||
|
||||
// SetLogger expects github.com/micro/go-micro/debug/log.Log interface
|
||||
log.SetLogger(mylogger)
|
||||
```
|
206
util/log/log.go
206
util/log/log.go
@ -1,206 +0,0 @@
|
||||
// Package log is a global internal logger
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/v2/debug/log"
|
||||
)
|
||||
|
||||
// level is a log level
|
||||
type Level int32
|
||||
|
||||
const (
|
||||
LevelFatal Level = iota
|
||||
LevelError
|
||||
LevelWarn
|
||||
LevelInfo
|
||||
LevelDebug
|
||||
LevelTrace
|
||||
)
|
||||
|
||||
var (
|
||||
// the local logger
|
||||
logger log.Log = log.DefaultLog
|
||||
|
||||
// default log level is info
|
||||
level = LevelInfo
|
||||
|
||||
// prefix for all messages
|
||||
prefix string
|
||||
)
|
||||
|
||||
func init() {
|
||||
switch os.Getenv("MICRO_LOG_LEVEL") {
|
||||
case "trace":
|
||||
level = LevelTrace
|
||||
case "debug":
|
||||
level = LevelDebug
|
||||
case "warn":
|
||||
level = LevelWarn
|
||||
case "info":
|
||||
level = LevelInfo
|
||||
case "error":
|
||||
level = LevelError
|
||||
case "fatal":
|
||||
level = LevelFatal
|
||||
}
|
||||
}
|
||||
|
||||
func (l Level) String() string {
|
||||
switch l {
|
||||
case LevelTrace:
|
||||
return "trace"
|
||||
case LevelDebug:
|
||||
return "debug"
|
||||
case LevelWarn:
|
||||
return "warn"
|
||||
case LevelInfo:
|
||||
return "info"
|
||||
case LevelError:
|
||||
return "error"
|
||||
case LevelFatal:
|
||||
return "fatal"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Log makes use of github.com/micro/debug/log
|
||||
func Log(v ...interface{}) {
|
||||
if len(prefix) > 0 {
|
||||
v = append([]interface{}{prefix, " "}, v...)
|
||||
}
|
||||
logger.Write(log.Record{
|
||||
Timestamp: time.Now(),
|
||||
Message: fmt.Sprint(v...),
|
||||
Metadata: map[string]string{
|
||||
"level": level.String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Logf makes use of github.com/micro/debug/log
|
||||
func Logf(format string, v ...interface{}) {
|
||||
if len(prefix) > 0 {
|
||||
format = prefix + " " + format
|
||||
}
|
||||
logger.Write(log.Record{
|
||||
Timestamp: time.Now(),
|
||||
Message: fmt.Sprintf(format, v...),
|
||||
Metadata: map[string]string{
|
||||
"level": level.String(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// WithLevel logs with the level specified
|
||||
func WithLevel(l Level, v ...interface{}) {
|
||||
if l > level {
|
||||
return
|
||||
}
|
||||
Log(v...)
|
||||
}
|
||||
|
||||
// WithLevel logs with the level specified
|
||||
func WithLevelf(l Level, format string, v ...interface{}) {
|
||||
if l > level {
|
||||
return
|
||||
}
|
||||
Logf(format, v...)
|
||||
}
|
||||
|
||||
// Trace provides trace level logging
|
||||
func Trace(v ...interface{}) {
|
||||
WithLevel(LevelTrace, v...)
|
||||
}
|
||||
|
||||
// Tracef provides trace level logging
|
||||
func Tracef(format string, v ...interface{}) {
|
||||
WithLevelf(LevelTrace, format, v...)
|
||||
}
|
||||
|
||||
// Debug provides debug level logging
|
||||
func Debug(v ...interface{}) {
|
||||
WithLevel(LevelDebug, v...)
|
||||
}
|
||||
|
||||
// Debugf provides debug level logging
|
||||
func Debugf(format string, v ...interface{}) {
|
||||
WithLevelf(LevelDebug, format, v...)
|
||||
}
|
||||
|
||||
// Warn provides warn level logging
|
||||
func Warn(v ...interface{}) {
|
||||
WithLevel(LevelWarn, v...)
|
||||
}
|
||||
|
||||
// Warnf provides warn level logging
|
||||
func Warnf(format string, v ...interface{}) {
|
||||
WithLevelf(LevelWarn, format, v...)
|
||||
}
|
||||
|
||||
// Info provides info level logging
|
||||
func Info(v ...interface{}) {
|
||||
WithLevel(LevelInfo, v...)
|
||||
}
|
||||
|
||||
// Infof provides info level logging
|
||||
func Infof(format string, v ...interface{}) {
|
||||
WithLevelf(LevelInfo, format, v...)
|
||||
}
|
||||
|
||||
// Error provides warn level logging
|
||||
func Error(v ...interface{}) {
|
||||
WithLevel(LevelError, v...)
|
||||
}
|
||||
|
||||
// Errorf provides warn level logging
|
||||
func Errorf(format string, v ...interface{}) {
|
||||
WithLevelf(LevelError, format, v...)
|
||||
}
|
||||
|
||||
// Fatal logs with Log and then exits with os.Exit(1)
|
||||
func Fatal(v ...interface{}) {
|
||||
WithLevel(LevelFatal, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatalf logs with Logf and then exits with os.Exit(1)
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
WithLevelf(LevelFatal, format, v...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// SetLogger sets the local logger
|
||||
func SetLogger(l log.Log) {
|
||||
logger = l
|
||||
}
|
||||
|
||||
// GetLogger returns the local logger
|
||||
func GetLogger() log.Log {
|
||||
return logger
|
||||
}
|
||||
|
||||
// SetLevel sets the log level
|
||||
func SetLevel(l Level) {
|
||||
atomic.StoreInt32((*int32)(&level), int32(l))
|
||||
}
|
||||
|
||||
// GetLevel returns the current level
|
||||
func GetLevel() Level {
|
||||
return level
|
||||
}
|
||||
|
||||
// Set a prefix for the logger
|
||||
func SetPrefix(p string) {
|
||||
prefix = p
|
||||
}
|
||||
|
||||
// Set service name
|
||||
func Name(name string) {
|
||||
prefix = fmt.Sprintf("[%s]", name)
|
||||
}
|
@ -16,10 +16,10 @@ import (
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/micro/go-micro/v2"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
maddr "github.com/micro/go-micro/v2/util/addr"
|
||||
mhttp "github.com/micro/go-micro/v2/util/http"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
mnet "github.com/micro/go-micro/v2/util/net"
|
||||
mls "github.com/micro/go-micro/v2/util/tls"
|
||||
)
|
||||
@ -126,7 +126,7 @@ func (s *service) register() error {
|
||||
|
||||
// use RegisterCheck func before register
|
||||
if err := s.opts.RegisterCheck(s.opts.Context); err != nil {
|
||||
log.Logf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err)
|
||||
log.Errorf("Server %s-%s register check error: %s", s.opts.Name, s.opts.Id, err)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ func (s *service) start() error {
|
||||
if s.static {
|
||||
_, err := os.Stat(static)
|
||||
if err == nil {
|
||||
log.Logf("Enabling static file serving from %s", static)
|
||||
log.Infof("Enabling static file serving from %s", static)
|
||||
s.mux.Handle("/", http.FileServer(http.Dir(static)))
|
||||
}
|
||||
}
|
||||
@ -223,7 +223,7 @@ func (s *service) start() error {
|
||||
ch <- l.Close()
|
||||
}()
|
||||
|
||||
log.Logf("Listening on %v", l.Addr().String())
|
||||
log.Infof("Listening on %v", l.Addr().String())
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ func (s *service) stop() error {
|
||||
s.exit <- ch
|
||||
s.running = false
|
||||
|
||||
log.Log("Stopping")
|
||||
log.Info("Stopping")
|
||||
|
||||
for _, fn := range s.opts.AfterStop {
|
||||
if err := fn(); err != nil {
|
||||
@ -392,10 +392,10 @@ func (s *service) Run() error {
|
||||
select {
|
||||
// wait on kill signal
|
||||
case sig := <-ch:
|
||||
log.Logf("Received signal %s", sig)
|
||||
log.Infof("Received signal %s", sig)
|
||||
// wait on context cancel
|
||||
case <-s.opts.Context.Done():
|
||||
log.Logf("Received context shutdown")
|
||||
log.Info("Received context shutdown")
|
||||
}
|
||||
|
||||
// exit reg loop
|
||||
|
Loading…
Reference in New Issue
Block a user