Skip to content

Commit

Permalink
Disable file infra log by default
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus committed Dec 5, 2021
1 parent ccef345 commit a99f30e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Messages {
def traceAstSimple = cache("quill.trace.ast.simple", variable("quill.trace.ast.simple", "quill_trace_ast_simple", "false").toBoolean)
def traceQuats = cache("quill.trace.quat", QuatTrace(variable("quill.trace.quat", "quill_trace_quat", QuatTrace.None.value)))
def cacheDynamicQueries = cache("quill.query.cacheDaynamic", variable("quill.query.cacheDaynamic", "query_query_cacheDaynamic", "true").toBoolean)
def quillLogFile = cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "./target/queries.sql")))
def quillLogFile = cache("quill.log.file", LogToFile(variable("quill.log.file", "quill_log_file", "false")))

sealed trait LogToFile
object LogToFile {
Expand Down
35 changes: 19 additions & 16 deletions quill-core/src/main/scala/io/getquill/util/QueryLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,37 @@ class QueryLogger(logToFile: LogToFile) {
.map(appender => Has(appender.get.filter((ctx, _) => ctx.get(LogAnnotation.Level) >= logLevel)))
>+> Logging.make >>> modifyLoggerM(addTimestamp[String]))

private[getquill] val env = {
def produceLoggerEnv(file: String) =
ZEnv.live >>>
logFile(
logLevel = LogLevel.Info,
format = LogFormat.fromFunction((ctx, str) => {
str
}),
destination = Paths.get(file)
) >>> Logging.withRootLoggerName("query-logger")

lazy val env = {
logToFile match {
case LogToFile.Enabled(file) =>
ZEnv.live >>>
logFile(
logLevel = LogLevel.Info,
format = LogFormat.fromFunction((ctx, str) => {
str
}),
destination = Paths.get(file)
) >>> Logging.withRootLoggerName("query-logger")
case LogToFile.Disabled => Logging.ignore
case LogToFile.Enabled(file) => Some(produceLoggerEnv(file))
case LogToFile.Disabled => None
}
}

private[getquill] val runtime = Runtime.unsafeFromLayer(env)
private[getquill] val runtime =
env.map(Runtime.unsafeFromLayer(_))

def apply(queryString: String, sourcePath: String, line: Int, column: Int): Unit = {
quillLogFile match {
case LogToFile.Enabled(_) =>
runtime.unsafeRunAsync_(log.info(
runtime match {
case Some(runtimeValue) =>
runtimeValue.unsafeRunAsync_(log.info(
s"""
|-- file: $sourcePath:$line:$column
|-- time: ${ZonedDateTime.now().format(LogDatetimeFormatter.isoLocalDateTimeFormatter)}
|$queryString;
|""".stripMargin
))
case LogToFile.Disabled => // do nothing
case None => // do nothing
}
}
}

0 comments on commit a99f30e

Please sign in to comment.