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:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/removeassign", method = RequestMethod.POST)
public String removeAssigned(Model model, @RequestParam(value = "id") int id) {
    try {//from  ww  w. ja v a  2  s .  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);
        RegistrationDAO.removereg(id, currentStudent.getStudentid());
        CourseDAO.decrementCourseStudentsAndDelete(id);
        logger.info("Course successfully deleted");
        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 = "/studentcourseofferings", method = RequestMethod.GET)
public String courseOfferings(Model model, @RequestParam(value = "year") String year) {
    try {//w w  w.  j  av  a  2 s .  co m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentCourseOfferings.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        int schoolid = currentStudent.getSchoolid();
        Schools sc = SchoolDAO.getSchool(schoolid);
        String schoolName = sc.getSchoolname();
        Schools schoolYear = SchoolDAO.getSchoolByNameYear(schoolName, year);
        int schoolYearID = schoolYear.getSchoolid();
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(schoolYearID);
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
            logger.info("Retrieved course: " + course.getCourseidentifier());
        }
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentcourseofferings";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/addlunch", method = RequestMethod.POST)
public String addlunch(Model model, @RequestParam("lunch") String lunchday) {
    try {//from w ww  . jav a 2  s .c  om
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        GenerationcriteriaDAO.addLunch(currentStudent.getStudentid(), lunchday);
        logger.info(lunchday + " successfully added to Generation Criteria.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/adddesiredcourse", method = RequestMethod.POST)
public String adddesiredcourses(Model model, @RequestParam("id") String id) {
    try {// w ww  .  ja  va2  s.c  o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        GenerationcriteriaDAO.addDesiredCourses(currentStudent.getStudentid(), id);
        logger.info("Course successfully added to generation criteria.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        logger.info("Generation Criteria successfully updated.");
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/removelunch", method = RequestMethod.POST)
public String removelunch(Model model, @RequestParam("lunch") String lunchday) {
    try {//from   w  w w  .  j  a v  a2 s .  c  o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        GenerationcriteriaDAO.removeLunch(currentStudent.getStudentid(), lunchday);
        logger.info(lunchday + " removed from generation crtieria.");
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Generation criteria successfully updated.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/removedesiredcourse", method = RequestMethod.POST)
public String removedesiredcourses(Model model, @RequestParam("id") String id) {
    try {/*  ww  w.j  av a  2  s  .c  o m*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        GenerationcriteriaDAO.removeDesiredCourses(currentStudent.getStudentid(), id);
        logger.info("Course sucessfully removed from generation criteria.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        if (!gencriteria.getCourseids().isEmpty()) {
            for (String courseid : courseids) {
                Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
                genCourses.add(genCourse);
                genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
            }
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Generation criteria successfully updated.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studentgeneratecourses", method = RequestMethod.GET)
public String generateCourses(Model model) {
    try {//  w  ww .  j  a v  a2 s.c o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());

        if (gencriteria != null) {
            String[] courseids = gencriteria.getCourseids().split(",");
            List<Courses> genCourses = new ArrayList<>();
            List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
            if (!gencriteria.getCourseids().isEmpty()) {
                for (String courseid : courseids) {
                    Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
                    genCourses.add(genCourse);
                    genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
                }
            }
            if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
                String[] lunch = gencriteria.getLunch().split(",");
                model.addAttribute("lunch", lunch);
            }
            String lunchrange = currentSchool.getLunchrange();
            model.addAttribute("lunchrange", lunchrange);
            int numdays = currentSchool.getNumdays();
            String lunchdays = lunchToText(numdays);
            String[] lunchdays2 = lunchdays.split(",");
            model.addAttribute("lunchdays", lunchdays2);
            model.addAttribute("genscheduleblocks", genscheduleblocks);
            model.addAttribute("gencourses", genCourses);
            model.addAttribute("schoolyears", schoolyears);
            model.addAttribute("scheduleblocks", scheduleblocks);
            model.addAttribute("courses", courses);
            logger.info("Successfully loaded generation criteria.");
            handler.close();
            logger.removeHandler(handler);
        }
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }

    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studentassignedcourses", method = RequestMethod.GET)
public String assignedCourses(Model model) {
    try {/*from  w w  w.  j  a  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> studentCourses = CourseDAO.getCoursesForStudent(currentStudent.getStudentid());
        Schools school = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<List<Courses[]>> semesters = new ArrayList<>();
        List<Students> friends = StudentDAO.getFriends(currentStudent.getStudentid());
        for (Courses course : studentCourses) {
            for (Students friend : friends) {
                List<Courses> friendCourses = CourseDAO.getCoursesForStudent(friend.getStudentid());
                for (Courses friendCourse : friendCourses) {
                    if (friendCourse.getCourseid() == (course.getCourseid())) {
                        if (course.getFriends() != null) {
                            course.setFriends(course.getFriends() + " " + friend.getFirstname() + " "
                                    + friend.getLastname());
                        } else {
                            course.setFriends(friend.getFirstname() + " " + friend.getLastname());
                        }
                    }
                }
            }
        }
        logger.info("Successfully retrieved all friends for each course.");
        for (int s = 0; s < school.getNumsemesters(); s++) {
            List<Courses[]> schedule = new ArrayList<>();
            for (int i = 0; i < school.getNumperiods(); i++) {
                Courses[] period = new Courses[7];
                for (Courses course : studentCourses) {
                    Scheduleblocks sb = ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid());
                    if (sb.getPeriod() == i + 1) {
                        String[] days = sb.getDays().split(",");
                        String[] semester = course.getSemester().split(",");
                        for (String sem : semester) {
                            if (Integer.parseInt(sem) == s + 1) {
                                for (String day : days) {
                                    period[Integer.parseInt(day) - 1] = course;
                                }
                            }
                        }
                    }
                }
                schedule.add(period);
            }
            semesters.add(schedule);
        }
        logger.info("Successfully retrieved schedule for each semester.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("semester", semesters);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentassignedcourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/submitassigned", method = RequestMethod.POST)
public String submitAssigned(Model model, @RequestParam(value = "courseidentifier") String courseidentifier,
        @RequestParam(value = "coursename") String coursename,
        @RequestParam(value = "instructor") String instructor,
        @RequestParam(value = "semesters") String[] semesters, @RequestParam(value = "period") String period,
        @RequestParam(value = "days") String[] days) {
    try {//from w  ww  .java2s.com
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAssignedCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        if (coursename.isEmpty() || instructor.isEmpty() || semesters[0].matches("noinput") || period.isEmpty()
                || days[0].matches("noinput")) {
            model.addAttribute("fieldempty", "Please fill out all required fields.");
            logger.info("Error: Fields are empty");
            handler.close();
            logger.removeHandler(handler);
            return enterCourses(model);
        }
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        int schoolid = currentStudent.getSchoolid();
        //Build the semester string
        String semString = "";
        for (int i = 0; i < semesters.length - 1; i++) {
            semString += semesters[i];
            semString += ",";
        }
        //Get rid of last ','
        semString = semString.substring(0, semString.length() - 1);
        //Build the scheduleblock days
        String daysString = "";
        for (int i = 0; i < days.length - 1; i++) {
            daysString += days[i];
            daysString += ",";
        }
        daysString = daysString.substring(0, daysString.length() - 1);
        int periodInt = Integer.parseInt(period);
        Scheduleblocks sb = ScheduleBlockDAO.getScheduleBlock(schoolid, periodInt, daysString);
        if (sb == null) {
            model.addAttribute("sbinvalid", "Scheduleblock provided is invalid.");
            logger.info("Error: The chosen scheduleblock does not exist for this school");
            // return error msg
        } else {
            Courses c = CourseDAO.getCourse(courseidentifier, coursename, sb.getScheduleblockid(), schoolid,
                    instructor, semString);
            if (c != null) {
                if (RegistrationDAO.isRegistered(c, currentStudent)) {
                    model.addAttribute("alreadyreg", "You are already registered for this course");
                    logger.info("Error: already registered for this course");
                } else {
                    RegistrationDAO.addRegistration(c.getCourseid(), currentStudent.getStudentid());
                    CourseDAO.incrementCourseStudents(c.getCourseid());
                    model.addAttribute("halfsuccess",
                            "Course already exists, you have been successfully added to the course roster.");
                    logger.info("Course exists and student has been added to roster");
                }
            } else {
                int sbid = sb.getScheduleblockid();
                Courses newCourse = new Courses(schoolid, coursename, courseidentifier, instructor, sbid,
                        semString);
                newCourse.setNumstudents(1);
                int studentid = currentStudent.getStudentid();
                CourseDAO.addCourse(newCourse, studentid);
                model.addAttribute("success", "New course successfully added.");
                logger.info("Course " + courseidentifier + " " + coursename + " successfully added");
            }
        }

        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("numSemesters", currentSchool.getNumsemesters());
        model.addAttribute("numPeriods", currentSchool.getNumperiods());
        model.addAttribute("numDays", currentSchool.getNumdays());
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studententercourses";
}

From source file:processing.app.Base.java

static public void initLogger() {
    Handler consoleHandler = new ConsoleLogger();
    consoleHandler.setLevel(Level.ALL);
    consoleHandler.setFormatter(new LogFormatter("%1$tl:%1$tM:%1$tS [%4$7s] %2$s: %5$s%n"));

    Logger globalLogger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
    globalLogger.setLevel(consoleHandler.getLevel());

    // Remove default
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
        globalLogger.removeHandler(handler);
    }//from   w  ww  .j a  va  2s  .  c  o m
    Logger root = Logger.getLogger("");
    handlers = root.getHandlers();
    for (Handler handler : handlers) {
        root.removeHandler(handler);
    }

    globalLogger.addHandler(consoleHandler);

    Logger.getLogger("cc.arduino.packages.autocomplete").setParent(globalLogger);
    Logger.getLogger("br.com.criativasoft.cpluslibparser").setParent(globalLogger);
    Logger.getLogger(Base.class.getPackage().getName()).setParent(globalLogger);

}