-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logging capabilities using logback and secured default Standard…
… Output Stream to reserve it for LSP4j
- Loading branch information
Showing
6 changed files
with
86 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
lsp | ||
target | ||
target | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<configuration> | ||
|
||
<!-- Appender to write logs to a file --> | ||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>logs/myapp.log</file> <!-- Change the file name as needed --> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> | ||
<fileNamePattern>logs/myapp.%i.log</fileNamePattern> | ||
<minIndex>1</minIndex> | ||
<maxIndex>10</maxIndex> | ||
</rollingPolicy> | ||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> | ||
<maxFileSize>10MB</maxFileSize> | ||
</triggeringPolicy> | ||
<encoder> | ||
<pattern>%date{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- Root logger settings --> | ||
<root level="info"> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/scala/io/smartdatalake/logging/LoggerOutputStream.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.smartdatalake.logging | ||
|
||
import org.slf4j.Logger | ||
|
||
import java.io.OutputStream | ||
|
||
private[logging] class LoggerOutputStream(logger: Logger) extends OutputStream { | ||
private val builder = new StringBuilder | ||
override def write(b: Int): Unit = { | ||
if (b == '\n') { | ||
logger.info(builder.toString) | ||
builder.clear() | ||
} else { | ||
builder.append(b.toChar) | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/scala/io/smartdatalake/logging/LoggingManager.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.smartdatalake.logging | ||
|
||
import org.slf4j.LoggerFactory | ||
|
||
import java.io.PrintStream | ||
|
||
object LoggingManager { | ||
|
||
def redirectStandardOutputToLoggerOutput(): Unit = | ||
val loggerRedirectedOutput = LoggerFactory.getLogger("redirectedOutput") | ||
val redirectedPrintStream = new PrintStream(new LoggerOutputStream(loggerRedirectedOutput)) | ||
System.setOut(redirectedPrintStream) | ||
println("Using new default output stream") | ||
|
||
} |