Skip to content

Commit f7106bd

Browse files
committed
Refactoring : LogBack methods, field, name
1 parent 75177b3 commit f7106bd

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

src/main/scala/gitbucket/monitoring/controllers/LogController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait LogController extends MonitoringControllerBase {
77

88
get("/admin/monitoring/logs/logback")(adminOnly {
99
gitbucket.monitoring.information.logs.html.logback(
10-
LogBack.getLogBackInfo,
10+
LogBack.logBackSettingsFile,
1111
LogBack.getLogBackSettings
1212
);
1313
})

src/main/scala/gitbucket/monitoring/services/GitBucketLog.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object GitBucketLog {
1010

1111
def getDefaultSettings: DefaultSettings = {
1212
DefaultSettings(
13-
LogBack.getLogBackInfo,
13+
LogBack.getLogBackSettings,
1414
1000,
1515
30000
1616
)

src/main/scala/gitbucket/monitoring/services/LogBack.scala

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ object LogBack {
1111
val dosentConfigureMessage = "Dosen't configure Logback."
1212
val enableLogging = Java.getSystemProperties.contains("logback.configurationFile")
1313
val confPath = Java.getSystemProperties.getOrElse("logback.configurationFile", notFoundMessage)
14-
15-
def getLogBackSettings: Either[String, String] = {
14+
val logBackSettingsFile: Either[String, String] = {
1615
if (enableLogging) {
1716
try {
1817
val bytes = Files.readAllBytes(Paths.get(confPath))
@@ -27,31 +26,29 @@ object LogBack {
2726
}
2827
}
2928

30-
def getLogBackInfo: LogBackInfo = {
31-
val logFilePath: Either[String, String] = {
32-
if (enableLogging) {
33-
try {
34-
val xml = getLogBackSettings match {
35-
case Left(message) => message
36-
case Right(s) => {
37-
(XML.loadString(s) \\ "appender" \ "file" toString).replace("<file>","").replace("</file>","")
38-
}
39-
}
40-
if (xml.trim.length == 0) {
41-
Left(Message.notFound)
42-
} else {
43-
(Right(
44-
xml
45-
))
29+
val logFilePath: Either[String, String] = {
30+
if (enableLogging) {
31+
try {
32+
val xml = logBackSettingsFile match {
33+
case Left(message) => message
34+
case Right(s) => {
35+
(XML.loadString(s) \\ "appender" \ "file" toString).replace("<file>","").replace("</file>","")
4636
}
47-
} catch {
48-
case e: Exception => Left(Message.error)
4937
}
50-
} else {
51-
Left(dosentConfigureMessage)
38+
if (xml.trim.length == 0) {
39+
Left(Message.notFound)
40+
} else {
41+
Right(xml)
42+
}
43+
} catch {
44+
case e: Exception => Left(Message.error)
5245
}
46+
} else {
47+
Left(dosentConfigureMessage)
5348
}
49+
}
5450

51+
def getLogBackSettings: LogBackInfo = {
5552
LogBackInfo(
5653
Java.getSystemProperties.contains("logback.configurationFile"),
5754
Java.getSystemProperties.getOrElse("logback.configurationFile", notFoundMessage),

src/main/twirl/gitbucket/monitoring/information/logs/logback.scala.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
@(logbackInfo: gitbucket.monitoring.models.LogBackInfo,
2-
logbackSettings: Either[String, String])(implicit context: gitbucket.core.controller.Context)
1+
@(logbackSettingsFile: Either[String, String],
2+
logbackSettings: gitbucket.monitoring.models.LogBackInfo)(implicit context: gitbucket.core.controller.Context)
33
@import context._
44
@gitbucket.core.html.main("Monitoring") {
55
@gitbucket.core.admin.html.menu("monitoring") {
66
@gitbucket.monitoring.html.navigation(context)
77
@gitbucket.monitoring.information.logs.html.tab(context)
88
@gitbucket.monitoring.html.loading(context)
9-
@if(logbackInfo.enableLogging) {
9+
@if(logbackSettings.enableLogging) {
1010
<div class="panel panel-default">
1111
<div class="panel-body">
1212
<h6><span class="label label-primary">Enable</span></h6><hr>
1313
<div class="row">
1414
<label class="col-md-2">Config file's path</label>
15-
<span class="col-md-10">@logbackInfo.confPath</span>
15+
<span class="col-md-10">@logbackSettings.confPath</span>
1616
</div>
1717
<div class="row">
1818
<label class="col-md-2">Log file's path</label>
1919
<span class="col-md-10">
20-
@logbackInfo.logFilePath match {
20+
@logbackSettings.logFilePath match {
2121
case Left(message) => { @gitbucket.monitoring.helper.html.coloring(message) }
2222
case Right(p) => { @p }
2323
}
2424
</span>
2525
</div>
2626
</div>
2727
</div>
28-
@logbackSettings match {
28+
@logbackSettingsFile match {
2929
case Left(message) => { @gitbucket.monitoring.helper.html.coloring(message) }
30-
case Right(s) => { <div class="box-header"><span class="glyphicon glyphicon-file"><span class="label label-default ">@logbackInfo.confPath</span></span></div>
30+
case Right(s) => { <div class="box-header"><span class="glyphicon glyphicon-file"><span class="label label-default ">@logbackSettings.confPath</span></span></div>
3131
<div class="box-content-bottom"><pre class="prettyprint linenums blob">@s</pre></div>
3232
}
3333
}

0 commit comments

Comments
 (0)