Skip to content

Commit

Permalink
Fix to flush console log
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Inoue <[email protected]>
  • Loading branch information
musaprg committed Jul 22, 2023
1 parent e8c4a99 commit 9d8872b
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions librarejob/rarejob.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func (c *client) ReserveTutor(ctx context.Context, from time.Time, margin time.D
c.saveCurrentScreenshot(rarejobctlTempDir, "reservation_completed.png")
zap.L().Debug("reservation completed")

c.flushConsoleLogs()

return &Reserve{
Name: tutors[0].Name,
StartAt: tutors[0].AvailableSlots[0],
Expand All @@ -313,14 +315,6 @@ func (c *client) Teardown() error {

if c.wd != nil {
zap.L().Debug("quitting current webdriver session")
// output console log
clog, err := c.wd.Log(log.Browser)
if err != nil {
return fmt.Errorf("failed to get console log: %w", err)
}
for _, l := range clog {
zap.L().Debug(l.Message, zap.Time("timestamp", l.Timestamp), zap.String("level", string(l.Level)))
}
if err := c.wd.Quit(); err != nil {
return fmt.Errorf("failed to quit current webdriver session: %w", err)
}
Expand All @@ -333,10 +327,15 @@ func (c *client) Teardown() error {
return nil
}

func formatConsoleLogs(logs []log.Message) []string {
var s []string
for _, l := range logs {
s = append(s, fmt.Sprintf("%s: %s", l.Timestamp, l.Message))
func (c *client) flushConsoleLogs() []string {
defer zap.L().Sync()

// output console log
clog, err := c.wd.Log(log.Browser)
if err != nil {
zap.L().Warn("failed to get console log", zap.Error(err))
}
for _, l := range clog {
zap.L().Debug(l.Message, zap.Time("timestamp", l.Timestamp), zap.String("level", string(l.Level)))
}
return s
}

0 comments on commit 9d8872b

Please sign in to comment.