You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/12/06 11:05:10 UTC

[GitHub] [beam] ilya-kozyrev commented on a change in pull request #16120: [BEAM-13333][Playground] Save Python logs to the cache

ilya-kozyrev commented on a change in pull request #16120:
URL: https://github.com/apache/beam/pull/16120#discussion_r762903906



##########
File path: playground/backend/internal/fs_tool/fs.go
##########
@@ -171,3 +172,10 @@ func (l *LifeCycle) GetAbsoluteBaseFolderPath() string {
 	absoluteFilePath, _ := filepath.Abs(l.Folder.BaseFolder)
 	return absoluteFilePath
 }
+
+// GetAbsoluteLogFilePath returns absolute path to the logs file (/path/to/workingDir/executable_files/{pipelineId}/logs.log)
+func (l *LifeCycle) GetAbsoluteLogFilePath() string {
+	filePath := filepath.Join(l.Folder.BaseFolder, logFileName)
+	absoluteFilePath, _ := filepath.Abs(filePath)

Review comment:
       Not sure that we need to process errors here, but let's double-check which cases we can take an error? 

##########
File path: playground/backend/internal/preparators/python_preparators.go
##########
@@ -15,7 +15,82 @@
 
 package preparators
 
+import (
+	"beam.apache.org/playground/backend/internal/logger"
+	"bufio"
+	"io"
+	"os"
+)
+
+const (
+	addLogHandlerCode = "import logging\nlogging.basicConfig(\n    level=logging.DEBUG,\n    format=\"%(asctime)s [%(levelname)s] %(message)s\",\n    handlers=[\n        logging.FileHandler(\"logs.log\"),\n    ]\n)\n"
+)
+
 // GetPythonPreparators returns preparation methods that should be applied to Python code
 func GetPythonPreparators(filePath string) *[]Preparator {
-	return &[]Preparator{}
+	addLogHandler := Preparator{
+		Prepare: addToCode,
+		Args:    []interface{}{filePath, addLogHandlerCode},
+	}
+	return &[]Preparator{addLogHandler}
+}
+
+// addToCode processes file by filePath and adds additional code

Review comment:
       seems like we can union this function with writeCodeToFile

##########
File path: playground/backend/internal/preparators/python_preparators.go
##########
@@ -15,7 +15,82 @@
 
 package preparators
 
+import (
+	"beam.apache.org/playground/backend/internal/logger"
+	"bufio"
+	"io"
+	"os"
+)
+
+const (
+	addLogHandlerCode = "import logging\nlogging.basicConfig(\n    level=logging.DEBUG,\n    format=\"%(asctime)s [%(levelname)s] %(message)s\",\n    handlers=[\n        logging.FileHandler(\"logs.log\"),\n    ]\n)\n"
+)
+
 // GetPythonPreparators returns preparation methods that should be applied to Python code
 func GetPythonPreparators(filePath string) *[]Preparator {
-	return &[]Preparator{}
+	addLogHandler := Preparator{
+		Prepare: addToCode,
+		Args:    []interface{}{filePath, addLogHandlerCode},
+	}
+	return &[]Preparator{addLogHandler}
+}
+
+// addToCode processes file by filePath and adds additional code

Review comment:
       and with writeToFile :) 

##########
File path: playground/backend/internal/preparators/python_preparators.go
##########
@@ -15,7 +15,82 @@
 
 package preparators
 
+import (
+	"beam.apache.org/playground/backend/internal/logger"
+	"bufio"
+	"io"
+	"os"
+)
+
+const (
+	addLogHandlerCode = "import logging\nlogging.basicConfig(\n    level=logging.DEBUG,\n    format=\"%(asctime)s [%(levelname)s] %(message)s\",\n    handlers=[\n        logging.FileHandler(\"logs.log\"),\n    ]\n)\n"
+)
+
 // GetPythonPreparators returns preparation methods that should be applied to Python code
 func GetPythonPreparators(filePath string) *[]Preparator {
-	return &[]Preparator{}
+	addLogHandler := Preparator{
+		Prepare: addToCode,
+		Args:    []interface{}{filePath, addLogHandlerCode},
+	}
+	return &[]Preparator{addLogHandler}
+}
+
+// addToCode processes file by filePath and adds additional code

Review comment:
       addCodeToFile might be clearer? :) 




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org