Example usage for java.util.logging Logger getLogger

List of usage examples for java.util.logging Logger getLogger

Introduction

In this page you can find the example usage for java.util.logging Logger getLogger.

Prototype




@CallerSensitive
public static Logger getLogger(String name) 

Source Link

Document

Find or create a logger for a named subsystem.

Usage

From source file:Person.java

public static void main(String args[]) {
    Logger logger = Logger.getLogger("your.logging");
    AgeFilter filter = new AgeFilter();
    logger.setFilter(filter);/*from   ww  w .jav  a 2 s  . com*/
    Person person = new Person("YourName", 32);
    logger.log(Level.INFO, "Person has age " + person.getAge(), person);
}

From source file:di.uniba.it.tee2.wiki.TestWikiIterator.java

/**
 * @param args the command line arguments
 *///www .ja  v  a  2 s. c om
public static void main(String[] args) {
    try {
        WikipediaDumpIterator it = new WikipediaDumpIterator(new File(args[0]), "UTF-8");
        while (it.hasNext()) {
            WikiPage page = it.next();
            System.out.println(page.getWikiID());
            System.out.println(page.getRevisionID());
            System.out.println(page.getTitle());
            System.out.println();
        }
    } catch (XMLStreamException | CompressorException | IOException ex) {
        Logger.getLogger(TestWikiIterator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:MyHtmlFormatter.java

public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    FileHandler fh = new FileHandler("mylog.html");
    fh.setFormatter(new MyHtmlFormatter());
    logger.addHandler(fh);/*  ww  w . j a v a2 s  . co m*/

    logger.setLevel(Level.ALL);
    logger.severe("my severe message");
    logger.info("my info message");
    logger.entering("Main class", "myMethod", new Object[] { "para1", "para2" });
}

From source file:HTMLFormatter.java

public static void main(String args[]) throws Exception {
    LogManager lm = LogManager.getLogManager();
    Logger parentLogger, childLogger;
    FileHandler xml_handler = new FileHandler("log_output.xml");
    FileHandler html_handler = new FileHandler("log_output.html");
    parentLogger = Logger.getLogger("ParentLogger");
    childLogger = Logger.getLogger("ParentLogger.ChildLogger");

    lm.addLogger(parentLogger);/*from  w  w  w  . j a v a 2  s. c o  m*/

    lm.addLogger(childLogger);

    parentLogger.setLevel(Level.WARNING);
    childLogger.setLevel(Level.ALL);
    xml_handler.setFormatter(new XMLFormatter());
    html_handler.setFormatter(new HTMLFormatter());

    parentLogger.addHandler(xml_handler);
    childLogger.addHandler(html_handler);

    childLogger.log(Level.FINE, "This is a fine log message");
    childLogger.log(Level.SEVERE, "This is a severe log message");
    xml_handler.close();
    html_handler.close();
}

From source file:edu.eci.cosw.samples.logic.Main.java

public static void main(String[] args) {
    ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
    ServiceFacade sf = ac.getBean(ServiceFacade.class);
    List<Cliente> clientes = null;
    try {/*  w  w w.  j  av a2 s. co  m*/
        clientes = sf.clientesReportadosPorApellido("var");
    } catch (ClientEvaluationException ex) {
        System.out.println("Fallo consulta por apellido");
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (clientes != null) {
        for (Cliente c : clientes) {
            System.out.println(
                    c.getIdcliente() + " " + c.getNombre() + " " + c.getDireccion() + " " + c.getTelefono());
        }
    }
    try {
        //Registrar un nuevo cliente
        sf.registrarCliente(1072672, "Guillermo Alvarez", "Calle 3#3E-116", "1234567");
    } catch (ClientEvaluationException ex) {
        System.out.println("Fallo insercion");
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    //Crear un pedido
    Date d = new Date(2015 - 1900, 8, 23);
    int[] idProductos = { 1 };
    int[] cantidades = { 3 };
    sf.registrarPedido(1072672, idProductos, cantidades, d);
    //Mirar en la base de datos que se creo el pedido de este cliente     
    try {
        //Consulta Fallida
        sf.registrarCliente(333, "Luis Alvarez", "Calle 3E#3-116", "1234567");
    } catch (ClientEvaluationException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:nayan.netty.client.FileUploadClient.java

public static void main(String args[]) {

    for (int i = 0; i < CLIENT_COUNT; i++) {
        new Thread(new Runnable() {

            @Override//from w w  w. j  a va2 s.  c  om
            public void run() {
                try {
                    uploadFile();
                } catch (Exception ex) {
                    Logger.getLogger(FileUploadClient.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();

    }

}

From source file:net.freedom.gj.example.Main.java

public static void main(String[] args) {
    try {/*from   w  w  w. j av a  2  s.c om*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        Logger.getLogger(EmployeeView.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Welcome to EL entity mapper demonstration.\n");

    AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(
            new String[] { "net/freedom/gj/example/mapping/mapping-configuration.xml" });

    ctx.registerShutdownHook();

}

From source file:com.mycompany.webtestegit.util.TesteMail.java

public static void main(String[] args) {
    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail 
    try {//from  ww  w  .  j  a v a2s.c  om
        email.addTo("cfs.bsi@gmail.com", "Christian"); //destinatrio 
        email.setFrom("programacao.micromap@gmail.com", "Micromap"); // remetente 
        email.setSubject("Titulo do e-mail"); // assunto do e-mail 
        email.setMsg("Teste de Email utilizando commons-email"); //conteudo do e-mail 
        email.setAuthentication("ORIGEM", "SENHA");
        email.setSSLCheckServerIdentity(true);
        email.send(); //envia o e-mail
    } catch (EmailException ex) {
        Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    }

    //EMAIL HTML
    //        HtmlEmail email = new HtmlEmail();
    //
    //        try {
    //            email.setHostName("smtp.gmail.com");
    //            email.addTo("cfs.bsi@gmail.com", "Cfs");
    //            email.setFrom("programacao.micromap@gmail.com", "Micromap"); 
    //            email.setSubject("Teste de e-mail em formato HTML");   
    //
    //
    //            // adiciona uma imagem ao corpo da mensagem e retorna seu id 
    //            URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
    //            String cid = email.embed(url, "Apache logo");   
    //
    //            // configura a mensagem para o formato HTML 
    //            email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");   
    //
    //            // configure uma mensagem alternativa caso o servidor no suporte HTML 
    //            email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML");   
    //            email.setAuthentication("ORIGEM", "SENHA");
    //            
    //            // envia o e-mail 
    //            email.send();
    //        } catch (EmailException ex) {
    //            Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    //        } catch (MalformedURLException ex) {
    //            Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    //        }
}

From source file:com.google.cloud.trace.v1.TraceServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {/*  ww w .ja va 2  s  .  c  o m*/
        Options options = new Options();
        options.addOption("h", "help", false, "show usage");
        options.addOption(Option.builder().longOpt("project_id").desc("Project id").hasArg()
                .argName("PROJECT-ID").required(true).build());
        CommandLine cl = (new DefaultParser()).parse(options, args);
        if (cl.hasOption("help")) {
            HelpFormatter formater = new HelpFormatter();
            formater.printHelp("TraceServiceSmokeTest", options);
        }
        executeNoCatch(cl.getOptionValue("project_id"));
        System.out.println("OK");
    } catch (Exception e) {
        System.err.println("Failed with exception:");
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:com.google.cloud.dlp.v2beta1.DlpServiceSmokeTest.java

public static void main(String args[]) {
    Logger.getLogger("").setLevel(Level.WARNING);
    try {//ww  w .  j a v  a  2s.  c o m
        executeNoCatch();
        System.out.println("OK");
    } catch (Exception e) {
        System.err.println("Failed with exception:");
        e.printStackTrace(System.err);
        System.exit(1);
    }
}