Skip to content

Commit a2ecc18

Browse files
authored
Adding logging framework to support i18n (#53)
1 parent bc3f6c8 commit a2ecc18

20 files changed

+701
-67
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
**/build
33
*.iml
44
.idea/
5+
!.idea/codeStyles/Project.xml
6+
!.idea/codeStyles/codeStyleConfig.xml
57
**/target
68
**/.DS_Store
79
.flattened-pom.xml

.idea/codeStyles/Project.xml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

imagetool/src/main/bin/logging.properties

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,14 @@ handlers=java.util.logging.ConsoleHandler
1616
#
1717

1818
com.oracle.weblogic.imagetool.level=INFO
19-
#com.oracle.weblogic.imagetool.cli.menu.CreateImage.level = FINEST
20-
#com.oracle.weblogic.imagetool.cli.menu.UpdateImage.level = FINEST
21-
#com.oracle.weblogic.imagetool.cli.menu.ImageOperation.level = FINEST
22-
#com.oracle.weblogic.imagetool.util.ARUUtil.level = FINEST
23-
#com.oracle.weblogic.imagetool.util.XPathUtil.level = FINEST
24-
#com.oracle.weblogic.imagetool.impl.PatchFile.level = FINEST
25-
#com.oracle.weblogic.imagetool.impl.InstallerFile.level = FINEST
26-
#com.oracle.weblogic.imagetool.util.Utils.level = FINEST
2719

2820
#
2921
# Change log file location and handlers logging level as needed. Note the default level for FileHandler is OFF
3022
# and ConsoleHandler is INFO
3123
#
32-
java.util.logging.FileHandler.pattern=tool.log
24+
java.util.logging.FileHandler.pattern=imagetool.log
3325
java.util.logging.FileHandler.count=1
34-
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
35-
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%3$s] [%4$-7s] %5$s %n
36-
java.util.logging.FileHandler.level=OFF
26+
java.util.logging.SimpleFormatter.format=[%4$-7s] %5$s %n
27+
java.util.logging.FileHandler.level=FINEST
3728
java.util.logging.ConsoleHandler.level=INFO
3829

imagetool/src/main/java/com/oracle/weblogic/imagetool/api/model/AbstractFile.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55

66
import java.nio.file.Files;
77
import java.nio.file.Paths;
8-
import java.util.logging.Logger;
98

109
import com.oracle.weblogic.imagetool.api.FileResolver;
1110
import com.oracle.weblogic.imagetool.api.meta.CacheStore;
11+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
12+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
1213

1314
/**
1415
* Base class to represent either an installer or a patch file.
1516
*/
1617
public abstract class AbstractFile implements FileResolver {
1718

18-
private static final Logger logger = Logger.getLogger(AbstractFile.class.getName());
19+
private static final LoggingFacade logger = LoggingFactory.getLogger(AbstractFile.class);
1920

2021
private String key;
2122
protected CachePolicy cachePolicy;

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/CLIDriver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
package com.oracle.weblogic.imagetool.cli;
55

66
import java.util.concurrent.Callable;
7-
import java.util.logging.Logger;
87

98
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
109
import com.oracle.weblogic.imagetool.cli.cache.CacheCLI;
1110
import com.oracle.weblogic.imagetool.cli.menu.CreateImage;
1211
import com.oracle.weblogic.imagetool.cli.menu.UpdateImage;
12+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
13+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
1314
import picocli.CommandLine;
1415
import picocli.CommandLine.Command;
1516
import picocli.CommandLine.HelpCommand;
@@ -33,6 +34,8 @@
3334
)
3435
public class CLIDriver implements Callable<CommandResponse> {
3536

37+
private static final LoggingFacade logger = LoggingFactory.getLogger(CLIDriver.class);
38+
3639
@Override
3740
public CommandResponse call() {
3841
return null;
@@ -43,7 +46,6 @@ public CommandResponse call() {
4346
* @param args command line arguments.
4447
*/
4548
public static void main(String[] args) {
46-
Logger logger = Logger.getLogger(CLIDriver.class.getName());
4749
CLIDriver cliDriver = new CLIDriver();
4850
if (args.length == 0) {
4951
CommandLine.usage(cliDriver, System.out);

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/AddPatchEntry.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33

44
package com.oracle.weblogic.imagetool.cli.cache;
55

6-
import java.io.FileInputStream;
7-
import java.io.IOException;
86
import java.nio.file.Files;
97
import java.nio.file.Path;
108
import java.util.ArrayList;
119
import java.util.List;
12-
import java.util.logging.Logger;
1310

1411
import com.oracle.weblogic.imagetool.api.meta.CacheStore;
15-
import com.oracle.weblogic.imagetool.api.model.AbstractFile;
1612
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
1713
import com.oracle.weblogic.imagetool.api.model.WLSInstallerType;
18-
import com.oracle.weblogic.imagetool.util.ARUUtil;
14+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
15+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
1916
import com.oracle.weblogic.imagetool.util.Constants;
20-
import com.oracle.weblogic.imagetool.util.SearchResult;
2117
import com.oracle.weblogic.imagetool.util.Utils;
22-
import com.oracle.weblogic.imagetool.util.XPathUtil;
23-
import org.apache.commons.codec.digest.DigestUtils;
24-
import org.w3c.dom.Document;
2518
import picocli.CommandLine.Command;
2619
import picocli.CommandLine.Option;
2720

@@ -32,7 +25,7 @@
3225
)
3326
public class AddPatchEntry extends CacheOperation {
3427

35-
private final Logger logger = Logger.getLogger(AddPatchEntry.class.getName());
28+
private static final LoggingFacade logger = LoggingFactory.getLogger(AddPatchEntry.class);
3629

3730
public AddPatchEntry() {
3831
}

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CreateImage.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import java.util.Properties;
1919
import java.util.Set;
2020
import java.util.logging.Level;
21-
import java.util.logging.Logger;
2221
import java.util.stream.Collectors;
2322

2423
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
2524
import com.oracle.weblogic.imagetool.api.model.DomainType;
2625
import com.oracle.weblogic.imagetool.api.model.InstallerType;
2726
import com.oracle.weblogic.imagetool.api.model.WLSInstallerType;
2827
import com.oracle.weblogic.imagetool.impl.InstallerFile;
28+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
29+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2930
import com.oracle.weblogic.imagetool.util.ARUUtil;
3031
import com.oracle.weblogic.imagetool.util.Constants;
3132
import com.oracle.weblogic.imagetool.util.HttpUtil;
@@ -42,7 +43,7 @@
4243
)
4344
public class CreateImage extends ImageOperation {
4445

45-
private final Logger logger = Logger.getLogger(CreateImage.class.getName());
46+
private static final LoggingFacade logger = LoggingFactory.getLogger(CreateImage.class);
4647

4748
public CreateImage() {
4849
super();
@@ -54,7 +55,7 @@ public CreateImage(boolean isCLIMode) {
5455

5556
@Override
5657
public CommandResponse call() throws Exception {
57-
logger.finer("Entering CreateImage call ");
58+
logger.entering();
5859
Instant startTime = Instant.now();
5960

6061
String tmpDir = null;
@@ -69,15 +70,12 @@ public CommandResponse call() throws Exception {
6970
List<String> cmdBuilder = getInitialBuildCmd();
7071
tmpDir = getTempDirectory();
7172

72-
// this handles wls, jdk and wdt install files.
73-
cmdBuilder.addAll(handleInstallerFiles(tmpDir));
74-
7573
if (!Utils.validatePatchIds(patches, false)) {
7674
return new CommandResponse(-1, "Patch ID validation failed");
7775
}
7876

7977
if (fromImage != null && !fromImage.isEmpty()) {
80-
logger.finer("User specified fromImage " + fromImage);
78+
logger.finer("IMG-0002", fromImage);
8179
dockerfileOptions.setBaseImage(fromImage);
8280

8381
Utils.copyResourceAsFile("/probe-env/test-create-env.sh",
@@ -95,7 +93,7 @@ public CommandResponse call() throws Exception {
9593
String existingJavaHome = baseImageProperties.getProperty("JAVA_HOME", null);
9694
if (existingJavaHome != null) {
9795
dockerfileOptions.disableJavaInstall(existingJavaHome);
98-
logger.info("JAVA_HOME detected in base image, skipping JDK install: " + existingJavaHome);
96+
logger.info("IMG-0000", existingJavaHome);
9997
}
10098

10199
if (ohAlreadyExists) {
@@ -111,6 +109,9 @@ public CommandResponse call() throws Exception {
111109
dockerfileOptions.setPackageInstaller(Constants.YUM);
112110
}
113111

112+
// this handles wls, jdk and wdt install files.
113+
cmdBuilder.addAll(handleInstallerFiles(tmpDir));
114+
114115
// build wdt args if user passes --wdtModelPath
115116
cmdBuilder.addAll(handleWdtArgsIfRequired(tmpDir));
116117

@@ -136,7 +137,7 @@ public CommandResponse call() throws Exception {
136137
}
137138
}
138139
Instant endTime = Instant.now();
139-
logger.finer("Exiting CreateImage call ");
140+
logger.exiting();
140141
return new CommandResponse(0, "build successful in "
141142
+ Duration.between(startTime, endTime).getSeconds() + "s. image tag: " + imageTag);
142143
}
@@ -151,12 +152,12 @@ public CommandResponse call() throws Exception {
151152
*/
152153
private List<String> handleInstallerFiles(String tmpDir) throws Exception {
153154

154-
logger.finer("Entering CreateImage.handleInstallerFiles: " + tmpDir);
155+
logger.entering(tmpDir);
155156
List<String> retVal = new LinkedList<>();
156157
List<InstallerFile> requiredInstallers = gatherRequiredInstallers();
157158
for (InstallerFile installerFile : requiredInstallers) {
158159
String targetFilePath = installerFile.resolve(cacheStore);
159-
logger.finer("CreateImage.handleInstallerFiles copying targetFilePath: " + targetFilePath);
160+
logger.finer("copying targetFilePath: {0}", targetFilePath);
160161
String filename = new File(targetFilePath).getName();
161162
try {
162163
Files.copy(Paths.get(targetFilePath), Paths.get(tmpDir, filename));
@@ -165,7 +166,7 @@ private List<String> handleInstallerFiles(String tmpDir) throws Exception {
165166
ee.printStackTrace();
166167
}
167168
}
168-
logger.finer("Exiting CreateImage.handleInstallerFiles: ");
169+
logger.exiting(retVal);
169170
return retVal;
170171
}
171172

@@ -302,19 +303,22 @@ private List<String> getWdtRequiredBuildArgs(Path wdtVariablesPath) throws IOExc
302303
* @throws Exception in case of error
303304
*/
304305
private List<InstallerFile> gatherRequiredInstallers() throws Exception {
305-
logger.finer("Entering CreateImage.gatherRequiredInstallers: ");
306+
logger.entering();
306307
List<InstallerFile> retVal = new LinkedList<>();
307308
if (wdtModelPath != null) {
309+
logger.finer("IMG-0001", InstallerType.WDT, wdtVersion);
308310
InstallerFile wdtInstaller = new InstallerFile(useCache, InstallerType.WDT, wdtVersion, null, null);
309311
retVal.add(wdtInstaller);
310312
addWdtUrl(wdtInstaller.getKey());
311313
}
314+
logger.finer("IMG-0001", installerType, installerVersion);
312315
retVal.add(new InstallerFile(useCache, InstallerType.fromValue(installerType.toString()), installerVersion,
313316
userId, password));
314-
retVal.add(new InstallerFile(useCache, InstallerType.JDK, jdkVersion, userId, password));
315-
logger.finer("Exiting CreateImage.gatherRequiredInstallers: "
316-
+ installerType.toString() + ":" + installerVersion + ", "
317-
+ InstallerType.JDK + ":" + jdkVersion);
317+
if (dockerfileOptions.installJava()) {
318+
logger.finer("IMG-0001", InstallerType.JDK, jdkVersion);
319+
retVal.add(new InstallerFile(useCache, InstallerType.JDK, jdkVersion, userId, password));
320+
}
321+
logger.exiting(retVal.size());
318322
return retVal;
319323
}
320324

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/ImageOperation.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.LinkedList;
1414
import java.util.List;
1515
import java.util.concurrent.Callable;
16-
import java.util.logging.Logger;
1716
import java.util.regex.Matcher;
1817
import java.util.regex.Pattern;
1918
import java.util.stream.Collectors;
@@ -26,6 +25,8 @@
2625
import com.oracle.weblogic.imagetool.api.model.WLSInstallerType;
2726
import com.oracle.weblogic.imagetool.impl.PatchFile;
2827
import com.oracle.weblogic.imagetool.impl.meta.CacheStoreFactory;
28+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
29+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2930
import com.oracle.weblogic.imagetool.util.ARUUtil;
3031
import com.oracle.weblogic.imagetool.util.Constants;
3132
import com.oracle.weblogic.imagetool.util.DockerfileOptions;
@@ -35,7 +36,7 @@
3536

3637
public abstract class ImageOperation implements Callable<CommandResponse> {
3738

38-
private final Logger logger = Logger.getLogger(ImageOperation.class.getName());
39+
private static final LoggingFacade logger = LoggingFactory.getLogger(ImageOperation.class);
3940
// DockerfileOptions provides switches and values to the customize the Dockerfile template
4041
protected DockerfileOptions dockerfileOptions;
4142
protected CacheStore cacheStore = new CacheStoreFactory().get();
@@ -91,7 +92,7 @@ private String handlePasswordOptions() throws IOException {
9192
* @throws Exception in case of error
9293
*/
9394
List<String> handlePatchFiles(String tmpDir, Path tmpPatchesDir) throws Exception {
94-
logger.finer("Entering ImageOperation.handlePatchFiles");
95+
logger.entering();
9596
List<String> retVal = new LinkedList<>();
9697
List<String> patchLocations = new LinkedList<>();
9798
String toPatchesPath = tmpPatchesDir.toAbsolutePath().toString();
@@ -134,7 +135,7 @@ List<String> handlePatchFiles(String tmpDir, Path tmpPatchesDir) throws Exceptio
134135
retVal.add("PATCHDIR=" + Paths.get(tmpDir).relativize(tmpPatchesDir).toString());
135136
dockerfileOptions.setPatchingEnabled();
136137
}
137-
logger.finer("Exiting ImageOperation.handlePatchFiles");
138+
logger.exiting(retVal.size());
138139
return retVal;
139140
}
140141

@@ -178,7 +179,7 @@ public String getTempDirectory() throws IOException {
178179
Path tmpDir = Files.createTempDirectory(Paths.get(Utils.getBuildWorkingDir()), "wlsimgbuilder_temp",
179180
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-xr-x")));
180181
String pathAsString = tmpDir.toAbsolutePath().toString();
181-
logger.info("tmp directory used for docker build context: " + pathAsString);
182+
logger.info("IMG-0003", pathAsString);
182183
return pathAsString;
183184
}
184185

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
import java.util.List;
1515
import java.util.Properties;
1616
import java.util.Set;
17-
import java.util.logging.Logger;
1817

1918
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
2019
import com.oracle.weblogic.imagetool.api.model.WLSInstallerType;
20+
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
21+
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
2122
import com.oracle.weblogic.imagetool.util.ARUUtil;
2223
import com.oracle.weblogic.imagetool.util.Constants;
2324
import com.oracle.weblogic.imagetool.util.Utils;
@@ -33,7 +34,7 @@
3334
)
3435
public class UpdateImage extends ImageOperation {
3536

36-
private final Logger logger = Logger.getLogger(UpdateImage.class.getName());
37+
private static final LoggingFacade logger = LoggingFactory.getLogger(UpdateImage.class);
3738

3839
public UpdateImage() {
3940
super();

0 commit comments

Comments
 (0)