8000 adds support for logging failures with traces by somdoron · Pull Request #9738 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

adds support for logging failures with traces #9738

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

Open
wants to merge 4 commits into
base: series/2.x
Choose a base branch
from
Open
Changes from all commits
Commits
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
150 changes: 150 additions & 0 deletions core/shared/src/main/scala/zio/ZIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
Exit.unit
}

/**
* Logs the specified failure at the current log level.
*/
def logFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
ZIO.logCause(Cause.fail(e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this change overall, but I wonder if users would expect this to capture a trace given it's not an explicit parameter. @kyri-petrou what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to have trace with default Empty, however scala only allow one overload with default params. So I had to split it into two overloads, one with error only and one with error and trace.

In total there are 3 overloads, one with error only, one with error and trace and one with message, error and trace with default parameter.

I'm fine with removing the first one with error only if it make it clearer.


/**
* Logs the specified failure with trace at the current log level.
*/
def logFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the current
* log level.
*/
def logFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logCause(message, Cause.fail(e, stackTrace))

/**
* Annotates each log in this effect with the specified log annotation.
*/
Expand Down Expand Up @@ -4195,6 +4216,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logDebugCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logDebugCause("", cause)

/**
* Logs the specified failure at the debug log level.
*/
def logDebugFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
ZIO.logDebugCause(Cause.fail(e, StackTrace.none))

/**
* Logs the specified failure with trace at the debug log level.
*/
def logDebugFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logDebugCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the debug log
* level.
*/
def logDebugFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logDebugCause(message, Cause.fail(e, stackTrace))

/**
* Logs the specified message at the error log level.
*/
Expand All @@ -4217,6 +4259,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logErrorCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logErrorCause("", cause)

/**
* Logs the specified failure as an error.
*/
def logErrorFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
ZIO.logErrorCause(Cause.fail(e))

/**
* Logs the specified failure with the trace as an error.
*/
def logErrorFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logErrorCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the error log
* level.
*/
def logErrorFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logErrorCause(message, Cause.fail(e, stackTrace))

/**
* Logs the specified message at the fatal log level.
*/
Expand All @@ -4239,6 +4302,30 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logFatalCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logFatalCause("", cause)

/**
* Logs the specified failure with optional trace as a fatal.
*/
/**
* Logs the specified failure as a fatal.
*/
def logFatalFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
ZIO.logFatalCause(Cause.fail(e))

/**
* Logs the specified failure with the trace as a fatal.
*/
def logFatalFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logFatalCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the fatal log
* level.
*/
def logFatalFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logFatalCause(message, Cause.fail(e, stackTrace))

/**
* Logs the specified message at the informational log level.
*/
Expand All @@ -4261,6 +4348,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logInfoCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logInfoCause("", cause)

/**
* Logs the specified failure as an informational.
*/
def logInfoFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
ZIO.logInfoCause(Cause.fail(e))

/**
* Logs the specified failure with the trace as an informational.
*/
def logInfoFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logInfoCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the fatal log
* level.
*/
def logInfoFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logInfoCause(message, Cause.fail(e, stackTrace))

/**
* Sets the log level for this effect.
* {{{
Expand Down Expand Up @@ -4319,6 +4427,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logTraceCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logTraceCause("", cause)

/**
* Logs the specified failure as a trace.
*/
def logTraceFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
logTraceFailure(e, StackTrace.none)

/**
* Logs the specified failure with trace at the trace log level.
*/
def logTraceFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logTraceCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the trace log
* level.
*/
def logTraceFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logTraceCause(message, Cause.fail(e, stackTrace))

/**
* Logs the specified message at the warning log level.
*/
Expand All @@ -4341,6 +4470,27 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
def logWarningCause(cause: => Cause[Any])(implicit trace: Trace): UIO[Unit] =
logWarningCause("", cause)

/**
* Logs the specified failure as a warning.
*/
def logWarningFailure(e: => Any)(implicit trace: Trace): UIO[Unit] =
logWarningFailure(e, StackTrace.none)

/**
* Logs the specified failure with trace as a warning.
*/
def logWarningFailure(e: => Any, stackTrace: => StackTrace)(implicit trace: Trace): UIO[Unit] =
ZIO.logWarningCause(Cause.fail(e, stackTrace))

/**
* Logs the specified message and failure with optional trace at the warning
* log level.
*/
def logWarningFailure(message: => String, e: => Any, stackTrace: => StackTrace = StackTrace.none)(implicit
trace: Trace
): UIO[Unit] =
ZIO.logWarningCause(message, Cause.fail(e, stackTrace))

/**
* Returns a memoized version of the specified effectual function.
*/
Expand Down
0