You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: projects/vdk-plugins/vdk-structlog/README.md
+141-25
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,9 @@ This plugin allows users to:
7
7
- select the log output format
8
8
- configure the logging metadata
9
9
- display metadata added by bound loggers
10
+
- emit logs to syslog
11
+
12
+
For a more in-depth technical analysis, check out [VEP-2448](https://github.com/vmware/versatile-data-kit/blob/main/specs/vep-2448-vdk-run-logs-simplified-and-readable/README.md)
10
13
11
14
## Usage
12
15
@@ -16,28 +19,36 @@ pip install vdk-structlog
16
19
17
20
### Configuration
18
21
19
-
(`vdk config-help` is useful command to browse all config options of your installation of vdk)
22
+
(`vdk config-help` is a useful command to browse all config options of your installation of vdk)
20
23
21
-
| Name | Description | Example Value | Possible Values |
| logging_metadata | Configure the metadata that will be output along with the log message | "timestamp, level, logger_name, file_name, vdk_job_name | "timestamp, level, logger_name, file_name, line_number, function_name, vdk_job_name, vdk_step_name, vdk_step_type" |
24
-
| logging_format | Configure the logging output format. Available formats: json, console | "console" | "console", "json" |
25
-
| custom_console_log_pattern | Custom format string for console logging, applied only when`logging_format` is 'console' and overrides `logging_metadata`| "%(asctime)s %(name)-12s %(levelname)-8s %(message)s" | Any valid Python logging format string |
26
-
| log_level_module | Configure the log level of different Python modules separately | "a.b.c=INFO;foo.bar=ERROR" | Semicolon-separated list of pairs of Python module paths and log level labels |
24
+
| Name | Description | Example Value | Possible Values |
| logging_metadata | Configure the metadata that will be output along with the log message | "timestamp, level, logger_name, file_name, vdk_job_name | Any combination of the following: "timestamp, level, logger_name, file_name, line_number, function_name, vdk_job_name, vdk_step_name, vdk_step_type". Can be expanded by extra params and bound key-value pairs. See the bound logger examples for more information |
27
+
| logging_format | Configure the logging output format. Available formats: json, console | "console" | "console", "json", "ltsv" |
28
+
| custom_console_log_pattern | Custom format string for console logging, applied only when`logging_format` is 'console'. Overrides `logging_metadata`. | "%(asctime)s %(name)-12s %(levelname)-8s %(message)s" | Any valid Python logging format string |
29
+
| log_level_module | Configure the log level of different Python modules separately | "a.b.c=INFO;foo.bar=ERROR" | Semicolon-separated list of pairs of Python module paths and log level labels |
30
+
| syslog_host | Syslog host to which logs are emitted | "syslog.vmware.com" | Any valid host name |
31
+
| syslog_port | Syslog port used to emit logs | 514 | Any valid port number |
32
+
| syslog_protocol | Protocol used to emit logs | "UDP" | "TCP", "UDP" |
If you wish to apply a specific format to your console logs, you can define a custom format using the `custom_console_log_pattern` configuration. This custom format string will be used only when the `logging_format` is set to 'console'.
37
+
If you wish to apply a specific format to your console logs, you can define a
38
+
custom format using the `custom_console_log_pattern` configuration. This custom
39
+
format string will be used only when the `logging_format` is set to 'console'.
31
40
32
41
For example, add the following to your data job configuration:
When you run your data job, regardless of other logging settings, your logs will strictly follow this custom format, displaying the timestamp, logger's name, log level, and the log message as per the format string specified.
47
+
When you run your data job, regardless of other logging settings, your logs will
48
+
strictly follow this custom format, displaying the timestamp, logger's name, log
49
+
level, and the log message as per the format string specified.
2024-01-16 10:16:53,237 [VDK] [INFO ] step_20_python_ste 20_python_step.py :22 run 78118954-fe0c-451d-80cf-9b9bc80b8140 - This is an info log statement with extra stuff
162
+
```
163
+
164
+
This is fine, however, if we want to have the same uuid with multiple log
165
+
statements, it's not very convenient to pass it every time. `vdk` offers a
166
+
function to solve this problem.
167
+
168
+
```python
169
+
import logging
170
+
import uuid
171
+
from vdk.internal.core.logging import bind_logger
172
+
173
+
log = logging.getLogger(__name__)
174
+
175
+
log.info(f"Starting job step {__name__}")
176
+
177
+
myid = uuid.uuid4()
178
+
bound_log = bind_logger(log, {"uuid": myid})
179
+
bound_log.info("This is an info log statement with extra stuff")
180
+
bound_log.info("This is another log statement with uuid")
2024-01-16 10:31:04,761 [VDK] [INFO ] step_20_python_ste 20_python_step.py :25 run ed1e447d-3746-4068-8a83-353176327985 - This is an info log statement with extra stuff
194
+
2024-01-16 10:31:04,761 [VDK] [INFO ] step_20_python_ste 20_python_step.py :26 run ed1e447d-3746-4068-8a83-353176327985 - This is another log statement with uuid
195
+
```
196
+
197
+
Bound loggers act the same as regular loggers. You can even pass extra params to
198
+
them, or bind additional context.
199
+
200
+
```python
201
+
import logging
202
+
import uuid
203
+
from vdk.internal.core.logging import bind_logger
204
+
205
+
log = logging.getLogger(__name__)
206
+
207
+
log.info(f"Starting job step {__name__}")
127
208
128
-
### Example: Passing custom metadata fields with extra_params
209
+
myid = uuid.uuid4()
210
+
bound_log = bind_logger(log, {"uuid": myid})
211
+
bound_log.info("This is an info log statement with extra stuff")
212
+
bound_log.info("This is another log statement with uuid")
.plugin-ci.yaml is needed only for plugins part of [Versatile Data Kit Plugin repo](https://github.com/vmware/versatile-data-kit/tree/main/projects/vdk-plugins).
146
261
147
-
The CI/CD is separated in two stages, a build stage and a release stage.
148
-
The build stage is made up of a few jobs, all which inherit from the same
149
-
job configuration and only differ in the Python version they use (3.7, 3.8, 3.9 and 3.10).
150
-
They run according to rules, which are ordered in a way such that changes to a
151
-
plugin's directory trigger the plugin CI, but changes to a different plugin does not.
262
+
The CI/CD is separated in two stages, a build stage and a release stage. The
263
+
build stage is made up of a few jobs, all which inherit from the same job
264
+
configuration and only differ in the Python version they use (3.7, 3.8, 3.9 and
265
+
3.10). They run according to rules, which are ordered in a way such that changes
266
+
to a plugin's directory trigger the plugin CI, but changes to a different plugin
0 commit comments