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:Logi.GSeries.Service.LogiGSKService.java

/**
 * @param args the command line arguments
 *//*from   w w  w. jav  a2 s. c  o m*/
public static void main(String[] args) {
    SystemTray.DEBUG = false;

    Settings settings;
    if (IOOperations.currentSettingsExist()) {
        settings = IOOperations.loadCurrentSettingsObjectFromFile();
    } else {
        settings = new Settings();
    }

    LogiGSKService l = new LogiGSKService();
    if (settings.getShowSystemTray()) {
        l.showSystemTray();
    } else {
        l.hideSystemTray();
    }
    l.begin();
    try {
        String dataFolderPath = IOOperations.getLocalDataDirectoryPath();
        File dataFolder = new File(dataFolderPath);
        if (!dataFolder.exists()) {
            dataFolder.mkdir();
        }
        String logFolderPath = IOOperations.getLogDirectoryPath();
        File logFolder = new File(logFolderPath);
        if (!logFolder.exists()) {
            logFolder.mkdir();
        }
        FileHandler fileHandler = new FileHandler(logFolderPath + "LogiGSK.log", FILE_SIZE, 3);
        fileHandler.setLevel(Level.ALL);
        logger.setLevel(Level.ALL);
        logger.addHandler(fileHandler);
    } catch (IOException | SecurityException ex) {
        Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex);
    }
    int clientNumber = 0;
    ServerSocket listener = null;
    PropertyConfigurator.configure(LogiGSKService.class.getResource("/Logi/GSeries/Service/log4j.properties"));
    reloading = true;
    boolean firstTime = true;
    while (reloading) {
        listener = null;
        if (reloading && !firstTime) {
            if (IOOperations.currentSettingsExist()) {
                settings = IOOperations.loadCurrentSettingsObjectFromFile();
            } else {
                settings = new Settings();
            }
        }
        firstTime = false;
        reloading = false;
        running = true;
        try {
            listener = new ServerSocket(settings.getPort(), 0, InetAddress.getByName(null));
            while (running) {
                new Manager(listener.accept(), clientNumber++, logger).start();
            }
        } catch (IOException ex) {
            Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (listener != null) {
                try {
                    listener.close();
                } catch (IOException ex) {
                    Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
}

From source file:testingproject.TestingProjectDLB.java

public static void main(String[] args) {
    try {// www .j av  a  2s.  c om
        // List<String> dataList =getDLBResults("j","16/11/17");     // jayoda
        //  List<String> dataList =getDLBResults("sf","16/11/19");       // shanida
        List<String> dataList = getDLBResults("jj", "16/12/04"); // Galaxy Star
        //  List<String> dataList =getDLBResults("nj","16/11/18");               // Niyath Jaya
        // List<String> dataList =getDLBResults("df","16/11/4");             // Lagna Vasana ? lagne enne naa
        //  List<String> dataList =getDLBResults("sb","16/12/10");               // super ball
        //  List<String> dataList =getDLBResults("l","16/11/14");               // sanwardana lakshapathi
        //   List<String> dataList =getDLBResults("ks","16/11/18");             // Kotipathi Shanida

        for (String data : dataList) {
            System.out.println(data);
        }
    } catch (IOException ex) {
        Logger.getLogger(TestingProjectDLB.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:dependencies.DependencyResolving.java

/**
 * @param args the command line arguments
 *///from w ww. j  a  v a 2  s  .  co m
public static void main(String[] args) {
    // TODO code application logic here
    JSONParser parser = new JSONParser(); //we use JSONParser in order to be able to read from JSON file
    try { //here we declare the file reader and define the path to the file dependencies.json
        Object obj = parser.parse(new FileReader(
                "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\dependencies.json"));
        JSONObject project = (JSONObject) obj; //a JSON object containing all the data in the .json file
        JSONArray dependencies = (JSONArray) project.get("dependencies"); //get array of objects with key "dependencies"
        System.out.print("We need to install the following dependencies: ");
        Iterator<String> iterator = dependencies.iterator(); //define an iterator over the array "dependencies"
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        } //on the next line we declare another object, which parses a Parser object and reads from all_packages.json
        Object obj2 = parser.parse(new FileReader(
                "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\all_packages.json"));
        JSONObject tools = (JSONObject) obj2; //a JSON object containing all thr data in the file all_packages.json
        for (int i = 0; i < dependencies.size(); i++) {
            if (tools.containsKey(dependencies.get(i))) {
                System.out.println(
                        "In order to install " + dependencies.get(i) + ", we need the following programs:");
                JSONArray temporaryArray = (JSONArray) tools.get(dependencies.get(i)); //a temporary JSON array in which we store the keys and values of the dependencies
                for (i = 0; i < temporaryArray.size(); i++) {
                    System.out.println(temporaryArray.get(i));
                }
                ArrayList<Object> arraysOfJsonData = new ArrayList<Object>(); //an array in which we will store the keys of the objects, after we use the values and won't need them anymore
                for (i = 0; i < temporaryArray.size(); i++) {
                    System.out.println("Installing " + temporaryArray.get(i));
                }
                while (!temporaryArray.isEmpty()) {

                    for (Object element : temporaryArray) {

                        if (tools.containsKey(element)) {
                            JSONArray secondaryArray = (JSONArray) tools.get(element); //a temporary array within the scope of the if-statement
                            if (secondaryArray.size() != 0) {
                                System.out.println("In order to install " + element + ", we need ");
                            }
                            for (i = 0; i < secondaryArray.size(); i++) {
                                System.out.println(secondaryArray.get(i));
                            }

                            for (Object o : secondaryArray) {

                                arraysOfJsonData.add(o);
                                //here we create a file with the installed dependency
                                File file = new File(
                                        "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\installed_modules\\"
                                                + o);
                                if (file.createNewFile()) {
                                    System.out.println(file.getName() + " is installed!");
                                } else {
                                }
                            }
                            secondaryArray.clear();
                        }
                    }
                    temporaryArray.clear();
                    for (i = 0; i < arraysOfJsonData.size(); i++) {
                        temporaryArray.add(arraysOfJsonData.get(i));
                    }
                    arraysOfJsonData.clear();
                }
            }
        }
        Set<String> keys = tools.keySet(); // here we define a set of keys of the objects in all_packages.json
        for (String s : keys) {
            File file = new File(
                    "C:\\Users\\Vladimir\\Documents\\NetBeansProjects\\DependenciesResolving\\src\\dependencies\\installed_modules\\"
                            + s);
            if (file.createNewFile()) {
                System.out.println(file.getName() + " is installed.");
            } else {
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(DependencyResolving.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ParseException ex) {
        Logger.getLogger(DependencyResolving.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.bamamoto.mactools.png2icns.Scaler.java

public static void main(String[] args) {

    Options options = new Options();
    options.addOption("i", "input-filename", true,
            "Filename ofthe image containing the icon. The image should be a square with at least 1024x124 pixel in PNG format.");
    options.addOption("o", "iconset-foldername", true,
            "Name of the folder where the iconset will be stored. The extension .iconset will be added automatically.");
    String folderName;/*ww  w .  j av  a2 s.  c  o  m*/
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("i")) {
            if (new File(cmd.getOptionValue("i")).isFile()) {

                if (cmd.hasOption("o")) {
                    folderName = cmd.getOptionValue("o");
                } else {
                    folderName = "/tmp/noname.iconset";
                }

                if (!folderName.endsWith(".iconset")) {
                    folderName = folderName + ".iconset";
                }
                new File(folderName).mkdirs();

                BufferedImage source = ImageIO.read(new File(cmd.getOptionValue("i")));
                BufferedImage resized = resize(source, 1024, 1024);
                save(resized, folderName + "/icon_512x512@2x.png");
                resized = resize(source, 512, 512);
                save(resized, folderName + "/icon_512x512.png");
                save(resized, folderName + "/icon_256x256@2x.png");

                resized = resize(source, 256, 256);
                save(resized, folderName + "/icon_256x256.png");
                save(resized, folderName + "/icon_128x128@2x.png");

                resized = resize(source, 128, 128);
                save(resized, folderName + "/icon_128x128.png");

                resized = resize(source, 64, 64);
                save(resized, folderName + "/icon_32x32@2x.png");

                resized = resize(source, 32, 32);
                save(resized, folderName + "/icon_32x32.png");
                save(resized, folderName + "/icon_16x16@2x.png");

                resized = resize(source, 16, 16);
                save(resized, folderName + "/icon_16x16.png");

                Scaler.runProcess(new String[] { "/usr/bin/iconutil", "-c", "icns", folderName });
            }
        }

    } catch (IOException e) {
        System.out.println("Error reading image: " + cmd.getOptionValue("i"));
        e.printStackTrace();

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

From source file:com.mmone.gpdati.allotment.record.AllotmentRecordsListBuilder.java

public static void main(String[] args) {

    AllotmentLineProvvider afr = new AllotmentFileReader(
            "D:/tmp_desktop/scrigno-gpdati/FILE_DISPO__20160802.txt");
    AllotmentRecordsListBuilder arlb = new AllotmentRecordsListBuilder(afr);

    try {/*www  . ja  v  a  2 s . c om*/
        List<AllotmentRecord> records = arlb.getGroupedRecords();
        System.out.println("Records in list " + records.size());

        if (true)
            for (AllotmentRecord record : records) {
                System.out.println("---- " + record.getCompleteKey());
            }

        //MapUtils.debugPrint(System.out , "MAP", arlb.getMappedRecords());
        //MapUtils.debugPrint(System.out , "MAP", reg);
    } catch (Exception ex) {
        SoapUI.log.info(ex.getMessage());
        Logger.getLogger(AllotmentRecordsListBuilder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:jsonclient.JsonClient.java

public static void main(String args[]) {

    int EPS = 1;//  w  ww  .j  ava 2 s .co  m
    List<Place> countries = new ArrayList<Place>();
    List<Thread> threads = new ArrayList<Thread>();
    Country country;
    countries = getCountries();
    //CountrySearcher countrySearcher = null;
    Iterator<Place> itrCountry = countries.iterator();
    ExecutorService exec = Executors.newFixedThreadPool(4);

    while (itrCountry.hasNext()) {
        country = new Country(itrCountry.next());
        CountrySearcher cs = new CountrySearcher(country, EPS);
        threads.add(cs.thread);
        exec.execute(cs);
    }

    exec.shutdown();

    for (Thread th : threads)
        try {
            th.join();
        } catch (InterruptedException ex) {
            Logger.getLogger(JsonClient.class.getName()).log(Level.SEVERE, null, ex);
        }

}

From source file:at.tuwien.ifs.somtoolbox.models.GrowingSOM.java

/**
 * Method for stand-alone execution of map training. Options are:<br/>
 * <ul>/*from w  ww .j a  v a 2 s .  c  o m*/
 * <li>-h toggles HTML output</li>
 * <li>-l name of class implementing the labeling algorithm</li>
 * <li>-n number of labels to generate</li>
 * <li>-w name of weight vector file in case of training an already trained map</li>
 * <li>-m name of map description file in case of training an already trained map</li>
 * <li>--noDWM switch to not write the data winner mapping file</li>
 * <li>properties name of properties file, mandatory</li>
 * </ul>
 * 
 * @param args the execution arguments as stated above.
 */
public static void main(String[] args) {
    InputData data = null;
    FileProperties fileProps = null;

    GrowingSOM som = null;
    SOMProperties somProps = null;
    String networkModelName = "GrowingSOM";

    // register and parse all options
    JSAPResult config = OptionFactory.parseResults(args, OPTIONS);

    Logger.getLogger("at.tuwien.ifs.somtoolbox").info("starting" + networkModelName);

    int cpus = config.getInt("cpus", 1);
    int systemCPUs = Runtime.getRuntime().availableProcessors();
    // We do not use more CPUs than available!
    if (cpus > systemCPUs) {
        String msg = "Number of CPUs required exceeds number of CPUs available.";
        if (cpus > 2 * systemCPUs) {
            msg += "Limiting to twice the number of available processors: " + 2 * systemCPUs;
            cpus = 2 * systemCPUs;
        }
        Logger.getLogger("at.tuwien.ifs.somtoolbox").warning(msg);
    }
    GrowingLayer.setNO_CPUS(cpus);

    String propFileName = AbstractOptionFactory.getFilePath(config, "properties");
    String weightFileName = AbstractOptionFactory.getFilePath(config, "weightVectorFile");
    String mapDescFileName = AbstractOptionFactory.getFilePath(config, "mapDescriptionFile");
    String labelerName = config.getString("labeling", null);
    int numLabels = config.getInt("numberLabels", DEFAULT_LABEL_COUNT);
    boolean skipDataWinnerMapping = config.getBoolean("skipDataWinnerMapping", false);
    Labeler labeler = null;
    // TODO: use parameter for max
    int numWinners = config.getInt("numberWinners", SOMLibDataWinnerMapping.MAX_DATA_WINNERS);

    if (labelerName != null) { // if labeling then label
        try {
            labeler = AbstractLabeler.instantiate(labelerName);
            Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Instantiated labeler " + labelerName);
        } catch (Exception e) {
            Logger.getLogger("at.tuwien.ifs.somtoolbox")
                    .severe("Could not instantiate labeler \"" + labelerName + "\".");
            System.exit(-1);
        }
    }

    if (weightFileName == null) {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Training a new SOM.");
    } else {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Further training of an already trained SOM.");
    }

    try {
        fileProps = new FileProperties(propFileName);
        somProps = new SOMProperties(propFileName);
    } catch (PropertiesException e) {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").severe(e.getMessage() + " Aborting.");
        System.exit(-1);
    }

    data = getInputData(fileProps);

    if (weightFileName == null) {
        som = new GrowingSOM(data.isNormalizedToUnitLength(), somProps, data);
    } else {
        try {
            som = new GrowingSOM(new SOMLibFormatInputReader(weightFileName, null, mapDescFileName));
        } catch (Exception e) {
            Logger.getLogger("at.tuwien.ifs.somtoolbox").severe(e.getMessage() + " Aborting.");
            System.exit(-1);
        }
    }

    if (somProps.getDumpEvery() > 0) {
        IntermediateSOMDumper dumper = som.new IntermediateSOMDumper(fileProps);
        som.layer.setTrainingInterruptionListener(dumper, somProps.getDumpEvery());
    }

    // setting input data so it is accessible by map output
    som.setSharedInputObjects(new SharedSOMVisualisationData(null, null, null, null,
            fileProps.vectorFileName(true), fileProps.templateFileName(true), null));
    som.getSharedInputObjects().setData(SOMVisualisationData.INPUT_VECTOR, data);

    som.train(data, somProps);

    if (labelerName != null) { // if labeling then label
        labeler.label(som, data, numLabels);
    }

    try {
        SOMLibMapOutputter.write(som, fileProps.outputDirectory(), fileProps.namePrefix(false), true, somProps,
                fileProps);
    } catch (IOException e) { // TODO: create new exception type
        Logger.getLogger("at.tuwien.ifs.somtoolbox").severe("Could not open or write to output file "
                + fileProps.namePrefix(false) + ": " + e.getMessage());
        System.exit(-1);
    }
    if (!skipDataWinnerMapping) {
        numWinners = Math.min(numWinners, som.getLayer().getXSize() * som.getLayer().getYSize());
        try {
            SOMLibMapOutputter.writeDataWinnerMappingFile(som, data, numWinners, fileProps.outputDirectory(),
                    fileProps.namePrefix(false), true);
        } catch (IOException e) {
            Logger.getLogger("at.tuwien.ifs.somtoolbox").severe("Could not open or write to output file "
                    + fileProps.namePrefix(false) + ": " + e.getMessage());
            System.exit(-1);
        }
    } else {
        Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Skipping writing data winner mapping file");
    }

    if (config.getBoolean("htmlOutput") == true) {
        try {
            new HTMLOutputter().write(som, fileProps.outputDirectory(), fileProps.namePrefix(false));
        } catch (IOException e) { // TODO: create new exception type
            Logger.getLogger("at.tuwien.ifs.somtoolbox").severe("Could not open or write to output file "
                    + fileProps.namePrefix(false) + ": " + e.getMessage());
            System.exit(-1);
        }
    }

    Logger.getLogger("at.tuwien.ifs.somtoolbox").info("finished" + networkModelName + "("
            + som.getLayer().getGridLayout() + ", " + som.getLayer().getGridTopology() + ")");
}

From source file:edu.ifpb.pos.restletclient.CommandLineApp.java

public static void main(String[] args) {
    try {//www  .j a va2 s  .  c  o  m
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(getOp(), args);
        execute(line);
    } catch (ParseException ex) {
        System.out.println("ERROR: " + ex.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(CommandLineApp.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:eu.edisonproject.training.execute.Main.java

public static void main(String args[]) {
    Options options = new Options();
    Option operation = new Option("op", "operation", true,
            "type of operation to perform. " + "For term extraction use 'x'.\n"
                    + "Example: -op x -i E-COCO/documentation/sampleTextFiles/databases.txt "
                    + "-o E-COCO/documentation/sampleTextFiles/databaseTerms.csv"
                    + "For word sense disambiguation use 'w'.\n"
                    + "Example: -op w -i E-COCO/documentation/sampleTextFiles/databaseTerms.csv "
                    + "-o E-COCO/documentation/sampleTextFiles/databse.avro\n"
                    + "For tf-idf vector extraction use 't'.\n" + "For running the apriori algorithm use 'a'");
    operation.setRequired(true);/*w w  w  .  j  a v  a 2  s .co  m*/
    options.addOption(operation);

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(true);
    options.addOption(input);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(true);
    options.addOption(output);

    Option popertiesFile = new Option("p", "properties", true, "path for a properties file");
    popertiesFile.setRequired(false);
    options.addOption(popertiesFile);

    Option termsFile = new Option("t", "terms", true, "terms file");
    termsFile.setRequired(false);
    options.addOption(termsFile);

    String helpmasg = "Usage: \n";
    for (Object obj : options.getOptions()) {
        Option op = (Option) obj;
        helpmasg += op.getOpt() + ", " + op.getLongOpt() + "\t Required: " + op.isRequired() + "\t\t"
                + op.getDescription() + "\n";
    }

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        String propPath = cmd.getOptionValue("properties");
        if (propPath == null) {
            prop = ConfigHelper
                    .getProperties(".." + File.separator + "etc" + File.separator + "configure.properties");
        } else {
            prop = ConfigHelper.getProperties(propPath);
        }
        //            ${user.home}

        switch (cmd.getOptionValue("operation")) {
        case "x":
            termExtraction(cmd.getOptionValue("input"), cmd.getOptionValue("output"));
            break;
        case "w":
            wsd(cmd.getOptionValue("input"), cmd.getOptionValue("output"));
            break;
        case "t":
            calculateTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("output"));
            break;
        //                case "tt":
        //                    calculateTermTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("terms"), cmd.getOptionValue("output"));
        //                    break;
        case "a":
            apriori(cmd.getOptionValue("input"), cmd.getOptionValue("output"));
            break;
        default:
            System.out.println(helpmasg);
        }

    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex);
    }
}

From source file:mecard.BImportCustomerLoader.java

/**
 * Runs the entire process of loading customer bimport files as a timed 
 * process such as cron or Windows scheduler.
 * @param args //  w  ww.j a  v  a2 s.  co  m
 */
public static void main(String args[]) {
    // First get the valid options
    Options options = new Options();
    // add t option c to config directory true=arg required.
    options.addOption("c", true,
            "Configuration file directory path, include all sys dependant dir seperators like '/'.");
    // add v option v for server version.
    options.addOption("v", false, "Metro server version information.");
    options.addOption("d", false, "Outputs debug information about the customer load.");
    options.addOption("U", false,
            "Execute upload of customer accounts, otherwise just cleans up the directory.");
    options.addOption("p", true,
            "Path to PID file. If present back off and wait for reschedule customer load.");
    options.addOption("a", false, "Maximum age of PID file before warning (in minutes).");
    try {
        // parse the command line.
        CommandLineParser parser = new BasicParser();
        CommandLine cmd;
        cmd = parser.parse(options, args);
        if (cmd.hasOption("v")) {
            System.out.println("Metro (MeCard) server version " + PropertyReader.VERSION);
            return; // don't run if user just wants version.
        }
        if (cmd.hasOption("U")) {
            uploadCustomers = true;
        }
        if (cmd.hasOption("p")) // location of the pidFile, default is current directory (relative to jar location).
        {
            pidDir = cmd.getOptionValue("p");
            if (pidDir.endsWith(File.separator) == false) {
                pidDir += File.separator;
            }
        }
        if (cmd.hasOption("d")) // debug.
        {
            debug = true;
        }
        if (cmd.hasOption("a")) {
            try {
                maxPIDAge = Integer.parseInt(cmd.getOptionValue("a"));
            } catch (NumberFormatException e) {
                System.out.println("*Warning: the value used on the '-a' flag, '" + cmd.getOptionValue("a")
                        + "' cannot be " + "converted to an integer and is therefore an illegal value for "
                        + "maximum PID file age. Maximum PID age set to: " + maxPIDAge + " minutes.");
            }
        }
        // get c option value
        String configDirectory = cmd.getOptionValue("c");
        PropertyReader.setConfigDirectory(configDirectory);
        BImportCustomerLoader loader = new BImportCustomerLoader();
        loader.run();
    } catch (ParseException ex) {
        String msg = new Date()
                + "Unable to parse command line option. Please check your service configuration.";
        if (debug) {
            System.out.println("DEBUG: request for invalid command line option.");
        }
        Logger.getLogger(MetroService.class.getName()).log(Level.SEVERE, msg, ex);
        System.exit(899); // 799 for mecard
    } catch (NumberFormatException ex) {
        String msg = new Date() + "Request for invalid -a command line option.";
        if (debug) {
            System.out.println("DEBUG: request for invalid -a command line option.");
            System.out.println("DEBUG: value set to " + maxPIDAge);
        }
        Logger.getLogger(MetroService.class.getName()).log(Level.WARNING, msg, ex);
    }
    System.exit(0);
}