Skip to content

Commit

Permalink
Improved logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette committed Dec 20, 2018
1 parent bb9d635 commit 440ced1
Show file tree
Hide file tree
Showing 39 changed files with 593 additions and 323 deletions.
46 changes: 46 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions actions/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (self *UpdateEventTable) Run(
}
}()

logger := logging.NewLogger(config)
logger := logging.GetLogger(config, &logging.ClientComponent)

// Start a new query for each event.
action_obj := &VQLClientAction{}
Expand All @@ -61,11 +61,11 @@ func (self *UpdateEventTable) Run(
}
}

logger.Info("Starting %s\n", name)
logger.Info("Starting %s", name)
action_obj.StartQuery(
config, new_ctx, responder, event)

logger.Info("Finished %s\n", name)
logger.Info("Finished %s", name)
}(event)
}

Expand Down
2 changes: 1 addition & 1 deletion actions/vql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type LogWriter struct {
}

func (self *LogWriter) Write(b []byte) (int, error) {
logging.NewLogger(self.config_obj).Info(string(b))
logging.GetLogger(self.config_obj, &logging.FrontendComponent).Info(string(b))
err := self.responder.Log("%s", string(b))
if err != nil {
return 0, err
Expand Down
10 changes: 5 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (self *ApiServer) LaunchFlow(
ctx context.Context,
in *flows_proto.FlowRunnerArgs) (*api_proto.StartFlowResponse, error) {
result := &api_proto.StartFlowResponse{}
in.Creator = getUsername(ctx)
in.Creator = GetUsername(ctx)
flow_id, err := flows.StartFlow(self.config, in)
if err != nil {
return nil, err
Expand Down Expand Up @@ -227,7 +227,7 @@ func (self *ApiServer) GetUserUITraits(
ctx context.Context,
in *empty.Empty) (*api_proto.ApiGrrUser, error) {
result := NewDefaultUserObject(self.config)
result.Username = getUsername(ctx)
result.Username = GetUsername(ctx)
return result, nil
}

Expand Down Expand Up @@ -260,14 +260,14 @@ func (self *ApiServer) GetUserNotifications(
in *api_proto.GetUserNotificationsRequest) (
*api_proto.GetUserNotificationsResponse, error) {
result, err := users.GetUserNotifications(
self.config, getUsername(ctx), in.ClearPending)
self.config, GetUsername(ctx), in.ClearPending)
return result, err
}

func (self *ApiServer) GetUserNotificationCount(
ctx context.Context,
in *empty.Empty) (*api_proto.UserNotificationCount, error) {
n, err := users.GetUserNotificationCount(self.config, getUsername(ctx))
n, err := users.GetUserNotificationCount(self.config, GetUsername(ctx))
return &api_proto.UserNotificationCount{Count: n}, err
}

Expand Down Expand Up @@ -352,7 +352,7 @@ func StartServer(config_obj *api_proto.Config, server_obj *server.Server) error
// Register reflection service.
reflection.Register(grpcServer)

logger := logging.NewLogger(config_obj)
logger := logging.GetLogger(config_obj, &logging.FrontendComponent)
logger.Info("Launched gRPC API server on %v ", bind_addr)

err = grpcServer.Serve(lis)
Expand Down
2 changes: 1 addition & 1 deletion api/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"www.velocidex.com/golang/velociraptor/gui/assets"
)

func install_mux(config_obj *api_proto.Config, mux *http.ServeMux) {
func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
dir := "/static/"
mux.Handle(dir, http.FileServer(assets.HTTP))
}
Expand Down
5 changes: 3 additions & 2 deletions api/assets_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
"www.velocidex.com/golang/velociraptor/logging"
)

func install_mux(config_obj *api_proto.Config, mux *http.ServeMux) {
logging.NewLogger(config_obj).Info("GUI will serve files from directory gui/static")
func install_static_assets(config_obj *api_proto.Config, mux *http.ServeMux) {
logging.GetLogger(config_obj, &logging.FrontendComponent).
Info("GUI will serve files from directory gui/static")
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(
http.Dir("gui/static"))))
}
Expand Down
9 changes: 7 additions & 2 deletions api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"google.golang.org/grpc/metadata"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/logging"
users "www.velocidex.com/golang/velociraptor/users"
)

Expand Down Expand Up @@ -42,7 +43,11 @@ func checkUserCredentialsHandler(

// Record the username for handlers lower in the stack.
ctx := context.WithValue(r.Context(), "USER", username)
parent.ServeHTTP(w, r.WithContext(ctx))

// Need to call logging after auth so it can access
// the USER value in the context.
logging.GetLoggingHandler(config_obj)(parent).ServeHTTP(
w, r.WithContext(ctx))
})
}

Expand All @@ -67,7 +72,7 @@ func getClientApprovalForUser(
return &result
}

func getUsername(ctx context.Context) string {
func GetUsername(ctx context.Context) string {
md, ok := metadata.FromIncomingContext(ctx)
if ok {
username := md.Get("USER")
Expand Down
2 changes: 1 addition & 1 deletion api/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func flowResultDownloadHandler(
// URL format: /api/v1/DownloadHuntResults
func huntResultDownloadHandler(
config_obj *api_proto.Config) http.Handler {
logger := logging.NewLogger(config_obj)
logger := logging.GetLogger(config_obj, &logging.FrontendComponent)

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hunt_id, pres := r.URL.Query()["hunt_id"]
Expand Down
7 changes: 6 additions & 1 deletion api/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
api_proto "www.velocidex.com/golang/velociraptor/api/proto"
"www.velocidex.com/golang/velociraptor/logging"
users "www.velocidex.com/golang/velociraptor/users"
)

Expand Down Expand Up @@ -220,6 +221,10 @@ to log in again:
// Checking is successfull - user authorized.
ctx := context.WithValue(
r.Context(), "USER", username)
parent.ServeHTTP(w, r.WithContext(ctx))

// Need to call logging after auth so it can access
// the USER value in the context.
logging.GetLoggingHandler(config_obj)(parent).ServeHTTP(
w, r.WithContext(ctx))
})
}
Loading

0 comments on commit 440ced1

Please sign in to comment.