Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Add internal Logging capabilities using zhttp.log #1115

Merged
merged 136 commits into from
May 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
7d6457d
implemented logging configuration to be able to invesigate netty laye…
gciuloaica Feb 28, 2022
3a32285
the low level logger should be off by default. logback config should …
gciuloaica Feb 28, 2022
d72adf8
wip
gciuloaica Feb 28, 2022
59b4b26
using internal logging
gciuloaica Mar 2, 2022
61140bd
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Mar 3, 2022
250523c
implemented simple console logging that is not allocated any memory f…
gciuloaica Mar 4, 2022
7d89f28
improved the logging api
gciuloaica Mar 4, 2022
869e9fc
udated workflow and added more logging
gciuloaica Mar 4, 2022
3177ff3
removed unused file
gciuloaica Mar 7, 2022
fd4cfc0
removed unused code.
gciuloaica Mar 9, 2022
2fe1737
extended loggig settings in configuration to provide ability to set d…
gciuloaica Mar 17, 2022
05e1118
added more logging and set benchmark in DEBBUG mode.
gciuloaica Mar 21, 2022
50f1ca6
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Mar 21, 2022
644da73
fixed merge
gciuloaica Mar 21, 2022
0293625
fixed formatting
gciuloaica Mar 21, 2022
2bd102e
changed logging level to INFO
gciuloaica Mar 21, 2022
4c80f23
change logging level for confing details
gciuloaica Mar 21, 2022
ca9f9ac
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Mar 21, 2022
5d2e103
disabled logging from benchmark
gciuloaica Mar 21, 2022
1d8321e
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Mar 28, 2022
e51386e
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Apr 8, 2022
581256c
doc: add scala dzio-http/src/test/scala/zhttp/internal/HttpGen.scalaoc
tusharmath Apr 9, 2022
b41e36b
remove: support logging of throwable
tusharmath Apr 9, 2022
a9831cd
refactor: rename params
tusharmath Apr 9, 2022
6a33bba
refactor: reorder methods
tusharmath Apr 9, 2022
eb2610c
refactor: Move ConsoleLogger into LogFrontend
tusharmath Apr 9, 2022
343fef0
refactor: Simplify LoggerFactory
tusharmath Apr 10, 2022
66db2c2
refactor: use `Logger.make` for generating a Logger
tusharmath Apr 10, 2022
919c91c
refactor: simplify LoggerMacro for 2.13
tusharmath Apr 10, 2022
a02bdae
refactor: simplify LogFrontend
tusharmath Apr 10, 2022
6b378b6
refactor: move LogLine inside of LogFormat
tusharmath Apr 10, 2022
33e470a
refactor: add apply method on LogFormat
tusharmath Apr 10, 2022
35ebba4
refactor: add LogTransport
tusharmath Apr 10, 2022
9896287
refactor: add Glogger
tusharmath Apr 11, 2022
88da3d8
working version after refactoring
gciuloaica Apr 18, 2022
2593d32
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Apr 18, 2022
54014c5
more refactoring
gciuloaica Apr 19, 2022
7850341
added location information, from where the log has been invoked
gciuloaica Apr 19, 2022
1215d6e
Merge branch 'netty-logger-zhttp' of github.com:dream11/zio-http into…
gciuloaica Apr 19, 2022
b004060
fixed after merge
gciuloaica Apr 19, 2022
6b3de8c
fixed scala 2.12 compilation
gciuloaica Apr 19, 2022
e07de8f
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Apr 19, 2022
b141eb8
migrating scala 3 macro wip
gciuloaica Apr 21, 2022
170d8b5
re-implemented based on new design. Single LoggerTransport for now is…
gciuloaica Apr 21, 2022
e1f2bf6
refactor: removed InternalLogger and the macro sbt package
gciuloaica Apr 26, 2022
d148dd3
Merge branch 'main' of github.com:dream11/zio-http into netty-logger-…
gciuloaica Apr 26, 2022
6ad62b5
wip adding another transport
gciuloaica Apr 26, 2022
ab55020
updated ci workflow
gciuloaica Apr 26, 2022
26f99fd
fixed scala 3 macro
gciuloaica Apr 26, 2022
6d67f5a
formatted
gciuloaica Apr 26, 2022
8a7a176
fixed scala 3 macro
gciuloaica Apr 26, 2022
5fa3756
removed compiler warning for scala 3
gciuloaica Apr 27, 2022
051956b
more simplifications
gciuloaica Apr 27, 2022
35ccd7a
added file transport implementation
gciuloaica Apr 27, 2022
e326704
added integration tests
gciuloaica Apr 27, 2022
7ea75c0
updated usage of logger in zio-http
gciuloaica Apr 27, 2022
9c38a47
updated tests to use api for java 8 only, added tags support in LogFo…
gciuloaica Apr 27, 2022
1b8f966
updated test to work also with scala 2.12
gciuloaica Apr 27, 2022
1006647
more simplifications
gciuloaica Apr 28, 2022
c67703b
fixed imports
gciuloaica Apr 28, 2022
ff6380f
updated server API to allow users of the API to provide a custom logger
gciuloaica Apr 28, 2022
cbf02b0
more simplifications - the name of the logger was redundant as we hav…
gciuloaica Apr 28, 2022
f02bcb0
updated example and added more log to server implementation
gciuloaica Apr 28, 2022
16f97e0
undo the exmple changes
gciuloaica Apr 29, 2022
da7ac32
Merge branch 'main' into netty-logger-zhttp
tusharmath Apr 30, 2022
3d86d15
refactor: rename logLevels
tusharmath Apr 30, 2022
46c817d
refactor: make LoggerFactory.Live private
tusharmath Apr 30, 2022
115567b
refactor: clean up the logger a bit
tusharmath Apr 30, 2022
33d249e
refactor: make LogTransport private to Logger
tusharmath Apr 30, 2022
40bda22
doc: add scala doc in netty logger
tusharmath Apr 30, 2022
e787248
doc: update scala doc
tusharmath Apr 30, 2022
25e5e3e
chore: remove unnecessary build changes
tusharmath Apr 30, 2022
644acca
refactor: LogFrontend and LoggerTransport
tusharmath Apr 30, 2022
50cc723
style: fmt
amitksingh1490 May 1, 2022
a5b1617
feature: add `autodetectLevel` and `startsWith` operators on Logger
tusharmath Apr 30, 2022
a0728fc
feat: add `detectFromEnv` method to LogLevel
tusharmath May 1, 2022
fde19e7
refactor: update Scala doc from Logger.scala
tusharmath May 1, 2022
dd31254
refactor: disable logging by default while reading loglevel from env
tusharmath May 1, 2022
af4f5a8
refactor: rename file
tusharmath May 1, 2022
7c6c023
refactor: simplify LogTransport
tusharmath May 1, 2022
040b8dc
feature: add `dispatch` and operators to modify tags
tusharmath May 1, 2022
fc217e6
perf: optimize Logger's macro implementation
tusharmath May 1, 2022
c82e503
Merge branch 'netty-logger-zhttp' of github.com:dream11/zio-http into…
gciuloaica May 4, 2022
1887535
scala 3 macro fixes and other cosmetic changes
gciuloaica May 4, 2022
fcca862
logger transport will discard the log line based on log transport log…
gciuloaica May 4, 2022
a9b2b4e
used SourcePos instead of passing 2 values around, only trace will pr…
gciuloaica May 6, 2022
040a75a
fixed flaky test
gciuloaica May 6, 2022
12c9475
style: reorder methods in Server
tusharmath May 8, 2022
6727c54
Merge branch 'main' into netty-logger-zhttp
tusharmath May 8, 2022
2e5311f
feature: add More LogDetection logic
tusharmath May 8, 2022
d3c8e19
refactor: drop `tags` from LogStatement
tusharmath May 8, 2022
79eada6
feature: add splat operator for withTags
tusharmath May 8, 2022
3b1bbc7
refactor: add `detechLevelFromProps`
tusharmath May 8, 2022
50e520d
chore: update default app to HelloWorld
tusharmath May 8, 2022
c25675d
refactor: cleanup LogFormat
tusharmath May 8, 2022
f390685
refactor: remove redundant `withTag` operator
tusharmath May 8, 2022
c7e9dbc
refactor: cleanup log statements in Server
tusharmath May 8, 2022
396c4e0
performance: optimize scala 3 output
tusharmath May 9, 2022
ff65e41
removed logging from API. the Log instance is created with LogLevel r…
gciuloaica May 11, 2022
f709b5e
formatting
gciuloaica May 11, 2022
5ecddaa
formatting
gciuloaica May 11, 2022
1e38cab
more tests for logger using an in memory transport
gciuloaica May 13, 2022
af59da4
fixed for scala 2.12
gciuloaica May 13, 2022
951b2cb
fix for scala 3
gciuloaica May 13, 2022
20ec5f5
removed logger api documentation
gciuloaica May 13, 2022
8c058cb
added empty line
gciuloaica May 13, 2022
d8ed1d9
update log tests
gciuloaica May 13, 2022
201ee8d
macro updated to check if the level is enabled for a certain log level
gciuloaica May 13, 2022
bb9da9d
trading maintenability for performance: extended LoggerMacroExtension…
gciuloaica May 16, 2022
0c07155
added isEnabled flag in logger
gciuloaica May 18, 2022
11f4a58
Merge branch 'main' into netty-logger-zhttp
tusharmath May 19, 2022
04a6725
chore: set default LogLevel to INFO
tusharmath May 19, 2022
a9a93d4
style: remove unnecessary bracket
tusharmath May 19, 2022
fdcd6f8
refactor: add Logging.scala
tusharmath May 19, 2022
ac71a76
refactor: update ChannelInitializer LogStatement
tusharmath May 19, 2022
aaebf84
refactor: Update log statement inside of runtime
tusharmath May 19, 2022
79b8746
refactor: Change default LogLevel to `Error`
tusharmath May 19, 2022
b293346
refactor: use `SimpleName` for class names
tusharmath May 19, 2022
f202e8e
formatting
gciuloaica May 19, 2022
62e9bf0
removed debug log statements.
gciuloaica May 19, 2022
8778244
rolled back last change
gciuloaica May 19, 2022
20bef93
minor correction in test name
gciuloaica May 19, 2022
42f6d3c
short circuit the logl level cheks when logger is disabled
gciuloaica May 19, 2022
c559265
refactor: add more operators to compare LogLevel
tusharmath May 19, 2022
0774d5a
chore: update scala-settings to ignore unused parameters
tusharmath May 19, 2022
079cbd8
refactor: add detectedLogLevel
tusharmath May 20, 2022
918d1ed
refactor: change dispatch signature
tusharmath May 20, 2022
6175b1b
refactor: add tests for LogLevel
tusharmath May 21, 2022
adfcbd1
refactor: rename formats
tusharmath May 21, 2022
0bc4ab1
refactor: clean-up logLevel
tusharmath May 21, 2022
e211b49
refactor: drop `Disable` level for Logging
tusharmath May 21, 2022
842b367
refactor: LoggerTransport to become an abstract class
tusharmath May 21, 2022
f9ac266
refactor: simplify LoggerSpec
tusharmath May 21, 2022
261832f
chore: update build
tusharmath May 21, 2022
512bea0
chore: update ScalaSettings
tusharmath May 25, 2022
0029336
if the env value is not matching any defined log levels, than the log…
gciuloaica May 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: LogFrontend and LoggerTransport
  • Loading branch information
tusharmath committed Apr 30, 2022
commit 644acca3399f9060475e498fe7f25a13c337df64
107 changes: 0 additions & 107 deletions zio-http-logging/src/main/scala/zhttp/logging/LogFrontend.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ package zhttp.logging

import zhttp.logging.LoggerTransport.Transport

import java.io.{PrintWriter, StringWriter}
import java.nio.file.{Files, Path, StandardOpenOption}
import java.time.LocalDateTime
import java.util

/**
@@ -14,12 +16,95 @@ private[logging] final case class LoggerTransport(
format: Setup.LogFormat,
filter: String => Boolean,
transport: Transport,
) extends LogFrontend { self =>
) { self =>
private[zhttp] val isDebugEnabled: Boolean = self.level >= LogLevel.Debug
private[zhttp] val isErrorEnabled: Boolean = self.level >= LogLevel.Error
private[zhttp] val isInfoEnabled: Boolean = self.level >= LogLevel.Info
private[zhttp] val isTraceEnabled: Boolean = self.level >= LogLevel.Trace
private[zhttp] val isWarnEnabled: Boolean = self.level >= LogLevel.Warn

private def buildLines(
msg: String,
throwable: Option[Throwable],
logLevel: LogLevel,
tags: List[String],
enclosingClass: String,
lineNumber: Int,
): List[LogLine] = {
throwable.fold(
List(LogLine(LocalDateTime.now(), thread, logLevel, msg, tags, throwable, enclosingClass, lineNumber)),
) { t =>
List(
LogLine(LocalDateTime.now(), thread, logLevel, msg, tags, throwable, enclosingClass, lineNumber),
LogLine(
LocalDateTime.now(),
thread,
logLevel,
stackTraceAsString(t),
tags,
throwable,
enclosingClass,
lineNumber,
),
)
},
}

private def logMayBe(
msg: String,
throwable: Option[Throwable],
logLevel: LogLevel,
tags: List[String],
enclosingClass: String,
lineNumber: Int,
): Unit =
if (filter(tags.mkString)) {
buildLines(msg, throwable, logLevel, tags, enclosingClass, lineNumber).foreach { line =>
self.log(format(line))
}
}

private def stackTraceAsString(throwable: Throwable): String = {
val sw = new StringWriter
throwable.printStackTrace(new PrintWriter(sw))
sw.toString
}

private def thread = Thread.currentThread()

def debug(msg: String, tags: List[String], enclosingClass: String, lineNumber: Int): Unit =
logMayBe(msg, None, LogLevel.Debug, tags, enclosingClass, lineNumber)

def error(msg: String, tags: List[String], enclosingClass: String, lineNumber: Int): Unit =
logMayBe(msg, None, LogLevel.Error, tags, enclosingClass, lineNumber)

def error(
msg: String,
throwable: Throwable,
tags: List[String],
enclosingClass: String,
lineNumber: Int,
): Unit =
logMayBe(msg, Some(throwable), LogLevel.Error, tags, enclosingClass, lineNumber)

def info(msg: String, tags: List[String], enclosingClass: String, lineNumber: Int): Unit =
logMayBe(msg, None, LogLevel.Info, tags, enclosingClass, lineNumber)

def log(msg: CharSequence): Unit = if (filter(msg.toString)) transport.run(msg)

def trace(msg: String, tags: List[String], enclosingClass: String, lineNumber: Int): Unit =
logMayBe(msg, None, LogLevel.Trace, tags, enclosingClass, lineNumber)

def warn(msg: String, tags: List[String], enclosingClass: String, lineNumber: Int): Unit =
logMayBe(msg, None, LogLevel.Warn, tags, enclosingClass, lineNumber)

def withFilter(filter: String => Boolean): LoggerTransport = self.copy(filter = filter)

def withFormat(format: LogLine => CharSequence): LoggerTransport = self.copy(format = format)
def withFormat(format: LogFormat): LoggerTransport = self.copy(format = LogFormat.run(format))
def withLevel(level: LogLevel): LoggerTransport = self.copy(level = level)
def withFilter(filter: String => Boolean): LoggerTransport = self.copy(filter = filter)
override def log(msg: CharSequence): Unit = if (filter(msg.toString)) transport.run(msg)

def withFormat(format: LogFormat): LoggerTransport = self.copy(format = LogFormat.run(format))

def withLevel(level: LogLevel): LoggerTransport = self.copy(level = level)
}

object LoggerTransport {