2

I tried to custom my logging using logging-profile, this is my standalone.xml logging-profile configuration:

<logging-profiles>
    <logging-profile name="PRUEBA">
        <console-handler name="CONSOLA">
            <level name="INFO"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <file-handler name="ARCHIVO">
            <level name="INFO"/>
            <file relative-to="jboss.server.log.dir" path="app.log"/>
        </file-handler>
        <logger category="py.com.myapp.controllers">
            <level name="INFO"/>
            <handlers>
                <handler name="ARCHIVO"/>
                <handler name="CONSOLA"/>
            </handlers>
        </logger>
        <formatter name="COLOR-PATTERN">
            <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </logging-profile>
 </logging-profiles>

This is the manifest.MF

Manifest-Version: 1.0
Class-Path:
Logging-Profile: PRUEBA

This is the prueba.java file

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

private Logger appLogger;

protected Logger getLogger() {
    if (appLogger == null) {
        appLogger = LoggerFactory.getLogger(Prueba.class);
    }
    return appLogger;
}

@RequestMapping(value = "/prueba")
public String prueba(ModelMap model{
    getLogger().error("****************PRUEBA***************");
}

But it does not log into the file app.log, it still logging in the server.log
Someone can help me?

Matt
  • 74,352
  • 26
  • 153
  • 180
  • Is this an EAR, WAR or JAR? Also make sure you `MANIFEST.MF` is in the `META-INF` directory. – James R. Perkins Jun 23 '15 at 15:59
  • I think the logger category was wrong, I changed the logger for a root logger and now it's logging. But i have another problem, now it is logging only the info. Do you know how to solve it? Thanks! – Norma Egusquiza Jun 23 '15 at 21:03
  • I wouldn't use a filter. Just set the `level` to the lowest level you want logged, e.g. `INFO`. Generally speaking it's best to set the `root-logger` to log at level `INFO` and the handlers should log to all levels. Then if you need a logger to log at `DEBUG` you just add the logger with a level of `DEBUG`. – James R. Perkins Jun 24 '15 at 17:58
  • Why I can't use a filter? When should I use a filter then? – Norma Egusquiza Jun 24 '15 at 23:03
  • You can, but it just extra overhead. With the filter you're using you're only going to see `INFO` and `ERROR` messages. No `WARN` messages. – James R. Perkins Jun 25 '15 at 16:08
  • The levels in order are: ALL, FINEST, FINER, TRACE, DEBUG, FINE, CONFIG, INFO, WARN, WARNING, ERROR, SEVERE, FATAL, OFF this is from [Wildfly levels](https://docs.jboss.org/author/display/WFLY8/Handlers#Handlers-level). "Message levels lower than this value will be discarded" If I use INFO level the ERROR level will be discarded. It should be logging those levels anyway with filter-spec. I don't understand what it's wrong with this logging-profile. Now, I'm logging using Per-deployment Logging with the logging.properties file and it works with the same configuration. – Norma Egusquiza Jun 25 '15 at 17:43
  • `INFO` is set to level 800 and `DEBUG` is set to 500. Which means if you log a `WARN` message (900) that's higher than `INFO` so it won't be discaded. So if you specify a level of `INFO` you'll get `INFO`, `WARN`, `WARNING`, `ERROR`, `SEVERE` and `FATAL`. Using the filter thought will change the result as you're say "Only log INFO and ERROR messages". – James R. Perkins Jun 26 '15 at 18:13
  • @NormaEgusquiza: Please do not edit your question to ask a different one. Ask a new question instead. – Matt Jul 14 '15 at 13:58
  • @JamesR.Perkins the MANIFEST.MF is in the /src/main/resources/META-INF directory. I turn on debug and I don't see "Logging profile *** found in ****" message. Do I have to define the manifest location in the pom.xml? – Norma Egusquiza Oct 26 '15 at 19:26
  • @JamesR.Perkins when I said "Now it's logging" 4 months ago I meant with "per-deployment-logging" option. Now I have time to try to change it for logging profile. – Norma Egusquiza Oct 26 '15 at 19:43
  • See https://docs.jboss.org/author/display/WFLY9/Logging+Configuration#LoggingConfiguration-LoggingProfiles for logging-profiles. – James R. Perkins Oct 26 '15 at 22:55
  • Maven was ignoring my MANIFEST.MF, I added the entry for the manifest in the pom.xml. Now works fine. Thanks! – Norma Egusquiza Oct 27 '15 at 17:11

2 Answers2

0

It should be working. Are you sure you are editing the correct file (standalone.xml, standalone-full.xml etc). Do any other changes on the logging profile work? You could also try adding <file-handler name="ARCHIVO" autoflush="true"> which is used in the standard configuration of wildfly

user140547
  • 7,750
  • 3
  • 28
  • 80
  • I think the logger category was wrong, I changed the logger for a root logger and now it's logging. But i have another problem, now it is logging only the info. Do you know how to solve it? Thanks! – Norma Egusquiza Jun 23 '15 at 21:03
0

" tag level name="INFO"/> should be changed to level name="DEBUG"/> this is for log level