|
1
|
# Deployment Logs Reference |
|
2
|
|
|
3
|
Fetch and analyze deployment logs to debug runtime issues and monitor your deployed application. |
|
4
|
|
|
5
|
## When to Read This Reference |
|
6
|
|
|
7
|
Read this when: |
|
8
|
|
|
9
|
- The user reports that their deployed application is not working correctly |
|
10
|
- The user wants to see what errors are occurring in production |
|
11
|
- The user needs to debug a runtime issue after deployment |
|
12
|
- The user asks to check deployment or server logs |
|
13
|
- The user wants to monitor application behavior after deployment |
|
14
|
|
|
15
|
## How to Use |
|
16
|
|
|
17
|
In the JavaScript notebook, call the `fetchDeploymentLogs` function: |
|
18
|
|
|
19
|
```javascript |
|
20
|
const result = await fetchDeploymentLogs({ |
|
21
|
afterTimestamp: (Date.now() - 3600 * 1000), // Last hour |
|
22
|
message: "ERROR" |
|
23
|
}); |
|
24
|
if (result.found) { |
|
25
|
console.log(result.logs); |
|
26
|
} else { |
|
27
|
console.log("No deployment logs found."); |
|
28
|
} |
|
29
|
``` |
|
30
|
|
|
31
|
## Parameters |
|
32
|
|
|
33
|
- `afterTimestamp` (float, optional): Only include logs after this Unix timestamp (milliseconds) |
|
34
|
- `beforeTimestamp` (float, optional): Only include logs before this Unix timestamp (milliseconds) |
|
35
|
- `message` (str, optional): RE2 regular expression to filter logs by message content |
|
36
|
- `messageContext` (dict, optional): Context configuration for regex matches with: |
|
37
|
- `lines` (int, required): Number of lines before/after each match (0-100) |
|
38
|
- `limit` (int, required): Max matches to fetch context for (1-10) |
|
39
|
|
|
40
|
## Return Value |
|
41
|
|
|
42
|
Returns a dictionary with: |
|
43
|
|
|
44
|
- `logs`: String containing the formatted deployment logs (empty string if none found) |
|
45
|
- `found`: Boolean indicating whether any logs were found |
|
46
|
- `message`: Optional message when no logs are found |
|
47
|
|
|
48
|
## Best Practices |
|
49
|
|
|
50
|
1. **Start broad, then filter**: First fetch logs without filters to understand what's available, then use `message` regex to narrow down |
|
51
|
2. **Use timestamps for recent issues**: If the user reports a recent issue, use `afterTimestamp` to focus on recent logs |
|
52
|
3. **Filter by log level**: Use message regex like `"ERROR"` or `"WARN"` to find problematic entries |
|
53
|
4. **Look for patterns**: Search for specific error messages, stack traces, or module names |
|
54
|
5. **Use context for debugging**: When investigating specific errors, use `messageContext` to see surrounding log lines (similar to `rg -C`) |
|
55
|
|
|
56
|
## Examples |
|
57
|
|
|
58
|
### Fetch All Recent Logs |
|
59
|
|
|
60
|
```javascript |
|
61
|
const result = await fetchDeploymentLogs(); |
|
62
|
console.log(result.logs); |
|
63
|
``` |
|
64
|
|
|
65
|
### Fetch Logs from Last Hour |
|
66
|
|
|
67
|
```javascript |
|
68
|
const oneHourAgo = Date.now() - 3600 * 1000; // Convert to milliseconds |
|
69
|
const result = await fetchDeploymentLogs({ afterTimestamp: oneHourAgo }); |
|
70
|
if (result.found) { |
|
71
|
console.log(result.logs); |
|
72
|
} |
|
73
|
``` |
|
74
|
|
|
75
|
### Find Error Logs |
|
76
|
|
|
77
|
```javascript |
|
78
|
const result = await fetchDeploymentLogs({ message: "ERROR" }); |
|
79
|
if (result.found) { |
|
80
|
console.log(result.logs); |
|
81
|
} else { |
|
82
|
console.log("No error logs found"); |
|
83
|
} |
|
84
|
``` |
|
85
|
|
|
86
|
### Find Database-Related Errors |
|
87
|
|
|
88
|
```javascript |
|
89
|
const result = await fetchDeploymentLogs({ |
|
90
|
message: "(?i)(database|postgres|mysql|mongo|connection.*refused)" |
|
91
|
}); |
|
92
|
console.log(result.logs); |
|
93
|
``` |
|
94
|
|
|
95
|
### Find Startup Failures |
|
96
|
|
|
97
|
```javascript |
|
98
|
const result = await fetchDeploymentLogs({ |
|
99
|
message: "(?i)(failed|crash|exception|traceback)" |
|
100
|
}); |
|
101
|
console.log(result.logs); |
|
102
|
``` |
|
103
|
|
|
104
|
### Find Errors with Context Lines |
|
105
|
|
|
106
|
```javascript |
|
107
|
// Get 10 lines of context before/after each error (up to 3 matches) |
|
108
|
const result = await fetchDeploymentLogs({ |
|
109
|
message: "ERROR", |
|
110
|
messageContext: { lines: 10, limit: 3 } |
|
111
|
}); |
|
112
|
if (result.found) { |
|
113
|
console.log(result.logs); |
|
114
|
} |
|
115
|
``` |
|
116
|
|
|
117
|
### Combined Time and Pattern Filter |
|
118
|
|
|
119
|
```javascript |
|
120
|
// Get logs from the last 30 minutes containing errors |
|
121
|
const thirtyMinAgo = Date.now() - 1800 * 1000; |
|
122
|
const result = await fetchDeploymentLogs({ |
|
123
|
afterTimestamp: thirtyMinAgo, |
|
124
|
message: "(?i)(error|exception|failed)" |
|
125
|
}); |
|
126
|
if (result.found) { |
|
127
|
console.log(result.logs); |
|
128
|
} else { |
|
129
|
console.log("No matching logs in the last 30 minutes"); |
|
130
|
} |
|
131
|
``` |
|
132
|
|
|
133
|
## Common Log Patterns to Search For |
|
134
|
|
|
135
|
- **Any errors**: `"ERROR"` |
|
136
|
- **Warnings and errors**: `"(WARN|ERROR)"` |
|
137
|
- **Database issues**: `"(?i)database|postgres|mysql|connection"` |
|
138
|
- **Network errors**: `"(?i)timeout|refused|unreachable"` |
|
139
|
- **Authentication**: `"(?i)auth|token|unauthorized|forbidden"` |
|
140
|
- **Memory issues**: `"(?i)memory|heap|oom|killed"` |
|
141
|
- **Import/module errors**: `"(?i)import|module|cannot find"` |
|
142
|
|
|
143
|
## Troubleshooting Tips |
|
144
|
|
|
145
|
1. **No logs returned**: The deployment may not have run recently, or there may be no logs matching your filter |
|
146
|
2. **Too many logs**: Use the `message` parameter to filter, or narrow the time range |
|
147
|
3. **Looking for specific errors**: Use case-insensitive regex with `(?i)` prefix |