Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does it print the same log twice?

I have to do an .upperCase() through a formatter, but I don’t understand why it prints the same message but without the upper, since I have established that it uses only that.

I am using java util test.

public DatabaseAccessProxy(String pass, DatabaseAccess database) throws SecurityException, IOException {
        this.logged = false;
        this.pass = pass;
        this.database = database;
        manejador = new ConsoleHandler();   
        fileManejador = new FileHandler("C:/Users/ignac/OneDrive/Escritorio/OO2/Practica 6/logs");
        manejador.setFormatter(new ShoutingSimpleFomatter());
        fileManejador.setFormatter(new JSONFormater());
        Logger.getLogger("app.main").addHandler(manejador);
    }
public class ShoutingSimpleFomatter extends SimpleFormatter {
    
    @Override
    public String format(LogRecord record) {
        return super.format(record).toUpperCase();
    }
    
}

Output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY INSERTNEWROW
ADVERTENCIA: ACCESO VALIDO PARA LA INSERCION!
may. 25, 2022 8:06:42 P. M. ar.edu.unlp.info.oo2.accesobd.DatabaseAccessProxy insertNewRow
ADVERTENCIA: Acceso valido para la insercion!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY GETSEARCHRESULTS
INFORMACIÓN: ACCESO VALIDO PARA LA BUSQUEDA!
may. 25, 2022 8:06:42 P. M. ar.edu.unlp.info.oo2.accesobd.DatabaseAccessProxy getSearchResults
INFORMACIÓN: Acceso valido para la busqueda!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY GETSEARCHRESULTS
INFORMACIÓN: ACCESO VALIDO PARA LA BUSQUEDA!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY GETSEARCHRESULTS
INFORMACIÓN: ACCESO VALIDO PARA LA BUSQUEDA!
may. 25, 2022 8:06:42 P. M. ar.edu.unlp.info.oo2.accesobd.DatabaseAccessProxy getSearchResults
INFORMACIÓN: Acceso valido para la busqueda!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY GETSEARCHRESULTS
INFORMACIÓN: ACCESO VALIDO PARA LA BUSQUEDA!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY GETSEARCHRESULTS
INFORMACIÓN: ACCESO VALIDO PARA LA BUSQUEDA!
may. 25, 2022 8:06:42 P. M. ar.edu.unlp.info.oo2.accesobd.DatabaseAccessProxy getSearchResults
INFORMACIÓN: Acceso valido para la busqueda!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY LOGIN
GRAVE: ACCESO INVALIDO A LA BASE DE DATOS!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY LOGIN
GRAVE: ACCESO INVALIDO A LA BASE DE DATOS!
MAY. 25, 2022 8:06:42 P. M. AR.EDU.UNLP.INFO.OO2.ACCESOBD.DATABASEACCESSPROXY LOGIN
GRAVE: ACCESO INVALIDO A LA BASE DE DATOS!
may. 25, 2022 8:06:42 P. M. ar.edu.unlp.info.oo2.accesobd.DatabaseAccessProxy login
GRAVE: Acceso invalido a la base de datos!

>Solution :

You can remove unwanted handlers by calling getHandlers() and iterating through that list, calling removeHandler() on any you don’t want. The default handlers are normally added at the root logger which is named "" (an empty string).

public class LoggerHandlers {
   
   public static void main( String[] args ) {
      // clean slate, remove all
      Handler[] handlers = Logger.getLogger( "" ).getHandlers();
      for( Handler h : handlers )
         Logger.getLogger( "" ).removeHandler( h );
      Logger.getLogger( "" ).warning( "Test" );
   }
   
}

However, this is normally a very bad idea. It prevents a system operator ("sysop") from externally configuring your application. This is a very user hostile app. Use this only during debugging when you have no other choice.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading