| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 288a368 commit 65ab6f8
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ | |||
| 33 | 33 | import com.google.cloud.logging.MonitoredResourceUtil; | |
| 34 | 34 | import com.google.cloud.logging.Payload; | |
| 35 | 35 | import com.google.cloud.logging.Severity; | |
| 36 | + import com.google.cloud.logging.Synchronicity; | ||
| 36 | 37 | import com.google.common.base.Strings; | |
| 37 | 38 | import com.google.common.collect.ImmutableList; | |
| 38 | 39 | import java.io.FileInputStream; | |
@@ -63,8 +64,12 @@ | |||
| 63 | 64 | * <!-- Optional: defaults to "ERROR" --> | |
| 64 | 65 | * <flushLevel>WARNING</flushLevel> | |
| 65 | 66 | * | |
| 67 | + * <!-- Optional: defaults to ASYNC --> | ||
| 68 | + * <writeSynchronicity>SYNC</writeSynchronicity> | ||
| 69 | + * | ||
| 66 | 70 | * <!-- Optional: auto detects on App Engine Flex, Standard, GCE and GKE, defaults to "global". See <a | |
| 67 | - * href="https://cloud.google.com/logging/docs/api/v2/resource-list">supported resource types</a> --> | ||
| 71 | + * href= | ||
| 72 | + * "https://cloud.google.com/logging/docs/api/v2/resource-list">supported resource types</a> --> | ||
| 68 | 73 | * <resourceType></resourceType> | |
| 69 | 74 | * | |
| 70 | 75 | * <!-- Optional: defaults to the default credentials of the environment --> | |
@@ -96,6 +101,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | |||
| 96 | 101 | private String log; | |
| 97 | 102 | private String resourceType; | |
| 98 | 103 | private String credentialsFile; | |
| 104 | + private Synchronicity writeSyncFlag = Synchronicity.ASYNC; | ||
| 99 | 105 | private final Set<String> enhancerClassNames = new HashSet<>(); | |
| 100 | 106 | private final Set<String> loggingEventEnhancerClassNames = new HashSet<>(); | |
| 101 | 107 | ||
@@ -122,8 +128,9 @@ public void setLog(String log) { | |||
| 122 | 128 | /** | |
| 123 | 129 | * Sets the name of the monitored resource (Optional). | |
| 124 | 130 | * | |
| 125 | - * <p>Must be a <a href="https://cloud.google.com/logging/docs/api/v2/resource-list">supported</a> | ||
| 126 | - * resource type. gae_app, gce_instance and container are auto-detected. | ||
| 131 | + * <p>Must be a <a href= | ||
| 132 | + * "https://cloud.google.com/logging/docs/api/v2/resource-list">supported</a> resource type. | ||
| 133 | + * gae_app, gce_instance and container are auto-detected. | ||
| 127 | 134 | * | |
| 128 | 135 | * <p>Defaults to "global" | |
| 129 | 136 | * | |
@@ -144,6 +151,15 @@ public void setCredentialsFile(String credentialsFile) { | |||
| 144 | 151 | this.credentialsFile = credentialsFile; | |
| 145 | 152 | } | |
| 146 | 153 | ||
| 154 | + /** | ||
| 155 | + * Define synchronization mode for writing log entries. | ||
| 156 | + * | ||
| 157 | + * @param flag to set {@code Synchronicity} value. | ||
| 158 | + */ | ||
| 159 | + public void setWriteSynchronicity(Synchronicity flag) { | ||
| 160 | + this.writeSyncFlag = flag; | ||
| 161 | + } | ||
| 162 | + | ||
| 147 | 163 | /** Add extra labels using classes that implement {@link LoggingEnhancer}. */ | |
| 148 | 164 | public void addEnhancer(String enhancerClassName) { | |
| 149 | 165 | this.enhancerClassNames.add(enhancerClassName); | |
@@ -161,6 +177,10 @@ String getLogName() { | |||
| 161 | 177 | return (log != null) ? log : "java.log"; | |
| 162 | 178 | } | |
| 163 | 179 | ||
| 180 | + public Synchronicity getWriteSynchronicity() { | ||
| 181 | + return (this.writeSyncFlag != null) ? this.writeSyncFlag : Synchronicity.ASYNC; | ||
| 182 | + } | ||
| 183 | + | ||
| 164 | 184 | MonitoredResource getMonitoredResource(String projectId) { | |
| 165 | 185 | return MonitoredResourceUtil.getResource(projectId, resourceType); | |
| 166 | 186 | } | |
@@ -253,6 +273,7 @@ Logging getLogging() { | |||
| 253 | 273 | synchronized (this) { | |
| 254 | 274 | if (logging == null) { | |
| 255 | 275 | logging = getLoggingOptions().getService(); | |
| 276 | + logging.setWriteSynchronicity(writeSyncFlag); | ||
| 256 | 277 | } | |
| 257 | 278 | } | |
| 258 | 279 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments