| 22 | import java.util.List; |
| 23 | |
| 24 | public class InitLogging implements InitStep { |
| 25 | private static final String CONTAINER = "container"; |
| 26 | private static final String JAVA_OPTIONS = "javaOptions"; |
| 27 | private static final String FLOGGER_BACKEND_PROPERTY = "flogger.backend_factory"; |
| 28 | private static final String FLOGGER_LOGGING_CONTEXT = "flogger.logging_context"; |
| 29 | |
| 30 | private final Section container; |
| 31 | |
| 32 | @Inject |
| 33 | public InitLogging(Section.Factory sections) { |
| 34 | this.container = sections.get(CONTAINER, null); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void run() throws Exception { |
| 39 | List<String> javaOptions = new ArrayList<>(Arrays.asList(container.getList(JAVA_OPTIONS))); |
| 40 | if (!isSet(javaOptions, FLOGGER_BACKEND_PROPERTY)) { |
| 41 | javaOptions.add( |
| 42 | getJavaOption( |
| 43 | FLOGGER_BACKEND_PROPERTY, |
| 44 | "com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance")); |
| 45 | } |
| 46 | if (!isSet(javaOptions, FLOGGER_LOGGING_CONTEXT)) { |
| 47 | javaOptions.add( |
| 48 | getJavaOption( |
| 49 | FLOGGER_LOGGING_CONTEXT, |
| 50 | "com.google.gerrit.server.logging.LoggingContext#getInstance")); |
| 51 | } |
| 52 | container.setList(JAVA_OPTIONS, javaOptions); |
| 53 | } |
| 54 | |
| 55 | private static boolean isSet(List<String> javaOptions, String javaOptionName) { |
| 56 | return javaOptions.stream() |
| 57 | .anyMatch( |
| 58 | o -> |
| 59 | o.startsWith("-D" + javaOptionName + "=") |
| 60 | || o.startsWith("\"-D" + javaOptionName + "=")); |
| 61 | } |
| 62 | |
| 63 | private static String getJavaOption(String javaOptionName, String value) { |
| 64 | return String.format("-D%s=%s", javaOptionName, value); |
| 65 | } |
| 66 | } |
nothing calls this directly
no outgoing calls
no test coverage detected