@@ -9,55 +9,105 @@ description: >
9
9
Each language adopts a distinctly different approach to logging information about the activity
10
10
of the program.
11
11
12
- ## Ruby
13
-
14
- Ruby uses a custom implementation of the default ` Logger ` class with some interesting additional features.
15
-
16
- ### Logger output
17
-
18
- By default, logs are sent to the console in ` stdout ` .
19
- if you want to store the logs in a file, add this to your code:
20
- ``` ruby
21
- Selenium ::WebDriver .logger.output = ' /path/to/selenium.log'
22
- ```
23
-
24
- ### Logger level
25
-
26
- The basic levels for the Ruby logger are: ` :debug ` , ` :info ` , ` :warn ` , ` :error ` , ` :fatal `
27
-
28
- Selenium uses ` :info ` and ` :debug ` similar to "verbose" and "very verbose", so the default
29
- is ` :warn ` .
30
-
31
- To change the level of the logger:
32
- ``` ruby
33
- Selenium ::WebDriver .logger.level = :fatal
34
- ```
12
+ ### 1. Getting a logger
13
+
14
+ {{< tabpane langEqualsHeader=true text=true >}}
15
+ {{< tab header="Java" >}}
16
+ {{< alert-content >}}{{< /alert-content >}}
17
+ {{< /tab >}}
18
+ {{< tab header="Python" >}}
19
+ {{< alert-content >}}{{< /alert-content >}}
20
+ {{< /tab >}}
21
+ {{< tab header="CSharp" >}}
22
+ {{< alert-content >}}{{< /alert-content >}}
23
+ {{< /tab >}}
24
+ {{< tab header="Ruby" >}}
25
+ <p >Ruby uses a custom implementation of the default `Logger` class with some interesting additional features.</p >
26
+ {{< /tab >}}
27
+ {{< tab header="JavaScript" >}}
28
+ <pre >
29
+ const logging = require('selenium-webdriver/lib/logging')
30
+ logger = logging.getLogger('webdriver')</pre >
31
+ {{< /tab >}}
32
+ {{< tab header="Kotlin" >}}
33
+ {{< alert-content >}}{{< /alert-content >}}
34
+ {{< /tab >}}
35
+ {{< /tabpane >}}
36
+
37
+ ### 2. Logger Level
38
+ Logger level helps to filter out logs based on their severity.
39
+
40
+ {{< tabpane langEqualsHeader=true text=true >}}
41
+ {{< tab header="Java" >}}
42
+ {{< alert-content >}}{{< /alert-content >}}
43
+ {{< /tab >}}
44
+ {{< tab header="Python" >}}
45
+ {{< alert-content >}}{{< /alert-content >}}
46
+ {{< /tab >}}
47
+ {{< tab header="CSharp" >}}
48
+ {{< alert-content >}}{{< /alert-content >}}
49
+ {{< /tab >}}
50
+ {{< tab header="Ruby" >}}
51
+ <p >Levels are: <i >`:debug`, `:info`, `:warn`, `:error`, `:fatal`.</i > Default is <i >`:warn`</i >.</p >
52
+ <p >To change the level of the logger:</p >
53
+ <pre >
54
+ Selenium::WebDriver.logger.level = :fatal</pre >
55
+ {{< /tab >}}
56
+ {{< tab header="JavaScript" >}}
57
+ <p >Levels are: <i >`OFF`, `SEVERE`, `WARNING`, `INFO`, `DEBUG`, `FINE`, `FINER`, `FINEST`, `ALL`</i >. Default is <i >`OFF`</i >.</p >
58
+ <p >To change the level of the logger:</p >
59
+ <pre >
60
+ logger.setLevel(logging.Level.INFO)</pre >
61
+ {{< /tab >}}
62
+ {{< tab header="Kotlin" >}}
63
+ {{< alert-content >}}{{< /alert-content >}}
64
+ {{< /tab >}}
65
+ {{< /tabpane >}}
35
66
36
67
** WARN**
37
68
38
69
Warnings include everything we want users to be aware of by default. This is mostly used
39
70
for deprecations. For various reasons, Selenium project does not follow standard Semantic Versioning practices.
40
71
Our policy is to mark things as deprecated for 3 releases and then remove them.
41
- As such, Ruby logs deprecations as warnings, specifying what is changing, what needs to be
42
- used instead. It may include additional messages, and always includes an ID.
43
-
44
- For example:
45
- > 2022-12-24 16:07:09 WARN Selenium [ DEPRECATION] [ : jwp_caps ] \` Capabilities#version=\` is deprecated. Use \` Capabilities#browser_version=\` instead.
46
-
47
- Because these items can get annoying, we've provided an easy way to turn them off.
48
-
49
- To turn off a specific warning, set the ID to ignore:
50
- ``` ruby
51
- Selenium ::WebDriver .logger.ignore(:jwp_caps )
52
- ```
53
- It accepts an ` Array ` to turn off multiple IDs:
54
- ``` ruby
55
- Selenium ::WebDriver .logger.ignore(%i[jwp_caps pause pauses] )
56
- ```
57
- To turn off all * deprecation* notices:
58
- ``` ruby
59
- Selenium ::WebDriver .logger.ignore(:deprecations )
60
- ```
72
+
73
+ {{< tabpane langEqualsHeader=true text=true >}}
74
+ {{< tab header="Java" >}}
75
+ {{< alert-content >}}{{< /alert-content >}}
76
+ {{< /tab >}}
77
+ {{< tab header="Python" >}}
78
+ {{< alert-content >}}{{< /alert-content >}}
79
+ {{< /tab >}}
80
+ {{< tab header="CSharp" >}}
81
+ {{< alert-content >}}{{< /alert-content >}}
82
+ {{< /tab >}}
83
+ {{< tab header="Ruby" >}}
84
+ <p >Ruby logs deprecations as warnings, specifying what is changing, what needs to be
85
+ used instead. It may include additional messages, and always includes an ID.</p >
86
+
87
+ <p >For example:</p >
88
+ <blockquote >2022-12-24 16:07:09 WARN Selenium [DEPRECATION] [:jwp_caps] \`Capabilities#version=\` is deprecated. Use \`Capabilities#browser_version=\` instead.</blockquote >
89
+
90
+ <p >Because these items can get annoying, we've provided an easy way to turn them off.</p >
91
+
92
+ <p >To turn off a specific warning, set the ID to ignore:</p >
93
+ <pre >
94
+ Selenium::WebDriver.logger.ignore(:jwp_caps)</pre >
95
+ <br >
96
+ <p >It accepts an `Array` to turn off multiple IDs:</p >
97
+ <pre >
98
+ Selenium::WebDriver.logger.ignore(%i[jwp_caps pause pauses])</pre >
99
+ <br >
100
+ <p >To turn off all *deprecation* notices:</p >
101
+ <pre >
102
+ Selenium::WebDriver.logger.ignore(:deprecations)</pre >
103
+ {{< /tab >}}
104
+ {{< tab header="JavaScript" >}}
105
+ {{< alert-content >}}{{< /alert-content >}}
106
+ {{< /tab >}}
107
+ {{< tab header="Kotlin" >}}
108
+ {{< alert-content >}}{{< /alert-content >}}
109
+ {{< /tab >}}
110
+ {{< /tabpane >}}
61
111
62
112
** INFO**
63
113
@@ -66,93 +116,63 @@ sent to and received from the driver or server. This is a great way to see what
66
116
doing under the hood, and can be used to determine if it is Selenium code or driver code that
67
117
is causing a problem. (Unfortunately, we can't blame the driver if Selenium is sending incorrect syntax).
68
118
119
+ Different languages have different level to log requests and response.
120
+
121
+ {{< tabpane langEqualsHeader=true text=true >}}
122
+ {{< tab header="Java" >}}
123
+ {{< alert-content >}}{{< /alert-content >}}
124
+ {{< /tab >}}
125
+ {{< tab header="Python" >}}
126
+ {{< alert-content >}}{{< /alert-content >}}
127
+ {{< /tab >}}
128
+ {{< tab header="CSharp" >}}
129
+ {{< alert-content >}}{{< /alert-content >}}
130
+ {{< /tab >}}
131
+ {{< tab header="Ruby" >}}
132
+ Logs request and response at level: <i >` :info ` </i >
133
+ {{< /tab >}}
134
+ {{< tab header="JavaScript" >}}
135
+ Logs request and response at level: <i >` FINER ` </i >
136
+ {{< /tab >}}
137
+ {{< tab header="Kotlin" >}}
138
+ {{< alert-content >}}{{< /alert-content >}}
139
+ {{< /tab >}}
140
+ {{< /tabpane >}}
141
+
69
142
** DEBUG**
70
143
71
144
This is less useful information where we log things about the servers and the sockets, and header information, etc.
72
145
Debug mode is set if either ` $DEBUG ` is true or ` ENV['DEBUG'] ` has a value.
73
146
74
-
75
- ## Javascript
76
-
77
- JS has implemented logging APIs. It has also added LogManager to maintain a collection of loggers.
78
-
79
- ### 1. Getting a logger can be done in two ways:
80
-
81
- ``` js
82
- const logging = require (' selenium-webdriver/lib/logging' )
83
- ```
84
-
85
- First method using manager
86
- ``` js
87
- mgr = new logging.LogManager ()
88
- logger = mgr .getLogger (' ' )
89
- ```
90
-
91
- Second method without manager
92
- ``` js
93
- logger = logging .getLogger (' ' )
94
- ```
95
-
96
- Loggers class uses hierarchical, dot-delimited namespaces (e.g. "" > "webdriver" > "webdriver.logging"). For example, the following code will give a hierarchy of loggers:
97
- ``` js
98
- logger = mgr .getLogger (' foo.bar.baz' )
99
- ```
100
-
101
- "" (parent of) > "foo" (parent of) > "foo.bar" (parent of) > "foo.bar.baz" (=logger)
102
-
103
-
104
- ### 2. Logger Level:
105
-
106
- The basic levels for JS loggers are: ` OFF ` , ` SEVERE ` , ` WARNING ` , ` INFO ` , ` DEBUG ` , ` FINE ` , ` FINER ` , ` FINEST ` , ` ALL ` .
107
- To log messages at the given level pass the level in the ` log() ` method:
108
- ``` js
109
- logger .log (logging .Level .INFO , ' This is an info message' )
110
- ```
111
-
112
- You can also use the instance methods to target logs of a particular level:
113
- ``` js
114
- logger .finest (' this is the finest message' )
115
- logger .finer (' this is a finer message' )
116
- logger .info (' this is an info message' )
117
- logger .warning (' this is a warning message' )
118
- logger .severe (' this is a severe message' )
119
- ```
120
-
121
- By default the logger's level is ` Level.OFF `
122
- To change the level of the logger:
123
- ``` js
124
- logger .setLevel (logging .Level .INFO )
125
- ```
126
-
127
147
### 3. Log Output:
128
-
129
- As opposed to ruby which by default sends logs to console in stdout, JS has the option to add a handler. The handler will be invoked for each message logged with this instance, or any of its descendants.
130
- ``` js
131
- logger . addHandler (callback)
132
- ```
133
-
134
- JS has provided a method to add console handler to the given logger. The console handler will log all messages using the JavaScript Console API:
135
- ``` js
136
- logging . addConsoleHandler (logger)
137
- ```
138
-
139
- Similarly, to add console handler to the root logger:
140
- ``` js
141
- logging . installConsoleHandler ()
142
- ```
143
-
144
- ### 4. Logging Preference (remote logging API):
145
-
146
- JS gives the ability to define log preference for a remote WebDriver session. There are 5 common log types: ` BROWSER ` , ` CLIENT ` , ` DRIVER ` , ` PERFORMANCE ` , ` SERVER `
147
-
148
- To set a log level for a particular log type:
149
- ``` js
150
- let prefs = new logging.Preferences ()
151
- prefs . setLevel ( logging . Type . BROWSER , logging . Level . FINE )
152
- ```
153
-
154
- -----
155
-
156
- {{< alert-content >}}
157
- Descriptions of how to set and use logging in Java, Python, JavaScript, and .NET
158
- {{< /alert-content >}}
148
+ Logs can be displayed on ` stdout ` or stored in a file.
149
+
150
+ {{< tabpane langEqualsHeader=true text=true >}}
151
+ {{< tab header="Java" >}}
152
+ {{< alert-content >}}{{< /alert-content >}}
153
+ {{< /tab >}}
154
+ {{< tab header="Python" >}}
155
+ {{< alert-content >}}{{< /alert-content >}}
156
+ {{< /tab >}}
157
+ {{< tab header="CSharp" >}}
158
+ {{< alert-content >}}{{< /alert-content >}}
159
+ {{< /tab >}}
160
+ {{< tab header="Ruby" >}}
161
+ < p >By default, logs are sent to the console in `stdout`.</ p >
162
+ < p >To store the logs in a file:</ p >
163
+ < pre >
164
+ Selenium::WebDriver.logger.output = '/path/to/selenium.log'</ pre >
165
+ {{< /tab >}}
166
+ {{< tab header="JavaScript" >}}
167
+ < p >Send logs to console output:</ p >
168
+ < pre >
169
+ logging.installConsoleHandler()</ pre >
170
+ < br >
171
+ {{< alert-content >}}
172
+ Store logs in a file.
173
+ {{< /alert-content >}}
174
+ {{< /tab >}}
175
+ {{< tab header="Kotlin" >}}
176
+ {{< alert-content >}}{{< / alert-content >}}
177
+ {{< /tab >}}
178
+ {{< /tabpane >}}
0 commit comments