Skip to content

Commit 7749ff8

Browse files
committed
created tabs for different languages
1 parent 5613555 commit 7749ff8

File tree

1 file changed

+137
-122
lines changed
  • website_and_docs/content/documentation/webdriver/troubleshooting

1 file changed

+137
-122
lines changed

website_and_docs/content/documentation/webdriver/troubleshooting/logging.en.md

Lines changed: 137 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -9,147 +9,162 @@ description: >
99
Each language adopts a distinctly different approach to logging information about the activity
1010
of the program.
1111

12-
## Ruby
12+
{{< tabpane code=false langEqualsHeader=true >}}
13+
{{< tab header="Java" >}}
14+
{{< /tab >}}
1315

14-
Ruby uses a custom implementation of the default `Logger` class with some interesting additional features.
16+
{{< tab header="Python" >}}
17+
{{< /tab >}}
1518

16-
### Logger output
19+
{{< tab header="CSharp" >}}
20+
{{< /tab >}}
1721

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-
```
22+
{{< tab header="Ruby" >}}
23+
<p>Ruby uses a custom implementation of the default <i>`Logger`</i> class with some interesting additional features.</p>
2324

24-
### Logger level
25+
<p><b>1. Logger output</b></p>
2526

26-
The basic levels for the Ruby logger are: `:debug`, `:info`, `:warn`, `:error`, `:fatal`
27+
<p>By default, logs are sent to the console in <i>`stdout`</i>. If you want to store the logs in a file, add this to your code:</p>
28+
<pre>
29+
Selenium::WebDriver.logger.output = '/path/to/selenium.log'
30+
</pre>
31+
<br>
32+
<p><b>2. Logger level</b></p>
2733

28-
Selenium uses `:info` and `:debug` similar to "verbose" and "very verbose", so the default
29-
is `:warn`.
34+
<p>The basic levels for the Ruby logger are: <i>`:debug`, `:info`, `:warn`, `:error`, `:fatal`</i>.
3035

31-
To change the level of the logger:
32-
```ruby
33-
Selenium::WebDriver.logger.level = :fatal
34-
```
36+
Selenium uses <i>`:info`</i> and <i>`:debug`</i> similar to "verbose" and "very verbose", so the default
37+
is <i>`:warn`</i>.</p>
3538

36-
**WARN**
39+
<p>To change the level of the logger:</p>
40+
<pre>
41+
Selenium::WebDriver.logger.level = :fatal
42+
</pre>
43+
<br>
44+
<p><b>WARN</b></p>
3745

38-
Warnings include everything we want users to be aware of by default. This is mostly used
46+
<p>Warnings include everything we want users to be aware of by default. This is mostly used
3947
for deprecations. For various reasons, Selenium project does not follow standard Semantic Versioning practices.
4048
Our policy is to mark things as deprecated for 3 releases and then remove them.
4149
As such, Ruby logs deprecations as warnings, specifying what is changing, what needs to be
4250
used instead. It may include additional messages, and always includes an ID.
51+
</p>
4352

44-
For example:
53+
<p>For example:</p>
54+
<pre>
4555
> 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-
```
61-
62-
**INFO**
63-
64-
This is where the most useful information gets logged. Selenium logs the endpoints and payloads
56+
</pre>
57+
<br>
58+
<p>Because these items can get annoying, we've provided an easy way to turn them off.</p>
59+
60+
<p>To turn off a specific warning, set the ID to ignore:</p>
61+
<pre>
62+
Selenium::WebDriver.logger.ignore(:jwp_caps)
63+
</pre>
64+
<br>
65+
<p>It accepts an `Array` to turn off multiple IDs:</p>
66+
<pre>
67+
Selenium::WebDriver.logger.ignore(%i[jwp_caps pause pauses])
68+
</pre>
69+
<br>
70+
<p>To turn off all <i>deprecation</i> notices:</p>
71+
<pre>
72+
Selenium::WebDriver.logger.ignore(:deprecations)
73+
</pre>
74+
<br>
75+
<p><b>INFO</b></p>
76+
77+
<p>This is where the most useful information gets logged. Selenium logs the endpoints and payloads
6578
sent to and received from the driver or server. This is a great way to see what Selenium is actually
6679
doing under the hood, and can be used to determine if it is Selenium code or driver code that
6780
is causing a problem. (Unfortunately, we can't blame the driver if Selenium is sending incorrect syntax).
81+
</p>
82+
83+
<p><b>DEBUG</b></p>
84+
85+
<p>This is less useful information where we log things about the servers and the sockets, and header information, etc.
86+
Debug mode is set if either <i>`$DEBUG`</i> is true or <i>`ENV['DEBUG']`</i> has a value.</p>
87+
{{< /tab >}}
88+
89+
{{< tab header="JavaScript" code=true >}}
90+
<p>JS has implemented logging APIs. It has also added LogManager to maintain a collection of loggers.</p>
91+
<p><b>1. Getting a logger can be done in two ways:</b></p>
92+
<pre>
93+
const logging = require('selenium-webdriver/lib/logging')
94+
</pre>
95+
<br>
96+
<p>First method using manager</p>
97+
<pre>
98+
mgr = new logging.LogManager()
99+
logger = mgr.getLogger('')
100+
</pre>
101+
<br>
102+
<p>Second method without manager</p>
103+
<pre>
104+
logger = logging.getLogger('')
105+
</pre>
106+
<br>
107+
<p>Loggers class uses hierarchical, dot-delimited namespaces (e.g. "" > "webdriver" > "webdriver.logging"). For example, the following code will give a hierarchy of loggers:</p>
108+
<pre>
109+
logger = mgr.getLogger('foo.bar.baz')
110+
</pre>
111+
<br>
112+
<p>"" (parent of) > "foo" (parent of) > "foo.bar" (parent of) > "foo.bar.baz" (=logger)</p>
113+
114+
<p><b>2. Logger Level:</b></p>
115+
116+
<p>The basic levels for JS loggers are: <i>`OFF`, `SEVERE`, `WARNING`, `INFO`, `DEBUG`, `FINE`, `FINER`, `FINEST`, `ALL`</i>.<br>
117+
To log messages at the given level pass the level in the <i>`log()`</i> method:</p>
118+
<pre>
119+
logger.log(logging.Level.INFO, 'This is an info message')
120+
</pre>
121+
<br>
122+
<p>You can also use the instance methods to target logs of a particular level:<p>
123+
<pre>
124+
logger.finest('this is the finest message')
125+
logger.finer('this is a finer message')
126+
logger.info('this is an info message')
127+
logger.warning('this is a warning message')
128+
logger.severe('this is a severe message')
129+
</pre>
130+
<br>
131+
<p>By default the logger's level is <i>`Level.OFF`.</i> To change the level of the logger:</p>
132+
<pre>
133+
logger.setLevel(logging.Level.INFO)
134+
</pre>
135+
<br>
136+
<p><b>3. Log Output:</b></p>
137+
138+
<p>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.</p>
139+
<pre>
140+
logger.addHandler(callback)
141+
</pre>
142+
<br>
143+
<p>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:</p>
144+
<pre>
145+
logging.addConsoleHandler(logger)
146+
</pre>
147+
<br>
148+
<p>Similarly, to add console handler to the root logger:</p>
149+
<pre>
150+
logging.installConsoleHandler()
151+
</pre>
152+
<br>
153+
<p><b>4. Logging Preference (remote logging API):</b></p>
154+
155+
<p>JS gives the ability to define log preference for a remote WebDriver session. There are 5 common log types: <i>`BROWSER`, `CLIENT`, `DRIVER`, `PERFORMANCE`, `SERVER`</i>.</p>
156+
157+
<p>To set a log level for a particular log type:</p>
158+
<pre>
159+
let prefs = new logging.Preferences()
160+
prefs.setLevel(logging.Type.BROWSER, logging.Level.FINE)
161+
</pre>
162+
{{< /tab >}}
163+
164+
{{< tab header="Kotlin" >}}
165+
{{< /tab >}}
166+
{{< /tabpane >}}
68167

69-
**DEBUG**
70-
71-
This is less useful information where we log things about the servers and the sockets, and header information, etc.
72-
Debug mode is set if either `$DEBUG` is true or `ENV['DEBUG']` has a value.
73-
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-
### 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-
```
153168

154169
-----
155170

0 commit comments

Comments
 (0)