Example usage for java.util.logging Handler setFormatter

List of usage examples for java.util.logging Handler setFormatter

Introduction

In this page you can find the example usage for java.util.logging Handler setFormatter.

Prototype

public synchronized void setFormatter(Formatter newFormatter) throws SecurityException 

Source Link

Document

Set a Formatter .

Usage

From source file:org.apache.qpid.amqp_1_0.client.Util.java

protected Util(String[] args) {
    CommandLineParser cmdLineParse = new PosixParser();

    Options options = new Options();
    options.addOption("h", "help", false, "show this help message and exit");
    options.addOption(OptionBuilder.withLongOpt("host").withDescription("host to connect to (default 0.0.0.0)")
            .hasArg(true).withArgName("HOST").create('H'));
    options.addOption(/* w ww.j  a va 2 s.c o m*/
            OptionBuilder.withLongOpt("username").withDescription("username to use for authentication")
                    .hasArg(true).withArgName("USERNAME").create('u'));
    options.addOption(
            OptionBuilder.withLongOpt("password").withDescription("password to use for authentication")
                    .hasArg(true).withArgName("PASSWORD").create('w'));
    options.addOption(OptionBuilder.withLongOpt("port").withDescription("port to connect to (default 5672)")
            .hasArg(true).withArgName("PORT").create('p'));
    options.addOption(OptionBuilder.withLongOpt("frame-size").withDescription("specify the maximum frame size")
            .hasArg(true).withArgName("FRAME_SIZE").create('f'));
    options.addOption(OptionBuilder.withLongOpt("container-name").withDescription("Container name").hasArg(true)
            .withArgName("CONTAINER_NAME").create('C'));

    options.addOption(OptionBuilder.withLongOpt("ssl").withDescription("Use SSL").create('S'));

    options.addOption(
            OptionBuilder.withLongOpt("remote-hostname").withDescription("hostname to supply in the open frame")
                    .hasArg(true).withArgName("HOST").create('O'));

    if (hasBlockOption())
        options.addOption(
                OptionBuilder.withLongOpt("block").withDescription("block until messages arrive").create('b'));

    if (hasCountOption())
        options.addOption(
                OptionBuilder.withLongOpt("count").withDescription("number of messages to send (default 1)")
                        .hasArg(true).withArgName("COUNT").create('c'));
    if (hasModeOption())
        options.addOption(OptionBuilder.withLongOpt("acknowledge-mode")
                .withDescription("acknowledgement mode: AMO|ALO|EO (At Least Once, At Most Once, Exactly Once")
                .hasArg(true).withArgName("MODE").create('k'));

    if (hasSubjectOption())
        options.addOption(OptionBuilder.withLongOpt("subject").withDescription("subject message property")
                .hasArg(true).withArgName("SUBJECT").create('s'));

    if (hasSingleLinkPerConnectionMode())
        options.addOption(OptionBuilder.withLongOpt("single-link-per-connection")
                .withDescription("acknowledgement mode: AMO|ALO|EO (At Least Once, At Most Once, Exactly Once")
                .hasArg(false).create('Z'));

    if (hasFilterOption())
        options.addOption(OptionBuilder.withLongOpt("filter")
                .withDescription("filter, e.g. exact-subject=hello; matching-subject=%.a.#").hasArg(true)
                .withArgName("<TYPE>=<VALUE>").create('F'));

    if (hasTxnOption()) {
        options.addOption("x", "txn", false, "use transactions");
        options.addOption(
                OptionBuilder.withLongOpt("batch-size").withDescription("transaction batch size (default: 1)")
                        .hasArg(true).withArgName("BATCH-SIZE").create('B'));
        options.addOption(OptionBuilder.withLongOpt("rollback-ratio")
                .withDescription("rollback ratio - must be between 0 and 1 (default: 0)").hasArg(true)
                .withArgName("RATIO").create('R'));
    }

    if (hasLinkDurableOption()) {
        options.addOption("d", "durable-link", false, "use a durable link");
    }

    if (hasStdInOption())
        options.addOption("i", "stdin", false, "read messages from stdin (one message per line)");

    options.addOption(
            OptionBuilder.withLongOpt("trace").withDescription("trace logging specified categories: RAW, FRM")
                    .hasArg(true).withArgName("TRACE").create('t'));
    if (hasSizeOption())
        options.addOption(
                OptionBuilder.withLongOpt("message-size").withDescription("size to pad outgoing messages to")
                        .hasArg(true).withArgName("SIZE").create('z'));

    if (hasResponseQueueOption())
        options.addOption(
                OptionBuilder.withLongOpt("response-queue").withDescription("response queue to reply to")
                        .hasArg(true).withArgName("RESPONSE_QUEUE").create('r'));

    if (hasLinkNameOption()) {
        options.addOption(OptionBuilder.withLongOpt("link").withDescription("link name").hasArg(true)
                .withArgName("LINK").create('l'));
    }

    if (hasWindowSizeOption()) {
        options.addOption(OptionBuilder.withLongOpt("window-size").withDescription("credit window size")
                .hasArg(true).withArgName("WINDOW-SIZE").create('W'));
    }

    CommandLine cmdLine = null;
    try {
        cmdLine = cmdLineParse.parse(options, args);

    } catch (ParseException e) {
        printUsage(options);
        System.exit(-1);
    }

    if (cmdLine.hasOption('h') || cmdLine.getArgList().isEmpty()) {
        printUsage(options);
        System.exit(0);
    }
    _host = cmdLine.getOptionValue('H', "0.0.0.0");
    _remoteHost = cmdLine.getOptionValue('O', null);
    String portStr = cmdLine.getOptionValue('p', "5672");
    String countStr = cmdLine.getOptionValue('c', "1");

    _useSSL = cmdLine.hasOption('S');

    if (hasWindowSizeOption()) {
        String windowSizeStr = cmdLine.getOptionValue('W', "100");
        _windowSize = Integer.parseInt(windowSizeStr);
    }

    if (hasSubjectOption()) {
        _subject = cmdLine.getOptionValue('s');
    }

    if (cmdLine.hasOption('u')) {
        _username = cmdLine.getOptionValue('u');
    }

    if (cmdLine.hasOption('w')) {
        _password = cmdLine.getOptionValue('w');
    }

    if (cmdLine.hasOption('F')) {
        _filter = cmdLine.getOptionValue('F');
    }

    _port = Integer.parseInt(portStr);

    _containerName = cmdLine.getOptionValue('C');

    if (hasBlockOption())
        _block = cmdLine.hasOption('b');

    if (hasLinkNameOption())
        _linkName = cmdLine.getOptionValue('l');

    if (hasLinkDurableOption())
        _durableLink = cmdLine.hasOption('d');

    if (hasCountOption())
        _count = Integer.parseInt(countStr);

    if (hasStdInOption())
        _useStdIn = cmdLine.hasOption('i');

    if (hasSingleLinkPerConnectionMode())
        _useMultipleConnections = cmdLine.hasOption('Z');

    if (hasTxnOption()) {
        _useTran = cmdLine.hasOption('x');
        _batchSize = Integer.parseInt(cmdLine.getOptionValue('B', "1"));
        _rollbackRatio = Double.parseDouble(cmdLine.getOptionValue('R', "0"));
    }

    if (hasModeOption()) {
        _mode = AcknowledgeMode.ALO;

        if (cmdLine.hasOption('k')) {
            _mode = AcknowledgeMode.valueOf(cmdLine.getOptionValue('k'));
        }
    }

    if (hasResponseQueueOption()) {
        _responseQueue = cmdLine.getOptionValue('r');
    }

    _frameSize = Integer.parseInt(cmdLine.getOptionValue('f', "65536"));

    if (hasSizeOption()) {
        _messageSize = Integer.parseInt(cmdLine.getOptionValue('z', "-1"));
    }

    String categoriesList = cmdLine.getOptionValue('t');
    String[] categories = categoriesList == null ? new String[0] : categoriesList.split("[, ]");
    for (String cat : categories) {
        if (cat.equalsIgnoreCase("FRM")) {
            FRAME_LOGGER.setLevel(Level.FINE);
            Formatter formatter = new Formatter() {
                @Override
                public String format(final LogRecord record) {
                    return "[" + record.getMillis() + " FRM]\t" + record.getMessage() + "\n";
                }
            };
            for (Handler handler : FRAME_LOGGER.getHandlers()) {
                FRAME_LOGGER.removeHandler(handler);
            }
            Handler handler = new ConsoleHandler();
            handler.setLevel(Level.FINE);
            handler.setFormatter(formatter);
            FRAME_LOGGER.addHandler(handler);
        } else if (cat.equalsIgnoreCase("RAW")) {
            RAW_LOGGER.setLevel(Level.FINE);
            Formatter formatter = new Formatter() {
                @Override
                public String format(final LogRecord record) {
                    return "[" + record.getMillis() + " RAW]\t" + record.getMessage() + "\n";
                }
            };
            for (Handler handler : RAW_LOGGER.getHandlers()) {
                RAW_LOGGER.removeHandler(handler);
            }
            Handler handler = new ConsoleHandler();
            handler.setLevel(Level.FINE);
            handler.setFormatter(formatter);
            RAW_LOGGER.addHandler(handler);
        }
    }

    _args = cmdLine.getArgs();

}

From source file:cz.cas.lib.proarc.desa.SIP2DESATransporter.java

private Handler setupLogHandler(String fileName) {
    Handler handler;
    try {//from  w w  w  .  j a v a 2 s .c  o m
        checkDirectory(logRoot);
        handler = new FileHandler(logRoot + System.getProperty("file.separator") + fileName + ".txt", 0, 1,
                true);
        handler.setFormatter(new SimpleFormatter());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Logger.getLogger("").addHandler(handler);

    return handler;
}

From source file:com.ebixio.virtmus.stats.StatsLogger.java

/** Creates a log handler for the stats logging.
 * @param newLogSet An identifier: "A" or "B".
 *//*from w w w  .j  av  a 2s  .co m*/
private Handler makeLogHandler(String newLogSet) {
    Handler handler = null;
    try {
        String pattern = "VirtMus-" + newLogSet + "-%g.log";
        File logFile = getLogFile(pattern);
        handler = new FileHandler(logFile.getAbsolutePath(), 50 * 1000 * 1000, 10, true);
        handler.setFormatter(new XMLFormatter());
        handler.setEncoding("utf-8");
    } catch (IOException | SecurityException ex) {
        Log.log(ex);
    }
    return handler;
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/acceptfriend", method = RequestMethod.POST)
public String acceptfriend(Model model, @RequestParam(value = "id") int id) {
    try {/*from   ww w.jav  a  2s. c  om*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        FriendshipsDAO.acceptfriend(currentStudent.getStudentid(), id);
        logger.info("Approved friendship between " + currentStudent.getStudentid() + " and " + id);
        List<Students> friendrequests = StudentDAO.getFriendRequests(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friendrequests", friendrequests);
        logger.info("Friend requests updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentmanagefriends";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/rejectfriend", method = RequestMethod.POST)
public String rejectfriend(Model model, @RequestParam(value = "id") int id) {
    try {//from  www.  j a  v  a 2 s . c om
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        FriendshipsDAO.deletefriend(currentStudent.getStudentid(), id);
        logger.info("Rejected friendship between " + currentStudent.getStudentid() + " and " + id);
        List<Students> friendrequests = StudentDAO.getFriendRequests(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friendrequests", friendrequests);
        logger.info("Friend requests updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentmanagefriends";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/unfriend", method = RequestMethod.POST)
public String unfriend(Model model, @RequestParam(value = "id") int id) {
    try {/*from w w w  .j  a  va2 s . co m*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        FriendshipsDAO.deletefriend(currentStudent.getStudentid(), id);
        logger.info("Successfully deleted friendship between " + currentStudent.getStudentid() + " and " + id);
        List<Students> friends = StudentDAO.getFriends(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friends", friends);
        logger.info("Friends updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentdisplayfriends";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(Model model, @RequestParam(value = "firstName") String firstName,
        @RequestParam(value = "lastName") String lastName, @RequestParam(value = "email") String email,
        @RequestParam(value = "password") String password, @RequestParam(value = "school") String school) {
    try {/*from   w  ww . j av a2 s.com*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAccount.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        List<Schools> schools = SchoolDAO.allSchools();
        if (schools != null) {
            model.addAttribute("school", schools);
        }
        Students student = StudentDAO.getStudent(email);
        if (firstName.isEmpty() || lastName.isEmpty() || email.isEmpty() || password.isEmpty()) {
            model.addAttribute("fillout", "Please fill out all Required Fields");
            logger.info("A field was not filled.");
        } else if (student != null) {
            model.addAttribute("taken", "The email address is taken");
            logger.info("Email address was taken.");
        } else {
            StudentDAO.register(firstName, lastName, email, password, school);
            model.addAttribute("registered", "You have been successfully registered. Please Login");
            logger.info("Successfully registered an account with email " + email);
        }
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "index";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studenteditassigned", method = RequestMethod.GET)
public String editAssigned(Model model) {
    try {//  w ww.  ja  v  a2s.  c o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAssignedCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        List<Courses> courses = CourseDAO.getCoursesForStudent(currentStudent.getStudentid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<Scheduleblocks>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Courses for this student added to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studenteditassigned";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/addfriend", method = RequestMethod.POST)
public String addfriend(Model model, @RequestParam(value = "email") String email) {
    try {// w  w w.  j  a v  a  2s.c  o m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        Students friend = StudentDAO.getStudent(email);
        if (friend == null) {
            model.addAttribute("msg", "The email you have entered doesn't belong to any student");
            logger.info(email + " does not exist in database.");
        } else if (friend.getStudentid() == currentStudent.getStudentid()) {
            model.addAttribute("msg", "Can't friend yourself...");
            logger.info("This is your email.");
        } else if (friend.getSchoolid() != currentStudent.getSchoolid()) {
            model.addAttribute("msg", "Can not add a student from different school");
            logger.info("This student belongs to a different school");
        } else {
            model.addAttribute("msg", FriendshipsDAO.addfriend(friend, currentStudent));
            logger.info("Successfully created a friend request.");
        }
        List<Students> friendrequests = StudentDAO.getFriendRequests(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friendrequests", friendrequests);
        logger.info("Friend requests updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentmanagefriends";
}