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:comparetopics.CompareTwoGroupTopics.java

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    System.out.println("please input the path for File1: ");
    String filepath1 = sc.nextLine();
    System.out.println("please input the path for File2: ");
    String filepath2 = sc.nextLine();

    try {/*from  www.  ja  v a  2  s  . c  o m*/
        File file1 = new File(filepath1);
        File file2 = new File(filepath2);
        System.out.println("File1: " + filepath1);
        System.out.println("File2: " + filepath2);

        if (!file1.exists()) {
            System.out.println("File1 isn't exist");
        } else if (!file2.exists()) {
            System.out.println("File2 isn't exist");
        } else {
            try (InputStream in1 = new FileInputStream(file1.getPath());
                    BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1))) {

                String line1 = null;
                int lineNr1 = -1;
                while ((line1 = reader1.readLine()) != null) {
                    ++lineNr1;

                    int lineNr2 = -1;
                    String line2 = null;
                    try (InputStream in2 = new FileInputStream(file2.getPath());
                            BufferedReader reader2 = new BufferedReader(new InputStreamReader(in2))) {
                        while ((line2 = reader2.readLine()) != null) {
                            ++lineNr2;
                            compareTwoGroups(line1, line2, lineNr1, lineNr2);
                        }
                    }
                    System.out.println();
                }
            }
        }

    } catch (IOException ex) {
        Logger.getLogger(CompareTopics.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.muni.fi.pa165.survive.rest.client.SurviveRESTClient.java

public static void main(String[] args) {

    File file = new File("err.txt");
    FileOutputStream fos = null;/*w  w w.ja v a  2 s.c  o m*/
    try {
        fos = new FileOutputStream(file);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(SurviveRESTClient.class.getName()).log(Level.SEVERE, null, ex);
    }
    PrintStream ps = new PrintStream(fos);
    System.setErr(ps);

    CommandLineParser parser = new PosixParser();
    Options options = OptionsProvider.getInstance().getOptions();

    try {
        CommandLine line = parser.parse(options, args);
        List<String> validate = CommandLineValidator.validate(line);
        if (!validate.isEmpty()) {
            System.out.println("The following errors occured when parsing the command:");

            for (String string : validate) {
                System.out.println(string);
            }

            System.out.println("");
            printHelp(options);
            System.exit(1);
        }

        if (line.hasOption("h")) {
            printHelp(options);
            System.exit(0);
        }

        CustomRestService crudService;

        String operation = line.getOptionValue("o");

        // weapon mode
        if (line.hasOption("w")) {
            crudService = new WeaponServiceImpl();
            switch (operation) {
            case "C": {
                WeaponDto dto = DtoBuilder.getWeaponDto(line);
                Object byId = crudService.create(dto);
                printEntity(crudService.getResponse(), "Creating a weapon", byId);
                break;
            }
            case "R": {
                Long id = Long.parseLong(line.getOptionValue("i"));
                Object byId = crudService.getById(id);
                printEntity(crudService.getResponse(), "Reading a weapon with id " + id, byId);
                break;
            }
            case "U": {

                WeaponDto dto = DtoBuilder.getWeaponDto(line);
                Object byId = crudService.update(dto);
                printEntity(crudService.getResponse(), "Updating a weapon with id " + line.getOptionValue("i"),
                        byId);

                break;
            }
            case "D": {
                Long id = Long.parseLong(line.getOptionValue("i"));
                Response delete = crudService.delete(id);
                printEntity(crudService.getResponse(), "Deleting a weapon with id " + line.getOptionValue("i"),
                        crudService.getResponse().getStatusInfo());
                break;
            }
            case "A":
                List<AbstractDto> all = crudService.getAll();
                printEntities(crudService.getResponse(), "Reading all weapons", all);

                break;
            }
        } else if (line.hasOption("a")) {
            crudService = new AreaServiceImpl();
            switch (operation) {
            case "C": {
                AreaDto dto = DtoBuilder.getAreaDto(line);
                Object byId = crudService.create(dto);
                printEntity(crudService.getResponse(), "Creating an area", byId);
                break;
            }
            case "R": {
                Long id = Long.parseLong(line.getOptionValue("i"));
                Object byId = crudService.getById(id);
                printEntity(crudService.getResponse(), "Reading an area with id " + id, byId);
                break;
            }
            case "U": {
                AreaDto dto = DtoBuilder.getAreaDto(line);
                Object byId = crudService.update(dto);
                printEntity(crudService.getResponse(), "Updating an area with id " + line.getOptionValue("i"),
                        byId);
                break;
            }
            case "D": {
                Long id = Long.parseLong(line.getOptionValue("i"));
                Object byId = crudService.delete(id);
                printEntity(crudService.getResponse(), "Deleting an area with id " + line.getOptionValue("i"),
                        crudService.getResponse().getStatusInfo());
                break;
            }
            case "A":
                List<AbstractDto> all = crudService.getAll();
                printEntities(crudService.getResponse(), "Reading all areas", all);
                break;
            }
        } else {
            printHelp(options);
        }
    } catch (ParseException ex) {
        System.out.println(ex.getMessage());
        printHelp(options);
        System.exit(1);
    } catch (NumberFormatException ex) {
        System.out.println(ex.getMessage());
        printHelp(options);
        System.exit(2);
    } catch (MessageBodyProviderNotFoundException ex) {
        System.out.println("Couldn't connect to the server! Please make sure that the server side is running.");
        System.exit(3);
    } catch (ProcessingException ex) {
        System.out.println("Couldn't connect to the server! Please make sure that the server side is running.");
        System.exit(4);
    } catch (Exception ex) {
        System.out.println(
                "There was an error when connecting to the server. Please make sure that the server side is running.");
    }
}

From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java

public static void main(String[] args) {
    try {// w  ww .j a va  2s .co m
        //new SendHtmlFormatedEmail().sendingHtml();
        String assunto = "";
        Mensagem msg = new Mensagem();
        // localizando a mensagem
        msg = new BusinessDelegate().getMensagem(new BigDecimal(61));
        assunto = msg.getAssunto();
        new SendHtmlFormatedEmail().sendingHtml("belchiorpalma@gmail.com", "Belchior", assunto, 2);
    } catch (Exception ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:downloadwolkflow.getWorkFlowList.java

public static void main(String args[]) {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    String[] pageList = getPageList();
    System.out.println(pageList.length);
    for (int i = 1; i < pageList.length; i++) {
        System.out.println(pageList[i]);
        System.out.println("---------------------------------------------------------------------------");
        HttpGet httpget = new HttpGet(pageList[i]);
        try {//from   w w  w .  j av a2  s .co  m
            HttpResponse response = httpclient.execute(httpget);
            String page = EntityUtils.toString(response.getEntity());
            Document mainDoc = Jsoup.parse(page);
            Elements resultList = mainDoc.select("div.resource_list_item");
            for (int j = 0; j < resultList.size(); j++) {
                Element workflowResult = resultList.get(j);
                Element detailInfo = workflowResult.select("div.main_panel").first().select("p.title.inline")
                        .first().select("a").first();
                String detailUrl = "http://www.myexperiment.org" + detailInfo.attributes().get("href")
                        + ".html";
                System.out.println(detailUrl);
                downloadWorkFlow(detailUrl, httpclient);
                Thread.sleep(1000);
            }
        } catch (IOException ex) {
            Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    try {
        httpclient.close();
    } catch (IOException ex) {
        Logger.getLogger(getWorkFlowList.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:de.pniehus.odal.App.java

public static void main(String[] args) throws IOException {
    List<Filter> filters = new ArrayList<Filter>();
    filters.add(new RegexFilter());
    filters.add(new FileTypeFilter());
    filters.add(new KeywordFilter());
    filters.add(new BlacklistFilter());
    Profile p = parseArgs(args, filters);

    String fileName = "log-" + new Date().toString().replace(":", "-") + ".txt";
    fileName = fileName.replace(" ", "-");
    File logPath = new File(p.getLogDirectory() + fileName);

    if (!logPath.getParentFile().isDirectory() && !logPath.getParentFile().mkdirs()) {
        logPath = new File(fileName);
    }/*from  www  .  j a v a  2  s  . c om*/

    if (logPath.getParentFile().canWrite() || logPath.getParentFile().setWritable(true)) {
        SimpleLoggingSetup.configureRootLogger(logPath.getAbsolutePath(), p.getLogLevel(), !p.isSilent());
    } else {
        Logger root = Logger.getLogger("");

        for (Handler h : root.getHandlers()) { // Removing default console handlers
            if (h instanceof ConsoleHandler) {
                root.removeHandler(h);
            }
        }

        ConsolePrintLogHandler cplh = new ConsolePrintLogHandler();
        cplh.setFormatter(new ScribblerLogFormat(SimpleLoggingSetup.DEFAULT_DATE_FORMAT));
        root.addHandler(cplh);

        System.out.println("Unable to create log: insufficient permissions!");

    }

    Logger.getLogger("").setLevel(p.getLogLevel());
    mainLogger = Logger.getLogger(App.class.getCanonicalName());
    untrustedSSLSetup();
    mainLogger.info("Successfully intitialized ODAL");
    if (!p.isLogging())
        mainLogger.setLevel(Level.OFF);
    if (p.isWindowsConsoleMode() && !p.isLogging()) {
        Logger root = Logger.getLogger("");
        for (Handler h : root.getHandlers()) {
            if (h instanceof FileHandler) {
                root.removeHandler(h); // Removes FileHandler to allow console output through logging
            }
        }
    }
    OdalGui ogui = new OdalGui(p, filters);
}

From source file:GUI.ListOfOffres1.java

public static void main(final String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override//from   ww w.j  a  v a 2  s . c  om
        public void run() {
            WebLookAndFeel.install();
            WebLookAndFeel.setDecorateAllWindows(true);
            openPleaseWait();
            try {
                openListOfOffresFrame();
            } catch (IOException ex) {
                Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:com.googlecode.promnetpp.main.Main.java

/**
 * Main function (entry point for the tool).
 *
 * @param args Command-line arguments./*from  w w w  .  ja va 2 s.  c  om*/
 */
public static void main(String[] args) {
    //Prepare logging
    try {
        Handler fileHandler = new FileHandler("promnetpp-log.xml");
        Logger logger = Logger.getLogger("");
        logger.removeHandler(logger.getHandlers()[0]);
        logger.addHandler(fileHandler);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    String PROMNeTppHome = System.getenv("PROMNETPP_HOME");
    if (PROMNeTppHome == null) {
        String userDir = System.getProperty("user.dir");
        System.err.println("WARNING: PROMNETPP_HOME environment variable" + " not set.");
        System.err.println("PROMNeT++ will assume " + userDir + " as" + " home.");
        PROMNeTppHome = userDir;
    }
    System.setProperty("promnetpp.home", PROMNeTppHome);

    Logger.getLogger(Main.class.getName()).log(Level.INFO, "PROMNeT++ home" + " set to {0}",
            System.getProperty("promnetpp.home"));
    if (args.length == 1) {
        fileNameOrPath = args[0];
        configurationFilePath = PROMNeTppHome + "/default-configuration.xml";
    } else if (args.length == 2) {
        fileNameOrPath = args[0];
        configurationFilePath = args[1];
    } else {
        System.err.println("Invalid number of command-line arguments.");
        System.err.println("Usage #1: promnetpp.jar <PROMELA model>.pml");
        System.err.println("Usage #2: promnetpp.jar <PROMELA model>.pml" + " <configuration file>.xml");
        System.exit(1);
    }
    //We must have a file name or path at this point
    assert fileNameOrPath != null : "Unspecified file name or" + " path to file!";

    //Log basic info
    Logger.getLogger(Main.class.getName()).log(Level.INFO, "Running" + " PROMNeT++ from {0}",
            System.getProperty("user.dir"));
    //Final steps
    loadXMLFile();
    Verifier verifier = new StandardVerifier(fileNameOrPath);
    verifier.doVerification();
    assert verifier.isErrorFree() : "Errors reported during model" + " verification!";
    verifier.finish();
    buildAbstractSyntaxTree();
    Translator translator = new StandardTranslator();
    translator.init();
    translator.translate(abstractSyntaxTree);
    translator.finish();
}

From source file:luceneindexdemo.LuceneIndexDemo.java

public static void main(String[] args) {
    try {/*from   www .  j  ava2 s .  c o  m*/
        // TODO code application logic here
        //int a=10;            
        //System.out.println("Enter your user name: ");
        //createIndex();
        searchIndex("i am feeling bored");
        //System.out.println("rishav"+10);
    } catch (Exception ex) {
        Logger.getLogger(LuceneIndexDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.nubits.nubot.tests.TestRPC.java

public static void main(String[] args) {

    //Default values
    String custodian = Passwords.CUSTODIAN_PUBLIC_ADDRESS;
    String user = Passwords.NUD_RPC_USER;
    String pass = Passwords.NUD_RPC_PASS;
    double sell = 0;
    double buy = 0;
    //java -jar testRPC user pass custodian sell buy
    if (args.length == 5) {
        LOG.info("Reading input parameters");
        user = args[0];// ww w.  j ava  2  s. c  o  m
        pass = args[1];
        custodian = args[2];
        sell = Double.parseDouble(args[3]);
        buy = Double.parseDouble(args[4]);
    }

    Utils.loadProperties("settings.properties");

    TestRPC test = new TestRPC();

    test.setup(Constant.INTERNAL_EXCHANGE_PEATIO, custodian, Constant.NBT_BTC, user, pass);
    test.testCheckNudTask();
    try {
        Thread.sleep(2000);

    } catch (InterruptedException ex) {
        Logger.getLogger(TestRPC.class.getName()).log(Level.SEVERE, null, ex);
    }
    //test.testGetInfo();
    //test.testIsConnected();
    test.testSendLiquidityInfo(buy, sell, 1);
    //test.testGetLiquidityInfo();
    //test.testGetLiquidityInfo(Constant.SELL, Passwords.CUSTODIA_PUBLIC_ADDRESS);
    //test.testGetLiquidityInfo(Constant.BUY, Passwords.CUSTODIA_PUBLIC_ADDRESS);

    System.exit(0);

}

From source file:com.chigix.autosftp.Application.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(Option.builder("P").longOpt("port").hasArg().build())
            .addOption(Option.builder("h").longOpt("help").desc("Print this message").build())
            .addOption(Option.builder("i").argName("identity_file").hasArg().build());
    int port = 22;
    CommandLine line;//from   w  ww.j a v  a  2s  . c  o m
    try {
        line = new DefaultParser().parse(options, args);
    } catch (UnrecognizedOptionException ex) {
        System.err.println(ex.getMessage());
        return;
    } catch (ParseException ex) {
        Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("autosftp /path/to/watch [user@]host2:[file2]", options, true);
        return;
    }
    String givenPort;
    if (line.hasOption("port") && StringUtils.isNumeric(givenPort = line.getOptionValue("port"))) {
        port = Integer.valueOf(givenPort);
    }
    if (line.getArgs().length < 0) {
        System.err.println("Please provide a path to watch.");
        return;
    }
    localPath = Paths.get(line.getArgs()[0]);
    if (line.getArgs().length < 1) {
        System.err.println("Please provide remote ssh information.");
        return;
    }
    SshAddressParser addressParse;
    try {
        addressParse = new SshAddressParser().parse(line.getArgs()[1]);
    } catch (SshAddressParser.InvalidAddressException ex) {
        System.err.println(ex.getMessage());
        return;
    }
    if (addressParse.getDefaultDirectory() != null) {
        remotePath = Paths.get(addressParse.getDefaultDirectory());
    }
    try {
        sshSession = new JSch().getSession(addressParse.getUsername(), addressParse.getHost(), port);
    } catch (JSchException ex) {
        Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    try {
        sshOpen();
    } catch (JSchException ex) {
        Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
        sshClose();
    }
    System.out.println("Remote Default Path: " + remotePath);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            sshClose();
            System.out.println("Bye~~~");
        }

    });
    try {
        watchDir(Paths.get(line.getArgs()[0]));
    } catch (Exception ex) {
        Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
    }
}