or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

events.mdindex.mdjavascript.mdlogging.mdnetwork.mdtargets.md

logging.mddocs/

0

# Log Management

1

2

The v133Log class provides comprehensive browser log monitoring and management capabilities, enabling developers to capture, filter, and process browser logs in real-time.

3

4

## Capabilities

5

6

### v133Log Class

7

8

Main log management class that implements the idealized Log interface with v133-specific implementations.

9

10

```java { .api }

11

/**

12

* v133-specific log management implementation

13

* Implements org.openqa.selenium.devtools.idealized.log.Log for browser log operations

14

*/

15

public class v133Log implements org.openqa.selenium.devtools.idealized.log.Log {

16

/**

17

* Creates a new v133Log instance

18

* Uses default constructor - no parameters required as operations are static

19

*/

20

}

21

```

22

23

### Log Domain Control

24

25

Methods for enabling and controlling browser log collection.

26

27

```java { .api }

28

/**

29

* Enable log domain to start collecting browser logs

30

* @return Command to enable log collection

31

*/

32

public Command<Void> enable();

33

34

/**

35

* Clear all existing browser logs

36

* @return Command to clear browser logs

37

*/

38

public Command<Void> clear();

39

```

40

41

**Usage Example:**

42

43

```java

44

import org.openqa.selenium.devtools.v133.v133Log;

45

46

v133Log log = new v133Log();

47

48

// Enable log collection

49

devTools.send(log.enable());

50

51

// Clear existing logs

52

devTools.send(log.clear());

53

```

54

55

### Log Event Monitoring

56

57

Monitor browser log entries as they are created in real-time.

58

59

```java { .api }

60

/**

61

* Get the log entry added event for monitoring new log entries

62

* @return Event for monitoring browser log entries

63

*/

64

public Event<org.openqa.selenium.devtools.idealized.log.model.LogEntry> entryAdded();

65

```

66

67

**Usage Example:**

68

69

```java

70

import org.openqa.selenium.devtools.idealized.log.model.LogEntry;

71

import java.util.logging.Level;

72

73

// Listen for log entries

74

devTools.addListener(log.entryAdded(), (LogEntry entry) -> {

75

System.out.printf("[%s] %s: %s%n",

76

entry.getSource(),

77

entry.getLogEntry().getLevel(),

78

entry.getLogEntry().getMessage()

79

);

80

});

81

82

// Now browse to pages and logs will be captured automatically

83

driver.get("https://example.com");

84

```

85

86

### Log Level Conversion

87

88

Internal methods for converting CDP log levels to Java logging levels.

89

90

```java { .api }

91

/**

92

* Convert CDP log level to Java logging Level

93

* @param level CDP LogEntry.Level

94

* @return Java logging Level equivalent

95

*/

96

private Level fromCdpLevel(LogEntry.Level level);

97

98

/**

99

* Convert CDP timestamp to Java long timestamp

100

* @param timestamp CDP Timestamp

101

* @return Java long timestamp in milliseconds

102

*/

103

private long fromCdpTimestamp(Timestamp timestamp);

104

```

105

106

## Log Data Types

107

108

### LogEntry (CDP)

109

110

Raw CDP log entry from the browser log domain.

111

112

```java { .api }

113

// From org.openqa.selenium.devtools.v133.log.model.LogEntry

114

public class LogEntry {

115

public String getSource(); // Source of the log entry (javascript, network, etc.)

116

public Level getLevel(); // Log level (verbose, info, warning, error)

117

public String getText(); // Log message text

118

public Timestamp getTimestamp(); // When the log entry was created

119

}

120

121

// Log levels from CDP

122

public enum Level {

123

VERBOSE, // Detailed debugging information

124

INFO, // General information

125

WARNING, // Warning messages

126

ERROR // Error messages

127

}

128

```

129

130

### LogEntry (Selenium)

131

132

Processed log entry converted to Selenium's standard format.

133

134

```java { .api }

135

// From org.openqa.selenium.devtools.idealized.log.model.LogEntry

136

public class LogEntry {

137

public LogEntry(String source, org.openqa.selenium.logging.LogEntry logEntry);

138

public String getSource(); // Source of the log entry

139

public org.openqa.selenium.logging.LogEntry getLogEntry(); // Standard Selenium log entry

140

}

141

142

// From org.openqa.selenium.logging.LogEntry

143

public class LogEntry {

144

public LogEntry(Level level, long timestamp, String message);

145

public Level getLevel(); // Java logging level

146

public long getTimestamp(); // Timestamp in milliseconds

147

public String getMessage(); // Log message

148

}

149

```

150

151

## Advanced Log Management Patterns

152

153

### Log Filtering by Level

154

155

Filter logs by severity level to focus on important messages:

156

157

```java

158

import java.util.logging.Level;

159

160

devTools.addListener(log.entryAdded(), (LogEntry entry) -> {

161

Level level = entry.getLogEntry().getLevel();

162

163

// Only process warnings and errors

164

if (level.intValue() >= Level.WARNING.intValue()) {

165

System.err.printf("⚠️ [%s] %s: %s%n",

166

entry.getSource(),

167

level.getName(),

168

entry.getLogEntry().getMessage()

169

);

170

171

// Take action on errors

172

if (level == Level.SEVERE) {

173

handleCriticalError(entry);

174

}

175

}

176

});

177

```

178

179

### Log Filtering by Source

180

181

Filter logs by their source to focus on specific types of browser activity:

182

183

```java

184

devTools.addListener(log.entryAdded(), (LogEntry entry) -> {

185

String source = entry.getSource();

186

String message = entry.getLogEntry().getMessage();

187

188

switch (source) {

189

case "javascript":

190

System.out.println("πŸ”Ά JS: " + message);

191

break;

192

case "network":

193

System.out.println("🌐 NET: " + message);

194

break;

195

case "security":

196

System.out.println("πŸ”’ SEC: " + message);

197

break;

198

case "deprecation":

199

System.out.println("⚠️ DEP: " + message);

200

break;

201

default:

202

System.out.println("πŸ“ " + source.toUpperCase() + ": " + message);

203

}

204

});

205

```

206

207

### Log Aggregation and Analysis

208

209

Collect and analyze logs for patterns:

210

211

```java

212

import java.util.*;

213

import java.util.concurrent.ConcurrentHashMap;

214

215

public class LogAnalyzer {

216

private final Map<String, Integer> errorCounts = new ConcurrentHashMap<>();

217

private final List<LogEntry> criticalErrors = Collections.synchronizedList(new ArrayList<>());

218

219

public void setupLogAnalysis(v133Log log, DevTools devTools) {

220

devTools.addListener(log.entryAdded(), this::analyzeLogEntry);

221

}

222

223

private void analyzeLogEntry(LogEntry entry) {

224

Level level = entry.getLogEntry().getLevel();

225

String message = entry.getLogEntry().getMessage();

226

227

// Count errors by type

228

if (level == Level.SEVERE) {

229

String errorType = extractErrorType(message);

230

errorCounts.merge(errorType, 1, Integer::sum);

231

criticalErrors.add(entry);

232

}

233

234

// Detect patterns

235

if (message.contains("Uncaught")) {

236

System.err.println("🚨 Uncaught JavaScript error detected: " + message);

237

}

238

239

if (message.contains("404") || message.contains("Failed to load")) {

240

System.err.println("πŸ“ Resource loading error: " + message);

241

}

242

}

243

244

private String extractErrorType(String message) {

245

if (message.contains("TypeError")) return "TypeError";

246

if (message.contains("ReferenceError")) return "ReferenceError";

247

if (message.contains("SyntaxError")) return "SyntaxError";

248

if (message.contains("NetworkError")) return "NetworkError";

249

return "Unknown";

250

}

251

252

public void printSummary() {

253

System.out.println("\n=== Log Analysis Summary ===");

254

System.out.println("Error counts by type:");

255

errorCounts.forEach((type, count) ->

256

System.out.printf("%s: %d occurrences%n", type, count));

257

System.out.printf("Total critical errors: %d%n", criticalErrors.size());

258

}

259

}

260

```

261

262

### Log Persistence

263

264

Save logs to files for later analysis:

265

266

```java

267

import java.io.*;

268

import java.time.Instant;

269

import java.time.format.DateTimeFormatter;

270

271

public class LogPersistence {

272

private final PrintWriter logWriter;

273

274

public LogPersistence(String filename) throws IOException {

275

this.logWriter = new PrintWriter(new FileWriter(filename, true));

276

}

277

278

public void setupLogPersistence(v133Log log, DevTools devTools) {

279

devTools.addListener(log.entryAdded(), this::persistLogEntry);

280

}

281

282

private void persistLogEntry(LogEntry entry) {

283

String timestamp = DateTimeFormatter.ISO_INSTANT

284

.format(Instant.ofEpochMilli(entry.getLogEntry().getTimestamp()));

285

286

logWriter.printf("[%s] %s/%s: %s%n",

287

timestamp,

288

entry.getSource(),

289

entry.getLogEntry().getLevel().getName(),

290

entry.getLogEntry().getMessage()

291

);

292

logWriter.flush();

293

}

294

295

public void close() {

296

logWriter.close();

297

}

298

}

299

```

300

301

## Level Mapping

302

303

The v133Log class maps CDP log levels to Java logging levels:

304

305

| CDP Level | Java Level | Description |

306

|-----------|------------|-------------|

307

| `verbose` | `FINEST` | Detailed debugging information |

308

| `info` | `INFO` | General informational messages |

309

| `warning` | `WARNING` | Potential problems or deprecations |

310

| `error` | `SEVERE` | Error conditions and exceptions |

311

312

## Common Log Sources

313

314

Browser logs come from various sources:

315

316

- **`javascript`**: JavaScript runtime errors, console calls, and exceptions

317

- **`network`**: Network request failures, CORS errors, and connectivity issues

318

- **`security`**: Security policy violations and certificate problems

319

- **`deprecation`**: Usage of deprecated APIs and features

320

- **`rendering`**: Layout and rendering warnings

321

- **`storage`**: Local storage, session storage, and database errors

322

323

## Error Handling

324

325

Log management includes error handling for:

326

327

- **Timestamp Parsing**: Falls back to current time if CDP timestamp cannot be parsed

328

- **Level Conversion**: Defaults to INFO level for unknown CDP log levels

329

- **Message Processing**: Handles null or malformed log messages gracefully

330

- **Connection Issues**: Continues operating if log domain connection is interrupted