SammyVimes commented on code in PR #1105:
URL: https://github.com/apache/ignite-3/pull/1105#discussion_r976268977
##########
modules/cli/src/main/java/org/apache/ignite/cli/Main.java:
##########
@@ -155,20 +157,40 @@ private static String banner(VersionProvider
versionProvider) {
private static void initJavaLoggerProps() {
InputStream propsFile =
Main.class.getResourceAsStream("/cli.java.util.logging.properties");
- Path props = null;
-
- try {
- props = Files.createTempFile("cli.java.util.logging.properties",
"");
-
- if (propsFile != null) {
- Files.copy(propsFile, props.toAbsolutePath(),
StandardCopyOption.REPLACE_EXISTING);
+ if (propsFile != null) {
+ try {
+ LogManager.getLogManager().updateConfiguration(propsFile, s ->
{
+ // Merge default configuration with configuration read
from propsFile
+ // and append the path to logs to the file pattern if
propsFile have the corresponding key
+ if (s.equals("java.util.logging.FileHandler.pattern")) {
+ return (o, n) -> {
+ if (n == null) {
+ return o;
+ }
+ try {
+ return getLogsDir() + "/" + n;
+ } catch (IOException e) {
+ return n;
+ }
+ };
+ }
+ return (o, n) -> n == null ? o : n;
+ });
+ } catch (IOException ignored) {
+ // No-op.
}
- } catch (IOException ignored) {
- // No-op.
}
+ }
- if (props != null) {
- System.setProperty("java.util.logging.config.file",
props.toString());
+ private static String getLogsDir() throws IOException {
+ String envLogsDir = System.getenv(IGNITE_CLI_LOGS_DIR);
+ String logsDir = envLogsDir != null ? envLogsDir :
StateFolderProvider.getStateFile("logs").getAbsolutePath();
+ File logsDirFile = new File(logsDir);
+ logsDirFile.mkdirs();
+ if (logsDirFile.isDirectory()) {
+ return logsDir;
+ } else {
+ throw new IOException(logsDir + " is not a directory");
Review Comment:
```suggestion
File logsDirFile = new File(logsDir);
if (!logsDirFile.exists()) {
if (!logsDirFile.mkdirs()) {
throw new IOException("Failed to create directory " +
logsDir);
}
}
if (logsDirFile.isDirectory()) {
return logsDir;
} else {
throw new IOException(logsDir + " is not a directory");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]