Skip to content

Commit

Permalink
Merge pull request #15 from nebula-contrib/add-log
Browse files Browse the repository at this point in the history
log setting
  • Loading branch information
jxnu-liguobin authored Sep 14, 2023
2 parents ebafec5 + c5dc681 commit 2c7e8b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions core/src/main/scala/zio/nebula/GlobalSettings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package zio.nebula

import zio._

/**
* @author
* 梦境迷离
* @version 1.0,2023/9/14
*/
object GlobalSettings {

var printStatement: Boolean = false
var logLevel: LogLevel = LogLevel.Warning

def printLog(stmt: String): ZIO[Any, Nothing, Unit] =
ZIO
.when(GlobalSettings.printStatement) {
if (GlobalSettings.logLevel == LogLevel.Error) {
ZIO.logError(s"Nebula client executed statement: $stmt")
} else if (GlobalSettings.logLevel == LogLevel.Warning) {
ZIO.logWarning(s"Nebula client executed statement: $stmt")
} else if (GlobalSettings.logLevel == LogLevel.Info) {
ZIO.logInfo(s"Nebula client executed statement: $stmt")
} else if (GlobalSettings.logLevel == LogLevel.Debug) {
ZIO.logDebug(s"Nebula client executed statement: $stmt")
} else if (GlobalSettings.logLevel == LogLevel.Trace) {
ZIO.logTrace(s"Nebula client executed statement: $stmt")
} else
ZIO.logFatal(s"Nebula client executed statement: $stmt").when(GlobalSettings.logLevel == LogLevel.Fatal).unit
}
.unit
}
3 changes: 2 additions & 1 deletion core/src/main/scala/zio/nebula/NebulaSessionClientLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import com.vesoft.nebula.client.graph._
private[nebula] final class NebulaSessionClientLive(underlying: SessionPool) extends NebulaSessionClient {

override def execute(stmt: String): Task[NebulaResultSet] =
ZIO.attempt(new NebulaResultSet(underlying.execute(stmt)))
GlobalSettings.printLog(stmt) *>
ZIO.attempt(new NebulaResultSet(underlying.execute(stmt)))

override def idleSessionNum: Task[Int] = ZIO.attempt(underlying.getIdleSessionNums)

Expand Down

0 comments on commit 2c7e8b9

Please sign in to comment.