Logger.info() cannot be used with primitive types
See original GitHub issueHello,
import com.typesafe.scalalogging.StrictLogging
new StrictLogging {
logger.info("2 + 2 == {}", new Integer(4)) // compiles
logger.info("2 + 2 == {}", 4) // fails to compile
}
The error is:
overloaded method value info with alternatives:
(marker: org.slf4j.Marker,message: String,args: AnyRef*)Unit <and>
(marker: org.slf4j.Marker,message: String)Unit <and>
(message: String,args: AnyRef*)Unit <and>
(message: String,cause: Throwable)Unit
cannot be applied to (String, Int)
Is there any reason for using AnyRef*
instead of Any*
in:
class Logger {
def info(message: String, args: AnyRef*): Unit = macro LoggerMacro.infoMessageArgs
}
If not, I can fix it and create a PR.
Issue Analytics
- State:
- Created 8 years ago
- Comments:15
Top Results From Across the Web
Logger.info() cannot be used with primitive types #38 - GitHub
I encountered the same problem and circumvented it by using Scala's String Interpolation feature http://docs.scala-lang.org/overviews/core/string-interpolation.
Read more >String Format and Logging primative types - Java
The problem is when calling String.format() with callerClass and args, Java Varargs creates a new array containing a string and an array, which ......
Read more >Logger info(String) method in Java with Examples
The info() method of a Logger class is used to Log an INFO message. This method is used to forward logs to all...
Read more >Logging HOWTO — Python 3.11.1 documentation
Multiple calls to getLogger() with the same name will return a reference to the same logger object. Loggers that are further down in...
Read more >Data Types in Java | Primitive and Non-Primitive Data Types
A boolean data type comprises of a bit of information and can store only true or false values. This data type is used...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually the string interpolation isn’t evaluated unless the logger is enabled! The logger macros converts
logger.debug
into a if statement that checks if debug is enabled before calling the logger.I encountered the same problem and circumvented it by using Scala’s String Interpolation feature http://docs.scala-lang.org/overviews/core/string-interpolation.html . When using sfl4j LoggerFactory’s logger directly similar problems occur as the one you describe above.