Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SEAM
seamcat
Commits
c04905cd
Commit
c04905cd
authored
1 year ago
by
Stephan Korsholm
Browse files
Options
Download
Email Patches
Plain Diff
#176
: Fix issue with empty log files
parent
b23a16b7
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/java/org/seamcat/model/Simulation.java
+36
-14
core/src/main/java/org/seamcat/model/Simulation.java
with
36 additions
and
14 deletions
+36
-14
core/src/main/java/org/seamcat/model/Simulation.java
+
36
-
14
View file @
c04905cd
...
@@ -6,6 +6,7 @@ import java.util.TimeZone;
...
@@ -6,6 +6,7 @@ import java.util.TimeZone;
import
org.apache.logging.log4j.Level
;
import
org.apache.logging.log4j.Level
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.core.Appender
;
import
org.apache.logging.log4j.core.LoggerContext
;
import
org.apache.logging.log4j.core.LoggerContext
;
import
org.apache.logging.log4j.core.appender.FileAppender
;
import
org.apache.logging.log4j.core.appender.FileAppender
;
import
org.apache.logging.log4j.core.config.Configuration
;
import
org.apache.logging.log4j.core.config.Configuration
;
...
@@ -68,17 +69,41 @@ public class Simulation {
...
@@ -68,17 +69,41 @@ public class Simulation {
+
"."
+
cal
.
get
(
Calendar
.
MINUTE
)
+
".log"
);
+
"."
+
cal
.
get
(
Calendar
.
MINUTE
)
+
".log"
);
LoggerContext
lc
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
LoggerContext
lc
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
FileAppender
fa
=
FileAppender
fa
=
(
FileAppender
)
lc
.
getConfiguration
().
getAppender
(
"DEBUG"
);
FileAppender
.
newBuilder
()
.
withName
(
"DEBUG"
)
if
(
fa
!=
null
)
{
.
withAppend
(
true
)
// Stop the old appender
.
withFileName
(
logfile
.
toString
())
fa
.
stop
();
.
withLayout
(
PatternLayout
.
newBuilder
().
withPattern
(
"%d{HH:mm:ss.SSS} %F %5p: %msg%n"
).
build
())
.
setConfiguration
(
lc
.
getConfiguration
())
// Reconfigure the appender with the new file path (and possibly other parameters if needed)
.
build
();
FileAppender
newAppender
=
FileAppender
.
newBuilder
()
fa
.
start
();
.
setConfiguration
(
lc
.
getConfiguration
())
lc
.
getConfiguration
().
addAppender
(
fa
);
.
withName
(
"DEBUG"
)
lc
.
getRootLogger
().
addAppender
(
lc
.
getConfiguration
().
getAppender
(
fa
.
getName
()));
.
withAppend
(
true
)
.
withFileName
(
logfile
.
toString
())
.
withLayout
(
fa
.
getLayout
())
.
build
();
// Start the new appender
newAppender
.
start
();
// Replace old appender with the new one in the configuration and logger
lc
.
getConfiguration
().
getAppenders
().
put
(
"DEBUG"
,
newAppender
);
lc
.
getRootLogger
().
removeAppender
(
fa
);
lc
.
getRootLogger
().
addAppender
(
newAppender
);
}
else
{
fa
=
FileAppender
.
newBuilder
()
.
withName
(
"DEBUG"
)
.
withAppend
(
true
)
.
withFileName
(
logfile
.
toString
())
.
withLayout
(
PatternLayout
.
newBuilder
().
withPattern
(
"%d{HH:mm:ss.SSS} %F %5p: %msg%n"
).
build
())
.
setConfiguration
(
lc
.
getConfiguration
())
.
build
();
fa
.
start
();
lc
.
getConfiguration
().
addAppender
(
fa
);
lc
.
getRootLogger
().
addAppender
(
lc
.
getConfiguration
().
getAppender
(
fa
.
getName
()));
}
Configuration
config
=
lc
.
getConfiguration
();
Configuration
config
=
lc
.
getConfiguration
();
LoggerConfig
loggerConfig
=
config
.
getRootLogger
();
LoggerConfig
loggerConfig
=
config
.
getRootLogger
();
loggerConfig
.
setLevel
(
Level
.
DEBUG
);
loggerConfig
.
setLevel
(
Level
.
DEBUG
);
...
@@ -93,9 +118,6 @@ public class Simulation {
...
@@ -93,9 +118,6 @@ public class Simulation {
public
void
removeDebugLog
()
{
public
void
removeDebugLog
()
{
LOG
.
debug
(
"Removing debug logger"
);
LOG
.
debug
(
"Removing debug logger"
);
LoggerContext
lc
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
LoggerContext
lc
=
(
LoggerContext
)
LogManager
.
getContext
(
false
);
FileAppender
debug
=
lc
.
getConfiguration
().
getAppender
(
"DEBUG"
);
debug
.
stop
();
lc
.
getRootLogger
().
removeAppender
(
debug
);
Configuration
config
=
lc
.
getConfiguration
();
Configuration
config
=
lc
.
getConfiguration
();
LoggerConfig
loggerConfig
=
config
.
getRootLogger
();
LoggerConfig
loggerConfig
=
config
.
getRootLogger
();
loggerConfig
.
setLevel
(
Level
.
INFO
);
loggerConfig
.
setLevel
(
Level
.
INFO
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets