-
Notifications
You must be signed in to change notification settings - Fork 50
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
Adds log4s logging to free and tagless #512
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7de77f7
Adds log4s logging to free and tagless
eperinan 0b3e948
Aligned packages and objects and fix typo
eperinan 4731c11
Adds documentation
eperinan c4c943b
Setting version to 0.6.2
eperinan 4ce3158
Improvement build.sbt and minor changes in documentation
eperinan ed27835
Fix wrong compilation tut documentation
eperinan 24135b1
Adds deprecated to default implicit
eperinan 6260100
Sort packages in one line
eperinan a24392a
Very minor grammar changes
MaureenElsberry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,21 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.free | ||
package loggingJVM | ||
package journal | ||
|
||
object implicits extends freestyle.tagless.loggingJVM.journal.Implicits |
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,21 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.free | ||
package loggingJVM | ||
package log4s | ||
|
||
object implicits extends freestyle.tagless.loggingJVM.log4s.Implicits |
20 changes: 20 additions & 0 deletions
20
modules/logging/jvm/src/main/scala/tagless/implicits.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,20 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.tagless | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Changed. |
||
package loggingJVM | ||
|
||
object implicits extends freestyle.tagless.loggingJVM.journal.Implicits |
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,81 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.tagless | ||
package loggingJVM | ||
|
||
import cats.Applicative | ||
import freestyle.logging._ | ||
import freestyle.tagless.logging._ | ||
import org.log4s._ | ||
|
||
object log4s { | ||
|
||
sealed abstract class TaglessLoggingMHandler[M[_]] extends LoggingM.Handler[M] { | ||
|
||
import sourcecode.{File, Line} | ||
|
||
protected def withLogger[A](f: Logger => A): M[A] | ||
|
||
def debug(msg: String, srcInfo: Boolean)(implicit line: Line, file: File): M[Unit] = | ||
withLogger(_.debug(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def debugWithCause(msg: String, cause: Throwable, srcInfo: Boolean)( | ||
implicit | ||
line: Line, | ||
file: File): M[Unit] = | ||
withLogger(_.debug(cause)(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def error(msg: String, srcInfo: Boolean)(implicit line: Line, file: File): M[Unit] = | ||
withLogger(_.error(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def errorWithCause(msg: String, cause: Throwable, srcInfo: Boolean)( | ||
implicit | ||
line: Line, | ||
file: File): M[Unit] = | ||
withLogger(_.error(cause)(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def info(msg: String, srcInfo: Boolean)(implicit line: Line, file: File): M[Unit] = | ||
withLogger(_.info(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def infoWithCause(msg: String, cause: Throwable, srcInfo: Boolean)( | ||
implicit | ||
line: Line, | ||
file: File): M[Unit] = | ||
withLogger(_.info(cause)(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def warn(msg: String, srcInfo: Boolean)(implicit line: Line, file: File): M[Unit] = | ||
withLogger(_.warn(formatMessage(msg, srcInfo, line, file))) | ||
|
||
def warnWithCause(msg: String, cause: Throwable, srcInfo: Boolean)( | ||
implicit | ||
line: Line, | ||
file: File): M[Unit] = | ||
withLogger(_.warn(cause)(formatMessage(msg, srcInfo, line, file))) | ||
|
||
} | ||
|
||
trait Implicits { | ||
implicit def taglessLoggingApplicative[M[_]: Applicative]( | ||
implicit log: Logger = getLogger("")): LoggingM.Handler[M] = new TaglessLoggingMHandler[M] { | ||
|
||
protected def withLogger[A](f: Logger => A): M[A] = Applicative[M].pure(f(log)) | ||
|
||
} | ||
} | ||
|
||
object implicits extends Implicits | ||
} |
79 changes: 79 additions & 0 deletions
79
modules/logging/jvm/src/test/scala/free/LoggingTestsJournal.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,79 @@ | ||
/* | ||
* Copyright 2017-2018 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package freestyle.free | ||
|
||
import cats.instances.future._ | ||
import cats.{Id, Monad} | ||
import freestyle.free.implicits._ | ||
import freestyle.free.loggingJVM.implicits._ | ||
import org.scalatest.{AsyncWordSpec, Matchers} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
import scala.util.control.NoStackTrace | ||
|
||
class LoggingTestsJournal extends AsyncWordSpec with Matchers { | ||
|
||
implicit override def executionContext = ExecutionContext.Implicits.global | ||
|
||
import algebras._ | ||
|
||
"Logging Freestyle free integration journal" should { | ||
|
||
case object Cause extends Exception("kaboom") with NoStackTrace | ||
|
||
"allow a log message to be interleaved inside a program monadic flow" in { | ||
val program = for { | ||
a <- app.nonLogging.x | ||
_ <- app.loggingM.debug("Debug Message", sourceAndLineInfo = true) | ||
_ <- app.loggingM.debugWithCause("Debug Message", Cause) | ||
_ <- app.loggingM.error("Error Message") | ||
_ <- app.loggingM.errorWithCause("Error Message", Cause) | ||
_ <- app.loggingM.info("Info Message") | ||
_ <- app.loggingM.infoWithCause("Info Message", Cause) | ||
_ <- app.loggingM.warn("Warning Message") | ||
_ <- app.loggingM.warnWithCause("Warning Message", Cause) | ||
b <- FreeS.pure(1) | ||
} yield a + b | ||
program.interpret[Future] map { _ shouldBe 2 } | ||
} | ||
|
||
"not depend on MonadError, thus allowing use of Monads without MonadError, like Id, for test algebras" in { | ||
val program = for { | ||
a <- app.nonLogging.x | ||
_ <- app.loggingM.info("Info Message") | ||
_ <- app.loggingM.infoWithCause("Info Message", Cause) | ||
b <- FreeS.pure(1) | ||
} yield a + b | ||
program.interpret[TestAlgebra].run("configHere") shouldBe 2 | ||
} | ||
|
||
"allow injecting a Logger instance" in { | ||
val program = for { | ||
a <- FreeS.pure(1) | ||
_ <- app.loggingM.info("Info Message") | ||
_ <- app.loggingM.error("Error Message") | ||
b <- FreeS.pure(1) | ||
} yield a + b | ||
|
||
implicit val logger = journal.Logger("Potatoes") | ||
|
||
program | ||
.interpret[TestAlgebra] | ||
.run("configHere") shouldEqual 2 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not much in favor of having multiple
package
declarations. IMHO, animport
should be as explicit and restricted as reasonably possible. In this case, it is not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Changed.