forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogConfig.java
More file actions
118 lines (97 loc) · 3.68 KB
/
Copy pathLogConfig.java
File metadata and controls
118 lines (97 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.github.dockerjava.api.model;
import java.io.IOException;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
/**
* Log driver to use for a created/running container. The available types are:
*
* json-file (default) syslog journald none
*
* If a driver is specified that is NOT supported,docker will default to null. If configs are supplied that are not supported by the type
* docker will ignore them. In most cases setting the config option to null will suffice. Consult the docker remote API for a more detailed
* and up-to-date explanation of the available types and their options.
*/
public class LogConfig {
@JsonProperty("Type")
public LoggingType type = null;
@JsonProperty("Config")
public Map<String, String> config;
public LogConfig(LoggingType type, Map<String, String> config) {
this.type = type;
this.config = config;
}
public LogConfig(LoggingType type) {
this(type, null);
}
public LogConfig() {
}
public LoggingType getType() {
return type;
}
public LogConfig setType(LoggingType type) {
this.type = type;
return this;
}
@JsonIgnore
public Map<String, String> getConfig() {
return config;
}
@JsonIgnore
public LogConfig setConfig(Map<String, String> config) {
this.config = config;
return this;
}
@JsonDeserialize(using = LoggingType.Deserializer.class)
@JsonSerialize(using = LoggingType.Serializer.class)
public enum LoggingType {
DEFAULT("json-file"),
JSON_FILE("json-file"),
NONE("none"),
SYSLOG("syslog"),
JOURNALD("journald"),
GELF("gelf"),
FLUENTD("fluentd"),
AWSLOGS("awslogs"),
SPLUNK("splunk");
private String type;
LoggingType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public static final class Serializer extends JsonSerializer<LoggingType> {
@Override
public void serialize(LoggingType value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeString(value.getType());
}
}
public static final class Deserializer extends JsonDeserializer<LoggingType> {
@Override
public LoggingType deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
for (LoggingType loggingType : values()) {
if (loggingType.getType().equals(node.asText())) {
return loggingType;
}
}
throw new IllegalArgumentException("No enum constant " + LoggingType.class + "." + node.asText());
}
}
}
}