Skip to content

Commit

Permalink
add log level for driver (#291)
Browse files Browse the repository at this point in the history
* add log level for driver

* update

* fix
  • Loading branch information
Uunnamed authored Aug 18, 2020
1 parent edac32b commit 47f64da
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,13 @@ skipped or have nil values. Some of them, if not passed, are taken from the
;; :all is set.
:log-level :err ;; to show only errors but not debug

;; Sets driver's log level.
;; The value is a string. Possible values are:
;; chrome: [ALL, DEBUG, INFO, WARNING, SEVERE, OFF]
;; phantomjs: [ERROR, WARN, INFO, DEBUG] (default INFO)
;; firefox [fatal, error, warn, info, config, debug, trace]
:driver-log-level

;; Paths to the driver's log files as strings.
;; When not set, the output goes to /dev/null (or NUL on Windows)
:log-stdout
Expand Down
14 changes: 13 additions & 1 deletion src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,15 @@
browser's logs. Possible values are: `:off`, `:debug`, `:warn`, `:info`,
`:error`, `:all`. When not passed, `:all` is set.
-- `:driver-log-level` a keyword to set driver's log level.
The value is a string. Possible values are:
chrome: [ALL, DEBUG, INFO, WARNING, SEVERE, OFF]
phantomjs: [ERROR, WARN, INFO, DEBUG] (default INFO)
firefox [fatal, error, warn, info, config, debug, trace]
-- `:log-stdout` and `:log-stderr`. Paths to the driver's log files as strings.
When not set, the output goes to /dev/null (or NUL on Windows)
-- `:args-driver` is a vector of additional arguments to the
driver's process.
Expand All @@ -2977,7 +2986,8 @@
args-driver
path-driver
download-dir
path-browser]}]]
path-browser
driver-log-level]}]]

(let [{:keys [type port]} @driver
log-level (or log-level :all)
Expand All @@ -2991,6 +3001,8 @@
(let [{:keys [perf]} dev]
(swap! driver drv/set-perf-logging perf)))

_ (when driver-log-level
(swap! driver drv/set-driver-log-level driver-log-level))
_ (when args-driver
(swap! driver drv/set-args args-driver))
_ (when path-browser
Expand Down
24 changes: 24 additions & 0 deletions src/etaoin/driver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,27 @@
:enablePage page?
:traceCategories (string/join "," (map name categories))
:bufferUsageReportingInterval interval})))))

(defmulti set-driver-log-level
dispatch-driver)

(defmethod set-driver-log-level
:default
[driver _]
(log/debugf "For this driver, the log level setting is not implemented.")
driver)

(defmethod set-driver-log-level
:chrome
[driver log-level]
(set-args driver [(format "--log-level=%s" log-level)]))

(defmethod set-driver-log-level
:firefox
[driver log-level]
(set-args driver ["--log" log-level]))

(defmethod set-driver-log-level
:phantom
[driver log-level]
(set-args driver [(format "--webdriver-loglevel=%s" log-level)]))

0 comments on commit 47f64da

Please sign in to comment.