Skip to content

Commit

Permalink
Reduce logging noise produced by the browser module as a default (#1553)
Browse files Browse the repository at this point in the history
* Update frame session onConsoleAPICalled to always use debug log level

* Update frame session onLogEntryAdded to always use debug log level

* Make parseConsoleRemoteObjectPreview use debug log-level on overflow

* Make parseConsoleRemoteArrayPreview use debug log level on overflow
  • Loading branch information
oleiade authored Dec 10, 2024
1 parent 0fbb4c7 commit 83cdf88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
46 changes: 15 additions & 31 deletions common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ func (fs *FrameSession) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICall
WithField("source", "browser").
WithField("browser_source", "console-api")

/* accessing the state Group while not on the eventloop is racy
if s := fs.vu.State(); s.Group.Path != "" {
l = l.WithField("group", s.Group.Path)
}
*/
/* accessing the state Group while not on the eventloop is racy
if s := fs.vu.State(); s.Group.Path != "" {
l = l.WithField("group", s.Group.Path)
}
*/

parsedObjects := make([]string, 0, len(event.Args))
for _, robj := range event.Args {
Expand All @@ -661,18 +661,9 @@ func (fs *FrameSession) onConsoleAPICalled(event *cdpruntime.EventConsoleAPICall

msg := strings.Join(parsedObjects, " ")

switch event.Type {
case "log", "info":
l.Info(msg)
case "warning":
l.Warn(msg)
case "error":
l.Error(msg)
default:
// this is where debug & other console.* apis will default to (such as
// console.table).
l.Debug(msg)
}
// this is where debug & other console.* apis will default to (such as
// console.table).
l.Debug(msg)
}

func (fs *FrameSession) onExceptionThrown(event *cdpruntime.EventExceptionThrown) {
Expand Down Expand Up @@ -894,21 +885,14 @@ func (fs *FrameSession) onLogEntryAdded(event *cdplog.EventEntryAdded) {
WithField("url", event.Entry.URL).
WithField("browser_source", event.Entry.Source.String()).
WithField("line_number", event.Entry.LineNumber)
/* accessing the state Group while not on the eventloop is racy
if s := fs.vu.State(); s.Group.Path != "" {
l = l.WithField("group", s.Group.Path)
}
*/
switch event.Entry.Level {
case "info":
l.Info(event.Entry.Text)
case "warning":
l.Warn(event.Entry.Text)
case "error":
l.WithField("stacktrace", event.Entry.StackTrace).Error(event.Entry.Text)
default:
l.Debug(event.Entry.Text)

/* accessing the state Group while not on the eventloop is racy
if s := fs.vu.State(); s.Group.Path != "" {
l = l.WithField("group", s.Group.Path)
}
*/

l.Debug(event.Entry.Text)
}

func (fs *FrameSession) onPageLifecycle(event *cdppage.EventLifecycleEvent) {
Expand Down
4 changes: 2 additions & 2 deletions common/remote_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func valueFromRemoteObject(_ context.Context, robj *cdpruntime.RemoteObject) (an
func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) (string, error) {
obj := make(map[string]string)
if op.Overflow {
logger.Infof("parseConsoleRemoteObjectPreview", "object is too large and will be parsed partially")
logger.Debugf("parseConsoleRemoteObjectPreview", "object is too large and will be parsed partially")
}

for _, p := range op.Properties {
Expand All @@ -209,7 +209,7 @@ func parseConsoleRemoteObjectPreview(logger *log.Logger, op *cdpruntime.ObjectPr
func parseConsoleRemoteArrayPreview(logger *log.Logger, op *cdpruntime.ObjectPreview) (string, error) {
arr := make([]any, 0, len(op.Properties))
if op.Overflow {
logger.Infof("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially")
logger.Debugf("parseConsoleRemoteArrayPreview", "array is too large and will be parsed partially")
}

for _, p := range op.Properties {
Expand Down

0 comments on commit 83cdf88

Please sign in to comment.