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
Here is an example of how a `StackdriverLogHandler` could be bootstrapped, notice that the `StackdriverLogHandler` initializer will throw if it receives an invalid filepath.
22
+
A factory `StackdriverLogHandlerFactory` is used to instantiate `StackdriverLogHandler` instances. Before bootstrapping your `LoggingSystem`, you must first call the `StackdriverLogHandlerFactory.prepare(:)` function with a `StackdriverLoggingConfiguration` to prepare the factory.
23
+
24
+
Here's an example of how this works:
23
25
24
26
```Swift
25
-
LoggingSystem.bootstrap { label -> LogHandler in
26
-
// ...
27
-
if label =="Stackdriver" {
28
-
do {
29
-
var logHandler =tryStackdriverLogHandler(logFilePath: "/var/log/my_app.log")
30
-
logHandler.logLevel= .error
31
-
return logHandler
32
-
} catch {
33
-
// The logFilePath does not exist or is inacessible, defaulting to a console logger
34
-
print("Failed to create a StackdriverLogHandler with error: '\(error.localizedDescription)'")
## Logging JSON values using `Logger.MetadataValue`
42
36
To log metadata values as JSON, simply log all JSON values other than `String` as a `Logger.MetadataValue.stringConvertible` and, instead of the usual conversion of your value to a `String` in the log entry, it will keep the original JSON type of your values whenever possible.
@@ -87,7 +81,7 @@ Will log the non pretty-printed representation of:
87
81
```
88
82
89
83
## Stackdriver logging agent + fluentd config
90
-
You can use this LogHandler in combination with the Stackdriver logging agent https://cloud.google.com/logging/docs/agent/installation and a matching json format
84
+
You must use this LogHandler in combination with the Stackdriver logging agent https://cloud.google.com/logging/docs/agent/installation and a matching json format
91
85
google-fluentd config (/etc/google-fluentd/config.d/example.conf) to automatically send your JSON logs to Stackdriver.
92
86
93
87
Here's an example google-fluentd conf file that monitors a json based logfile and send new log entries to Stackdriver:
@@ -107,3 +101,6 @@ Here's an example google-fluentd conf file that monitors a json based logfile an
107
101
tag exampletag
108
102
</source>
109
103
```
104
+
105
+
## Future
106
+
A Stackdriver gRPC API based implementation is being considered.
0 commit comments