mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
improve commands (#648)
* stat show json refactor
> will show {} since scripts should expect it, its the json style of blank value
* combine statistics commands to one
* code optimize
* fix runtime flag
* remove json indent
* change overridden to override
* api bi -json
* convert stdin support
code optimize
* writeRow() code optimize
add stats tittle
revert back to restartlogger
* api log -restart
* follow log
* codeql
* move -json to shared flags
* flags optimize
* update flag descriptions
* change "-v" of "api bo" to duration
* change "-expire" of "tls cert" to days
* cmds short description optimize
* fix multiple log followers
* Format loader refactor
* "infra/conf/merge" refactor
* "LoadConfig" refactor
* add "infra/conf/mergers"
* contribute to it will benifit `v2ray run`,`v2ray test`,`v2ray convert`
* easily add new formats, by just adding a converter like json.FromTOML
* default format auto, to all cmds above
* auto detect input format
* mixed formats support
* better stdin behavior
* don't wait if no content
* don't use 'stdin:' placeholder
* `v2ray test` now behaves exactly the same with `v2ray run`, including stdin reading
* api ado, adi, rmo, rmi refactor
* support folders to files resolving, mixed formats
* remove remaining 'stdin:' placeholders
* fix tests
* os.Stdin.Stat() behaves different in platforms, removed
* code optimize
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
@@ -4,14 +4,17 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v4"
|
||||
"github.com/v2fly/v2ray-core/v4/app/log"
|
||||
"github.com/v2fly/v2ray-core/v4/common"
|
||||
cmlog "github.com/v2fly/v2ray-core/v4/common/log"
|
||||
)
|
||||
|
||||
// LoggerServer is the implemention of LoggerService
|
||||
type LoggerServer struct {
|
||||
V *core.Instance
|
||||
}
|
||||
@@ -31,6 +34,34 @@ func (s *LoggerServer) RestartLogger(ctx context.Context, request *RestartLogger
|
||||
return &RestartLoggerResponse{}, nil
|
||||
}
|
||||
|
||||
// FollowLog implements LoggerService.
|
||||
func (s *LoggerServer) FollowLog(_ *FollowLogRequest, stream LoggerService_FollowLogServer) error {
|
||||
logger := s.V.GetFeature((*log.Instance)(nil))
|
||||
if logger == nil {
|
||||
return newError("unable to get logger instance")
|
||||
}
|
||||
follower, ok := logger.(cmlog.Follower)
|
||||
if !ok {
|
||||
return newError("logger not support following")
|
||||
}
|
||||
var err error
|
||||
f := func(msg cmlog.Message) {
|
||||
err = stream.Send(&FollowLogResponse{
|
||||
Message: msg.String(),
|
||||
})
|
||||
}
|
||||
follower.AddFollower(f)
|
||||
defer follower.RemoveFollower(f)
|
||||
ticker := time.NewTicker(time.Second)
|
||||
for {
|
||||
<-ticker.C
|
||||
if err != nil {
|
||||
ticker.Stop()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *LoggerServer) mustEmbedUnimplementedLoggerServiceServer() {}
|
||||
|
||||
type service struct {
|
||||
|
||||
Reference in New Issue
Block a user