Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Logging statement says Cannot Find Symbol

Tags:

java

slf4j

private static final Logger LOGGER = LoggerFactory.getLogger(Updater.class);

I am using SLF4J and Logback

When I try to log statements

LOGGER.info("{}:{}:{}", one, two, three)

it says

cannot find symbol method info(java.lang.String,java.lang.String,java.lang.String,java.lang.String)

Is there not any way I can log more than two variables in a single info statement?

like image 467
daydreamer Avatar asked Dec 26 '22 15:12

daydreamer


2 Answers

You must upgrade SLF4J to 1.7 which includes Logger.info(java.lang.String, java.lang.Object...) varargs method. See Bug 31 - Varargs for Logger methods fixed after six years worth of discussion.

Prior to 1.7 you must surround arguments with Object[] if you are using more than two:

LOGGER.info("{}:{}:{}", new Object[] {one, two, three})

See also

  • Is there a Java 1.5 varargs API for slf4j yet?
like image 54
Tomasz Nurkiewicz Avatar answered Jan 08 '23 02:01

Tomasz Nurkiewicz


You might be using an old version of slf4j.

In previous version you could only log up to 2 parameters in this way, but newer version can take any number of parameters.

like image 37
Augusto Avatar answered Jan 08 '23 02:01

Augusto