Skip to content

Commit

Permalink
Push logs to file, define folder for logs for each OS
Browse files Browse the repository at this point in the history
  • Loading branch information
pflooky committed Mar 20, 2024
1 parent 80a6676 commit 71ba313
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ jobs:
with:
name: jars
path: app/build/libs/
- name: Package jar as exe
- name: Package jar as msi
run: 'jpackage "@misc/jpackage/jpackage.cfg" "@misc/jpackage/jpackage-windows.cfg"'
- name: Upload installer
uses: actions/upload-artifact@v4
with:
name: data-caterer-windows
path: "DataCaterer-1.0.0.exe"
path: "DataCaterer-1.0.0.msi"
overwrite: true

linux:
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/resources/log4j2.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
rootLogger.level=${env:LOG_LEVEL:-info}
rootLogger.appenderRefs=console,file
rootLogger.appenderRef.stdout.ref=console
rootLogger.appenderRef.logfile.ref=file
# Console log
appender.console.type=Console
appender.console.name=console
appender.console.target=SYSTEM_OUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d{dd/MM/yyyy HH:mm:ss} [%-5p] %c: %m%n%ex
# File log
appender.file.type=File
appender.file.name=file
appender.file.fileName=${sys:LOG_FOLDER:-logs}/data-caterer.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=%d{dd/MM/yyyy HH:mm:ss} [%-5p] %c: %m%n%ex
# Settings to quiet third party logs that are too verbose
logger.spark.name=org.apache.spark
logger.spark.level=error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object ConnectionRepository extends JsonSupport {
}

def getConnection(name: String): Connection = {
LOGGER.info(s"Getting connection details, connection-name=$name")
LOGGER.debug(s"Getting connection details, connection-name=$name")
val connectionFile = Path.of(s"$connectionSaveFolder/$name.csv")
val connection = Connection.fromString(Files.readString(connectionFile))
val mappedPw = connection.options.map(o => if (o._1 == "password") (o._1, "***") else o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.github.datacatering.datacaterer.core.plan.PlanProcessor
import io.github.datacatering.datacaterer.core.ui.config.UiConfiguration.INSTALL_DIRECTORY
import io.github.datacatering.datacaterer.core.ui.mapper.UiMapper
import io.github.datacatering.datacaterer.core.ui.model.{JsonSupport, PlanRunExecution, PlanRunRequest, PlanRunRequests}
import io.github.datacatering.datacaterer.core.ui.plan.ConnectionRepository.getClass
import io.github.datacatering.datacaterer.core.ui.plan.ConnectionRepository.{LOGGER, getClass}
import io.github.datacatering.datacaterer.core.ui.plan.PlanResponseHandler.{KO, OK, Response}
import org.apache.log4j.Logger
import org.joda.time.{DateTime, Seconds}
Expand Down Expand Up @@ -117,6 +117,7 @@ object PlanRepository extends JsonSupport {
}

private def savePlanRunExecution(planRunRequest: PlanRunRequest, planRunExecution: PlanRunExecution): Unit = {
LOGGER.debug(s"Saving plan run execution details, plan-name=${planRunRequest.name}, plan-run-id=${planRunRequest.id}")
savePlan(planRunRequest)
try {
Path.of(executionSaveFolder).toFile.mkdirs()
Expand All @@ -128,6 +129,7 @@ object PlanRepository extends JsonSupport {
}

private def savePlan(planRunRequest: PlanRunRequest): Unit = {
LOGGER.debug(s"Saving plan details, plan-name=${planRunRequest.name}")
try {
Path.of(planSaveFolder).toFile.mkdirs()
val planFile = Path.of(s"$planSaveFolder/${planRunRequest.name}.json")
Expand All @@ -138,6 +140,7 @@ object PlanRepository extends JsonSupport {
}

private def getPlans: PlanRunRequests = {
LOGGER.debug("Getting all plans")
val planFolder = Path.of(planSaveFolder)
if (!planFolder.toFile.exists()) planFolder.toFile.mkdirs()
val plans = Files.list(planFolder)
Expand All @@ -152,12 +155,14 @@ object PlanRepository extends JsonSupport {
}

private def getPlan(name: String): PlanRunRequest = {
LOGGER.debug(s"Getting plan details, plan-name=$name")
val planFile = Path.of(s"$planSaveFolder/$name.json")
Files.readString(planFile).parseJson.convertTo[PlanRunRequest]
}

private def updatePlanRunExecution(planRunExecution: PlanRunExecution, status: String, failedReason: Option[String] = None,
results: Option[PlanRunResults] = None): Unit = {
LOGGER.debug(s"Update plan execution, plan-name=${planRunExecution.name}, plan-run-id=${planRunExecution.id}, status=$status")
val executionFile = Path.of(s"$executionSaveFolder/${planRunExecution.id}.csv")
val cleanFailReason = failedReason.map(s => s.replaceAll("\n", " "))
val generationSummary = results.map(res => res.generationResults.map(_.summarise)).getOrElse(List())
Expand All @@ -173,12 +178,14 @@ object PlanRepository extends JsonSupport {
}

private def getPlanRunStatus(id: String): PlanRunExecution = {
LOGGER.debug(s"Getting current plan status, plan-run-id=$id")
val executionFile = Path.of(s"$executionSaveFolder/$id.csv")
val latestUpdate = Files.readAllLines(executionFile).asScala.last
PlanRunExecution.fromString(latestUpdate)
}

private def getAllPlanExecutions: PlanRunExecutionDetails = {
LOGGER.debug("Getting all plan executions")
val executionPath = Path.of(executionSaveFolder)
if (!executionPath.toFile.exists()) executionPath.toFile.mkdirs()
val allPlanRunExecutions = Files.list(executionPath)
Expand Down
3 changes: 2 additions & 1 deletion misc/jpackage/jpackage-linux.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--type deb
--icon misc/banner/data_catering_transparent.png
--icon misc/banner/data_catering_transparent.png
--java-options "-DLOG_FOLDER=/opt/DataCaterer/log"
3 changes: 2 additions & 1 deletion misc/jpackage/jpackage-mac.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--type dmg
--icon misc/banner/data_catering_transparent.icns
--icon misc/banner/data_catering_transparent.icns
--java-options "-DLOG_FOLDER=/Applications/DataCaterer.app/Logs"
5 changes: 3 additions & 2 deletions misc/jpackage/jpackage-windows.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--type exe
--icon misc/banner/data_catering_transparent.ico
--type msi
--icon misc/banner/data_catering_transparent.ico
--java-options "-DLOG_FOLDER=/Program Files/DataCaterer/log"
2 changes: 1 addition & 1 deletion misc/jpackage/jpackage.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--name "DataCaterer"
--vendor "Data Catering"
--about-url https://data.catering
--description "Data generation and validation tool"
--description "Data Caterer: Data generation and validation tool"
--input app/build/libs/
--app-version 1.0.0
--main-jar app-0.7.0-all.jar
Expand Down

0 comments on commit 71ba313

Please sign in to comment.