SammyVimes commented on code in PR #1105:
URL: https://github.com/apache/ignite-3/pull/1105#discussion_r976241145


##########
modules/cli/src/main/java/org/apache/ignite/cli/Main.java:
##########
@@ -155,20 +157,26 @@ 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) -> n == null ? o : getLogsDir() + "/" + 
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() {
+        String envLogsDir = System.getenv(IGNITE_CLI_LOGS_DIR);
+        String logsDir = envLogsDir != null ? envLogsDir : 
StateFolderProvider.getStateFile("logs").getAbsolutePath();
+        new File(logsDir).mkdirs();

Review Comment:
   Probably should be something like
   
   if (!exists) {
       if (!mkdirs) {
           throw new Exception
       }
   }



##########
modules/cli/src/main/java/org/apache/ignite/cli/Main.java:
##########
@@ -155,20 +157,26 @@ 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) -> n == null ? o : getLogsDir() + "/" + 
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() {
+        String envLogsDir = System.getenv(IGNITE_CLI_LOGS_DIR);
+        String logsDir = envLogsDir != null ? envLogsDir : 
StateFolderProvider.getStateFile("logs").getAbsolutePath();
+        new File(logsDir).mkdirs();

Review Comment:
   Probably should be something like
   ```
   if (!exists) {
       if (!mkdirs) {
           throw new Exception
       }
   }
   ```



-- 
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]

Reply via email to