1
1
# 3.0.0 Migration Guide
2
2
3
+ The v3.0.0 release of ` google-cloud-logging ` is focused on improving usability of the library,
4
+ particularly on newer serverless environments.
5
+
6
+ If you experience issues or have questions, please file an [ issue] ( https://github.com/googleapis/python-logging/issues ) .
7
+
8
+ ## Primary Changes
9
+
10
+ ### Handler deprecations ([ #310 ] ( https://github.com/googleapis/python-logging/pull/310 ) )
11
+
12
+ > ** WARNING** : Breaking change
13
+
14
+ Prior to v3.0.0, there were three ` Handler ` classes used for the Python logging standard library integration:
15
+
16
+ - [ ` AppEngineHandler ` ] ( https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/app_engine.py )
17
+ - [ ` ContainerEngineHandler ` ] ( https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/container_engine.py )
18
+ - [ ` CloudLoggingHandler ` ] ( https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/handlers.py )
19
+
20
+ Google Cloud has grown, and adding a new handler class for each new product does not scale.
21
+ Recently, we have changed to support two more generic ` Handler ` classes instead:
22
+
23
+ - [ ` CloudLoggingHandler ` ] ( https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/handlers.py )
24
+ - sends logs over the network (using gRPC or HTTP API calls)
25
+ - replaces ` AppEngineHandler `
26
+ - [ ` StructuredLogHandler ` ] ( https://github.com/googleapis/python-logging/blob/v2.7.0/google/cloud/logging_v2/handlers/structured_log.py )
27
+ - exports logs in JSON format through standard out, to be parsed by an agent
28
+ - replaces ` ContainerEngineHandler `
29
+
30
+ As of v3.0.0, ` AppEngineHandler ` and ` ContainerEngineHandler ` have been marked as deprecated and will not be updated.
31
+ They may be removed from the library in a future update.
32
+
33
+ ### Metadata autodetection ([ #315 ] ( https://github.com/googleapis/python-logging/pull/315 ) )
34
+
35
+ > ** WARNING** : Breaking change
36
+
37
+ Logs emitted by the library must be associated with a [ montored-resource type] ( https://cloud.google.com/monitoring/api/resources ) ,
38
+ indicating the compute environment the log originated from. Previously, the logs would default to
39
+ [ "global"] ( https://cloud.google.com/monitoring/api/resources#tag_global ) when left unspecified.
40
+ Going forward, the library will attempt to determine the monitored-resource automatically if not explicitly set.
41
+
42
+ ### Full JSON log support in standard library integration ([ #316 ] ( https://github.com/googleapis/python-logging/pull/316 ) , [ #339 ] ( https://github.com/googleapis/python-logging/pull/339 ) , [ #447 ] ( https://github.com/googleapis/python-logging/pull/447 ) )
43
+
44
+ You can now log JSON data using the Python ` logging ` standard library integration.
45
+ The library supports two different methods:
46
+
47
+ 1 . Using the ` json_fields ` ` extra ` argument:
48
+
49
+ ``` py
50
+ import logging
51
+
52
+ data_dict = {" hello" : " world" }
53
+ logging.info(" message field" , extra = {" json_fields" : data_dict})
54
+ ```
55
+
56
+ 2 . Logging a JSON-parsable string:
57
+
58
+ ``` py
59
+ import logging
60
+ import json
61
+
62
+ data_dict = {" hello" : " world" }
63
+ logging.info(json.dumps(data_dict))
64
+ ```
65
+
66
+ ### New ` Logger.log ` method ([ #316 ] ( https://github.com/googleapis/python-logging/pull/316 ) )
67
+
68
+ Previously, the Logger class had four methods for sending logs of different types:
69
+
70
+ ``` py
71
+ logger.log_text(" hello world" )
72
+ logger.log_struct({" hello" : " world" })
73
+ logger.log_proto(proto_message)
74
+ logger.log_empty()
75
+ ```
76
+
77
+ In v3.0.0, the library adds a generic ` log() ` method that will attempt to infer and log any type:
78
+
79
+ ``` py
80
+ logger.log(" hello world" )
81
+ ```
82
+
83
+ ### More permissive arguments ([ #422 ] ( https://github.com/googleapis/python-logging/pull/422 ) )
84
+
85
+ > ** WARNING** : Breaking change
86
+
87
+ In v3.0.0, the library will be more forgiving if inputs are given in a different format than expected
88
+
89
+ ``` py
90
+ # lowercase severity strings will be accepted
91
+ logger.log(" hello world" , severity = " warning" )
92
+ ```
93
+
94
+ ``` py
95
+ # a severity will be pulled out of the JSON payload if not otherwise set
96
+ logger.log({" hello" : " world" , " severity" :" warning" })
97
+ ```
98
+
99
+ ``` py
100
+ # resource data can be passed as a dict instead of a Resource object
101
+ logger.log(" hello world" , resource = {" type" :" global" , " labels" :[]})
102
+ ```
103
+
104
+ ### Improved support for non-project resources ([ #444 ] ( https://github.com/googleapis/python-logging/pull/444 ) )
105
+
106
+ There was a crashing bug when attempting to read back logs from non-project resources:
107
+
108
+ - ` organizations/[ORGANIZATION_ID]/logs/[LOG_ID] `
109
+ - ` billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID] `
110
+ - ` folders/[FOLDER_ID]/logs/[LOG_ID] `
111
+
112
+ The v3.0.0 update fixes this issue.
113
+
114
+ ### Internal Gapic and HTTP implementation changes ([ #375 ] ( https://github.com/googleapis/python-logging/pull/375 ) )
115
+
116
+ > ** WARNING** : Breaking change
117
+
118
+ The library supports sending logs using two different network protocols: gRPC and HTTP. Previously, there was an \
119
+ inconsistency in the implementations, resulting in unexpected behaviour when in HTTP mode.
120
+
121
+ As part of these changes, we introduced a new ` max_size ` argument to ` list_entries ` calls, which can be used to determine
122
+ how many results should be returned:
123
+
124
+ ``` py
125
+ from google.cloud import logging_v2
126
+
127
+ client = logging_v2.Client()
128
+ client.list_entries(max_size = 5 )
129
+ ```
130
+
131
+
132
+ ---
3
133
4
134
# 2.0.0 Migration Guide
5
135
@@ -337,4 +467,4 @@ The following resource name helpers have been renamed.
337
467
338
468
** ` ConfigServiceV2Client ` **
339
469
* ` sink_path ` -> ` log_sink_path `
340
- * ` exclusion_path ` -> ` log_exclusion_path `
470
+ * ` exclusion_path ` -> ` log_exclusion_path `
0 commit comments