Example usage for java.util.logging SimpleFormatter SimpleFormatter

List of usage examples for java.util.logging SimpleFormatter SimpleFormatter

Introduction

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

Prototype

SimpleFormatter

Source Link

Usage

From source file:com.twitter.heron.common.utils.logging.LoggingHelper.java

/**
 * Initialize a <tt>FileHandler</tt> to write to a set of files
 * with optional append.  When (approximately) the given limit has
 * been written to one file, another file will be opened.  The
 * output will cycle through a set of count files.
 * The pattern of file name should be: ${processId}.log.index
 * <p>//from   w  ww .  j  av  a2  s  .c o m
 * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
 * properties (or their default values) except that the given pattern
 * argument is used as the filename pattern, the file limit is
 * set to the limit argument, and the file count is set to the
 * given count argument, and the append mode is set to the given
 * <tt>append</tt> argument.
 * <p>
 * The count must be at least 1.
 *
 * @param limit the maximum number of bytes to write to any one file
 * @param count the number of files to use
 * @param append specifies append mode
 * @throws IOException if there are IO problems opening the files.
 * @throws SecurityException if a security manager exists and if
 * the caller does not have <tt>LoggingPermission("control")</tt>.
 * @throws IllegalArgumentException if {@code limit < 0}, or {@code count < 1}.
 * @throws IllegalArgumentException if pattern is an empty string
 */
public static FileHandler getFileHandler(String processId, String loggingDir, boolean append, ByteAmount limit,
        int count) throws IOException, SecurityException {

    String pattern = loggingDir + "/" + processId + ".log.%g";

    FileHandler fileHandler = new FileHandler(pattern, (int) limit.asBytes(), count, append);
    fileHandler.setFormatter(new SimpleFormatter());
    fileHandler.setEncoding(StandardCharsets.UTF_8.toString());

    return fileHandler;
}

From source file:BSxSB.Controllers.AdminController.java

@RequestMapping(value = "/addscheduleblock", method = RequestMethod.POST)
public String addScheduleBlock(Model model, @RequestParam(value = "schoolid") String schoolID,
        @RequestParam(value = "period") String period, @RequestParam(value = "days") String[] days) {
    try {/*from w  w w. j  a v a  2s  .com*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBAdminScheduleBlocks.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        logger.info("Admin Viewing List of School's Schedule Blocks.");
        int schoolID2 = Integer.parseInt(schoolID);
        if (period.isEmpty() || days.length == 0) {
            model.addAttribute("sbempty", "A field is empty");
        }
        int periodInt = Integer.parseInt(period);
        String daysString = "";
        for (String x : days) {
            daysString += x;
            daysString += ",";
        }
        daysString = daysString.substring(0, daysString.length() - 1);
        Scheduleblocks sb = ScheduleBlockDAO.getScheduleBlock(schoolID2, periodInt, daysString);
        if (sb != null) {
            model.addAttribute("sbexists", "This scheduleblock exists");
            logger.info("Error: SB exists");
        } else {
            ScheduleBlockDAO.addScheduleBlock(schoolID2, periodInt, daysString);
            logger.info(
                    "Scheduleblock with period " + periodInt + " and days " + daysString + " added to school.");
        }
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return editScheduleBlocks(model, schoolID);
}

From source file:org.deviceconnect.android.manager.DConnectMessageService.java

@Override
public void onCreate() {
    super.onCreate();

    if (BuildConfig.DEBUG) {
        AndroidHandler handler = new AndroidHandler("dconnect.manager");
        handler.setFormatter(new SimpleFormatter());
        handler.setLevel(Level.ALL);
        mLogger.addHandler(handler);/*  w ww.j av  a 2 s .  c o  m*/
        mLogger.setLevel(Level.ALL);
    } else {
        mLogger.setLevel(Level.OFF);
    }

    // ???
    EventManager.INSTANCE.setController(new MemoryCacheController());

    // Local OAuth??
    LocalOAuth2Main.initialize(getApplicationContext());

    // DConnect
    mSettings = DConnectSettings.getInstance();
    mSettings.load(this);

    // ?
    mFileMgr = new FileManager(this);

    // ???Local OAuth
    mLocalOAuth = new DConnectLocalOAuth(this);

    // ????
    mPluginMgr = new DevicePluginManager(this, mDConnectDomain);
    mPluginMgr.setEventListener(this);

    // ?
    addProfile(new AuthorizationProfile());
    addProfile(new DConnectAvailabilityProfile());
    addProfile(new DConnectServiceDiscoveryProfile(this, mPluginMgr));
    addProfile(new DConnectFilesProfile(this));
    addProfile(new DConnectSystemProfile(this, mPluginMgr));

    // dConnect Manager????????????
    setDeliveryProfile(new DConnectDeliveryProfile(mPluginMgr, mLocalOAuth, mSettings.requireOrigin()));
}

From source file:com.nilostep.xlsql.database.xlInstanceOLD.java

private xlInstanceOLD(String cfg) throws xlException {
    logger = Logger.getLogger(this.getClass().getName());
    instance = this;
    //name = cfg;

    try {//from  w  w  w  .  j  a  v a 2 s. c  om
        //            file = new File(cfg + "_config.xml");
        //            handler = new XMLFileHandler();
        //            handler.setFile(file);
        //
        //            cm = ConfigurationManager.getInstance();
        //            config = cm.getConfiguration(name);
        //            config.addConfigurationListener(this);
        //
        //            if (file.exists()) {

        PropertiesConfiguration config = new PropertiesConfiguration();
        config.load(this.getClass().getResourceAsStream(cfg + ".properties"));
        String engine = config.getString("general.engine");

        //cm.load(handler, name);                
        //Category cat = config.getCategory("general");                                                                
        //engine = config.getProperty("engine", null, "general");
        //config.setCategory(engine, true);
        //logger.info("Configuration file: " + file + " loaded");
        logger.info("Configuration engine: " + engine + " loaded");
        //            } else {

        //
        //                assert (config.isNew());
        //
        //                //
        //                config.setCategory("general", true);
        //
        //                String engine = "hsqldb";
        //                setLog("xlsql.log");
        //                setDatabase(System.getProperty("user.dir"));
        //
        //                //
        //                this.engine = engine;
        //                this.config.setProperty("engine", engine);
        //                addEngine(engine);
        //                config.setCategory(engine, true);
        //
        //
        //                //
        //                setDriver("org.hsqldb.jdbcDriver");
        //                setUrl("jdbc:hsqldb:.");
        //                setSchema("");
        //                setUser("sa");
        //                setPassword("");
        //                config.setCategory(getEngine(), true);
        //                logger.info("Configuration file: " + file + " created.");
        //            }
    }
    //catch (ConfigurationManagerException cme) {
    //   config = cm.getConfiguration(name);
    //} 
    catch (ConfigurationException e) {
        e.printStackTrace();
        throw new xlException(e.getMessage());
    }

    try {
        if (getLog() == null) {
            setLog("xlsql.log");
        }

        boolean append = true;
        FileHandler loghandler = new FileHandler(getLog(), append);
        loghandler.setFormatter(new SimpleFormatter());
        logger.addHandler(loghandler);
    } catch (IOException e) {
        throw new xlException("error while creating logfile");
    }

    //logger.info("Instance created with engine " + getEngine());
    logger.info("Instance created with engine " + engine);

    //
    //
    //
}

From source file:com.versusoft.packages.ooo.odt2daisy.addon.gui.UnoGUI.java

/**
 *
 * @param m_xContext Component context to be passed to a component via ::com::sun::star::lang::XSingleComponentFactory.
 * @param m_xFrame Frame object that serves as an "anchor" object where a component can be attached to.
 * @param isFullExport true if the content should be exported as Full DAISY, false if the content should be exported as DAISY XML (no audio).
 *///w  w w.j  ava2  s .  c  om
public UnoGUI(XComponentContext m_xContext, XFrame m_xFrame, boolean isFullExport) {

    this.m_xContext = m_xContext;
    this.m_xFrame = m_xFrame;
    this.isFullExport = isFullExport;

    try {

        // Configuring logger
        logFile = File.createTempFile(LOG_FILENAME, null);
        fh = new FileHandler(logFile.getAbsolutePath());
        fh.setFormatter(new SimpleFormatter());
        Logger.getLogger("").addHandler(fh);
        Logger.getLogger("").setLevel(Level.FINEST);
        logger.fine("entering");

        // Configuring Locale
        OOoLocale = new Locale(UnoUtils.getUILocale(m_xContext));
        L10N_MessageBox_Warning_Title = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("MessageBox_Warning_Title");
        L10N_No_Headings_Warning = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("No_Headings_Warning");
        L10N_Incompatible_Images_Error = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Incompatible_Images_Error");
        L10N_Default_Export_Filename = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Default_Export_Filename");
        L10N_MessageBox_Error_Title = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("MessageBox_Error_Title");
        L10N_DTD_Error_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("DTD_Error_Message");
        L10N_Line = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Line");
        L10N_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Message");
        L10N_MessageBox_InternalError_Title = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("MessageBox_InternalError_Title");
        L10N_Export_Aborted_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Export_Aborted_Message");
        L10N_MessageBox_Info_Title = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("MessageBox_Info_Title");
        L10N_Empty_Document_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Empty_Document_Message");
        L10N_Validated_DTD_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("Validated_DTD_Message");
        L10N_PipelineLite_Update_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("PipelineLite_Update_Message");
        L10N_PipelineLite_Size_Error_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("PipelineLite_Size_Error_Message");
        L10N_PipelineLite_Extract_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("PipelineLite_Extract_Message");
        L10N_PipelineLite_Extract_Error_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("PipelineLite_Extract_Error_Message");
        L10N_PipelineLite_Exec_Error_Message = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("PipelineLite_Exec_Error_Message");
        L10N_StatusIndicator_Step_1 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_1");
        L10N_StatusIndicator_Step_2 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_2");
        L10N_StatusIndicator_Step_3 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_3");
        L10N_StatusIndicator_Step_4 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_4");
        L10N_StatusIndicator_Step_5 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_5");
        L10N_StatusIndicator_Step_6 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_6");
        L10N_StatusIndicator_Step_7 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_7");
        L10N_StatusIndicator_Step_8 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_8");
        L10N_StatusIndicator_Step_9 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_9");
        L10N_StatusIndicator_Step_10 = java.util.ResourceBundle
                .getBundle("com/versusoft/packages/ooo/odt2daisy/addon/l10n/Bundle", OOoLocale)
                .getString("StatusIndicator_Step_10");

        // Init Status Indicator
        xStatusIndicatorFactory = (XStatusIndicatorFactory) UnoRuntime
                .queryInterface(XStatusIndicatorFactory.class, m_xFrame);
        xStatusIndicator = xStatusIndicatorFactory.createStatusIndicator();

        // Query Uno Object
        xDoc = (XModel) UnoRuntime.queryInterface(XModel.class, m_xFrame.getController().getModel());

        parentWindow = xDoc.getCurrentController().getFrame().getContainerWindow();
        parentWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, parentWindow);

        //DEBUG MODE
        //UnoAwtUtils.showInfoMessageBox(parentWindowPeer, L10N_MessageBox_Info_Title, "DEBUG MODE: "+logFile.getAbsolutePath());

    } catch (Exception ex) {
        logger.log(Level.SEVERE, null, ex);
    }

}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studentassignedcourses", method = RequestMethod.GET)
public String assignedCourses(Model model) {
    try {/*  www  . j  av a 2 s . co  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:org.apache.oodt.cas.pge.PGETaskInstance.java

protected Logger createLogger() throws IOException, PGEException {
    File logDir = new File(pgeConfig.getExeDir(), "logs");
    if (!(logDir.exists() || logDir.mkdirs())) {
        throw new PGEException("mkdirs for logs directory return false");
    }/*ww w  .  j  ava  2  s . co  m*/

    Logger logger = Logger.getLogger(PGETaskInstance.class.getName() + "." + workflowInstId);
    FileHandler handler = new FileHandler(new File(logDir, createLogFileName()).getAbsolutePath());
    handler.setEncoding("UTF-8");
    handler.setFormatter(new SimpleFormatter());
    logger.addHandler(handler);
    return logger;
}

From source file:org.deviceconnect.android.localoauth.LocalOAuth2Main.java

/**
 * .//from w  w w .  j  a  va 2 s  .co  m
 */
public LocalOAuth2Main(final android.content.Context context, final String dbName) {
    // 
    Logger logger = sLogger;
    if (BuildConfig.DEBUG) {
        AndroidHandler handler = new AndroidHandler(logger.getName());
        handler.setFormatter(new SimpleFormatter());
        handler.setLevel(Level.ALL);
        logger.addHandler(handler);
        logger.setLevel(Level.ALL);
    } else {
        logger.setLevel(Level.OFF);
    }

    mContext = context;

    // DB??
    mDbHelper = new LocalOAuthOpenHelper(context, dbName);
    mDb = mDbHelper.getWritableDatabase();

    // ??
    mUserManager = new SampleUserManager();
    mClientManager = new SQLiteClientManager(mDb);
    mTokenManager = new SQLiteTokenManager(mDb);

    // 
    addUserData(SampleUser.LOCALOAUTH_USER, SampleUser.LOCALOAUTH_PASS);

    register(context);
}

From source file:com.coprtools.core.CopyrightToolsEngine.java

/**
 * Enables the logging capabilities. Creates a log file in the roots path.
 *
 * @param rootPath/*from   w w  w. ja  va  2 s .  c  o m*/
 *            - the projects's root directory
 * @throws SecurityException
 * @throws IOException
 */
private void enableLogging(String rootPath) throws SecurityException, IOException {
    LOGGER.setLevel(Level.ALL);
    String logFilePath = rootPath + File.separator + InserterConstants.LOG_FILENAME;
    this.fileHandler = new FileHandler(logFilePath);
    fileHandler.setFormatter(new SimpleFormatter());
    fileHandler.setLevel(Level.ALL);
    LOGGER.addHandler(fileHandler);
}

From source file:BSxSB.Controllers.AdminController.java

@RequestMapping(value = "/deletescheduleblock", method = RequestMethod.POST)
public String deleteScheduleBlocks(Model model, @RequestParam(value = "scheduleblockID") String scheduleblockID,
        @RequestParam(value = "schoolid") String schoolid) {
    try {/*from   w w  w . j  a v  a2 s . com*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBAdminScheduleBlocks.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        logger.info("Admin Viewing List of School's Schedule Blocks.");
        int sbid = Integer.parseInt(scheduleblockID);
        ScheduleBlockDAO.deleteScheduleBlock(sbid);
        logger.info("Scheduleblock " + sbid + " was deleted.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return editScheduleBlocks(model, schoolid);
}