Companion object to Spy.
Attributes
Members list
Value members
Concrete methods
This method (and the related class Spy) is here only to enable the implicit spyFunc mechanism. It you declare the return from spyFunc as Unit, the compiler doesn't know where to look for the implicit function.
This method (and the related class Spy) is here only to enable the implicit spyFunc mechanism. It you declare the return from spyFunc as Unit, the compiler doesn't know where to look for the implicit function.
Value parameters
- x
-
ignored
Attributes
- Returns
-
a new Spy instance
Convenience method to get a logger for a class. By using this method, the caller does not need to import any logging classes.
Convenience method to get a logger for a class. By using this method, the caller does not need to import any logging classes.
Value parameters
- clazz
-
class for which the logger is required
Attributes
- Returns
-
a Logger
Get a println-type spyFunc that can be made an implicit val at the point of the spy method invocation so that spy invokes println statements instead of logging.
Get a println-type spyFunc that can be made an implicit val at the point of the spy method invocation so that spy invokes println statements instead of logging.
Value parameters
- ps
-
the PrintStream to use (defaults to System.out).
Attributes
- Returns
-
a spy function
This method is used in development/debug phase to "see" a string while returning Unit.
This method is used in development/debug phase to "see" a string while returning Unit.
It is recommended simply to import Spy._ before invoking this method.
CONSIDER renaming this method as debug and providing warn, info, etc. versions
Value parameters
- b
-
if true AND if spying is true, the spyFunc will be called (defaults to true)
- spyFunc
-
(implicit) the function to be called with a String based on w and x IF b && spying are true
- w
-
a String to be used as the prefix of the resulting message
Attributes
- Returns
-
the value of x
This method can be used if you have an expression you would like to be evaluated WITHOUT any spying going on. Bear in mind that this turns off ALL spying during the evaluation of x
This method can be used if you have an expression you would like to be evaluated WITHOUT any spying going on. Bear in mind that this turns off ALL spying during the evaluation of x
Type parameters
- X
-
the type of the expression
Value parameters
- x
-
the expression
Attributes
- Returns
-
the expression
This method is used in development/debug phase to "see" the values of expressions without altering the flow of the code.
This method is used in development/debug phase to "see" the values of expressions without altering the flow of the code.
The behavior implied by "see" is defined by the spyFunc. This could be a simple println (which is the default) or a SLF4J debug function or whatever.
The caller MUST provide an implicit value in scope for a Logger (unless the spyFunc has been explicitly defined to use some other non-logging mechanism, such as calling getPrintlnSpyFunc).
NOTE that there will be times when you cannot use spy, for example when yielding the result of a tail-recursive method. You will need to use log then instead.
Type parameters
- X
-
the type of the value.
Value parameters
- b
-
if true AND if spying is true, the spyFunc will be called (defaults to true). However, note that this is intended only for the situation where the default spyFunc is being used. If a logging spyFunc is used, then logging should be turned on/off at the class level via the logging configuration file.
- isEnabledFunc
-
(implicit) the function to be called to determine if spying is enabled -- by default this will be based on the (implicit) logger.
- message
-
(call-by-name) a String to be used as the prefix of the resulting message OR as the whole string where "{}" will be substituted by the value. Note that the message will only be evaluated if spying will actually occur, otherwise, since it is call-by-name, it will never be evaluated.
- spyFunc
-
(implicit) the function to be called (as a side-effect) with a String based on w and x IFF b && spying are true.
- x
-
(call-by-name) the value being spied on and which will be returned by this method; Note that since this is call-by-name, it is evaluated INSIDE the spy method. This allows the method to deal with exceptions in such a way that a message based on 'message' (and including the exception message rather than an actual X value, obviously) is logged as usual.
Attributes
- Returns
-
the value of x.
Concrete fields
This is pattern which, if found in the message, will be substituted for
This is pattern which, if found in the message, will be substituted for
Attributes
This is the global setting for whether to invoke the spyFunc of each spy invocation. However, each invocation can also turn spying off for itself. Normally it is true. Think of this as the red emergency button. Setting this to false turns all spying off everywhere.
This is the global setting for whether to invoke the spyFunc of each spy invocation. However, each invocation can also turn spying off for itself. Normally it is true. Think of this as the red emergency button. Setting this to false turns all spying off everywhere.
Attributes
Implicits
Implicits
For really quick-and-dirty spying, you can use this default Logger simply by importing Spy._
For really quick-and-dirty spying, you can use this default Logger simply by importing Spy._
Attributes
This is the default isEnabled function This method takes a Spy object (essentially a Unit) and returns a Boolean if the logger is enabled for debug.
This is the default isEnabled function This method takes a Spy object (essentially a Unit) and returns a Boolean if the logger is enabled for debug.
NOTE that it is necessary that this method takes a Spy, in the same way that the spyFunc must return a Spy -- so that the implicits can be found.
NOTE that if the logger parameter is null, then no logging is performed. This is another way to turn off logging.
Value parameters
- logger
-
an (implicit) logger (if null, then this method returns false)
- x
-
an instance of Spy
Attributes
- Returns
-
true if the logger is debugEnabled
This is the default spy function. NOTE that if the logger parameter is null, then no logging is performed. This is another way to turn off logging.
This is the default spy function. NOTE that if the logger parameter is null, then no logging is performed. This is another way to turn off logging.
Value parameters
- logger
-
an (implicit) logger (if null, then this method does nothing)
- s
-
the message to be output when spying
Attributes
- Returns
-
a Spy (that's to say nothing)