how can I supress the classnames in sl4j?
public class LogManager {
static Logger logger = LoggerFactory.getLogger(classname);
static void log(String sender, String msg) {
logger.info(sender + " - " + msg);
}
}
The output of this its something like this:
2018-05-23 16:15:41,000 [ 196598] WARN - [classname] - [sender] - [msg]
how can I remove the classname?
Other questions: Is there a way to remove the loglevel? What is the number "[ 196598]" in the string and how can it be removed?
If you are using Log4j you can use the org.apache.log4j.PatternLayout
to format the logging information.
conversionPattern
Sets the conversion pattern. Default is %r [%t] %p %c %x - %m%n
.
c
- Used to output the category of the logging event.
For example, for the category name "abc"
the pattern %c{2}
will output "bc".
C
- Used to output the fully qualified class name of the caller issuing the logging request.
For example, for the class name "org.apache.xyz.SomeClass"
, the pattern %C{1}
will output "SomeClass"
.
Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%-C{1}:%m%n
This is how you need to provide in the config file of log4j.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.