-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add logging to files #257
add logging to files #257
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2894,6 +2894,7 @@ | |
proxy | ||
profile | ||
headless | ||
log-files | ||
log-level | ||
args-driver | ||
path-driver | ||
|
@@ -2939,7 +2940,7 @@ | |
|
||
proc-args (drv/get-args @driver) | ||
_ (log/debugf "Starting process: %s" (str/join \space proc-args)) | ||
process (proc/run proc-args)] | ||
process (proc/run proc-args log-files)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут их нужно будет передать мапой, вроде
|
||
(swap! driver assoc | ||
:env env ;; todo process env | ||
:process process) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
(ns etaoin.proc | ||
(:require [clojure.java.io :as io]) | ||
(:import java.lang.Runtime | ||
java.lang.IllegalThreadStateException | ||
java.io.IOException)) | ||
(:require [clojure.java.io :as io] | ||
[clojure.string :as str]) | ||
(:import java.lang.IllegalThreadStateException | ||
java.io.IOException)) | ||
|
||
(defn get-null-file ^java.io.File | ||
[] | ||
(if-let [windows? (str/starts-with? (System/getProperty "os.name") "Windows")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут переменная windows? не нужна, поэтому просто if. Но еще лучше вынести ее на уровне def, потому что операционка не меняется в рантайме.
|
||
(io/file "NUL") | ||
(io/file "/dev/null"))) | ||
|
||
(defn get-log-file | ||
[file-path] | ||
(if file-path (io/file file-path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. положительную ветку перенести на след. строку после условия |
||
(get-null-file))) | ||
|
||
(defn java-params ^"[Ljava.lang.String;" [params] | ||
(->> params | ||
(map str) | ||
(into-array String))) | ||
|
||
(defn run [args] | ||
(let [binary (first args) | ||
readme-link "https://github.com/igrishaev/etaoin#installing-the-browser-drivers" | ||
pb (java.lang.ProcessBuilder. (java-params args))] | ||
(.redirectOutput pb (java.io.File/createTempFile "driver.out" ".log")) | ||
(.redirectError pb (java.io.File/createTempFile "driver.err" ".log")) | ||
(try | ||
(.start pb) | ||
(catch java.io.IOException e | ||
(throw (ex-info | ||
(format "Cannot find a binary file `%s` for the driver. | ||
(defn run | ||
([args] (run args {})) | ||
([args {:keys [log-stdout log-stderr]}] | ||
(let [binary (first args) | ||
readme-link "https://github.com/igrishaev/etaoin#installing-the-browser-drivers" | ||
pb (java.lang.ProcessBuilder. (java-params args))] | ||
(.redirectOutput pb (get-log-file log-stdout)) | ||
(.redirectError pb (get-log-file log-stderr)) | ||
(try | ||
(.start pb) | ||
(catch java.io.IOException e | ||
(throw (ex-info | ||
(format "Cannot find a binary file `%s` for the driver. | ||
Please ensure you have the driver installed and specify the path to it. | ||
For driver installation, check out the official readme file from Etaoin: %s" binary readme-link) | ||
{:args args} e)))))) | ||
{:args args} e))))))) | ||
|
||
;; todo store those streams | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут не очень, что файлы слиплись в одну мапу. Лучше отдельными ключами log-stdout и log-stderr