go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.

Home Page:https://go-rod.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to Log CDP Logs to a File or Use slog

thuongtin opened this issue · comments

I’m currently working on a project using the go-rod/rod library and I need some assistance with logging CDP logs. Specifically, I want to achieve one of the following:

1.	Log CDP logs to a file.
2.	Use slog for logging CDP logs.

Could anyone provide guidance or examples on how to implement either of these logging methods with go-rod/rod? Any help or pointers to relevant documentation would be greatly appreciated.

Please add a valid Rod Version: v0.0.0 to your issue. Current version is v0.116.0

generated by check-issue

All the unit test of rod will output files, check the unit test code as example:

rod/setup_test.go

Lines 253 to 259 in 0340433

// create init log file
utils.E(os.MkdirAll(filepath.Join(LogDir, id), 0o755))
f, err := os.Create(filepath.Join(LogDir, id, "_.log"))
log := log.New(f, "", log.Ltime)
utils.E(err)
client := cdp.New().Logger(utils.MultiLogger(defaults.CDP, log)).Start(cdp.MustConnectWS(u))