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

@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(Model model) {
    try {//from www  . j  a  v  a2  s. co m
        Handler handler = new FileHandler("%tBSxSBAdminSchools.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        logger.info("Admin Viewing List of Schools.");
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Admins admin = AdminDAO.getAdmin(name);
        if (!admin.getLoggedin()) {
            AdminDAO.setLoggedIn(name);
        }
        SchoolDAO schoolDAO = new SchoolDAO();
        ScheduleBlockDAO scheduleBlockDAO = new ScheduleBlockDAO();
        List<Schools> schools = schoolDAO.allSchools();
        for (Schools school : schools) {
            List<Scheduleblocks> scheduleBlocks = scheduleBlockDAO
                    .getSchoolsScheduleBlocks(school.getSchoolid());
            String SB2Strings = "";
            for (Scheduleblocks sb : scheduleBlocks) {
                SB2Strings += sb.toString();
            }
            school.setScheduleblocks(SB2Strings);
        }
        model.addAttribute("school", schools);
        logger.info("Schools successfully 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 "admin";
}

From source file:org.deviceconnect.android.deviceplugin.theta.ThetaDeviceApplication.java

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

    if (BuildConfig.DEBUG) {
        for (Logger logger : mLoggers) {
            AndroidHandler handler = new AndroidHandler(logger.getName());
            handler.setFormatter(new SimpleFormatter());
            handler.setLevel(Level.ALL);
            logger.addHandler(handler);/*from  w  w w .  j a va2s. co  m*/
            logger.setLevel(Level.ALL);
        }
    } else {
        for (Logger logger : mLoggers) {
            logger.setLevel(Level.OFF);
        }
    }

    Context context = getApplicationContext();
    mDeviceMgr = new ThetaDeviceManager(context);
    mHeadTracker = new HeadTrackerWrapper(new DefaultHeadTracker(context));
    mSphericalViewApi = new SphericalViewApi(context);
}

From source file:android.net.http.CookiesTest.java

/**
 * Test that we don't log potentially sensitive cookie values.
 * http://b/3095990/*w  w  w . j ava2  s  .  co m*/
 */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();

        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));

    } finally {
        logger.removeHandler(handler);
    }
}

From source file:com.sustainalytics.crawlerfilter.PDFtoTextBatch.java

/**
 * Method to initiate logger//w ww.  j av  a  2  s  .c  o  m
 * @param file is a File object. The log file will be placed in this file's folder
 */
public static void initiateLogger(File file) {
    FileHandler fileHandler;
    try {
        // This block configure the logger with handler and formatter
        fileHandler = new FileHandler(file.getAbsolutePath() + "/" + "log.txt", true);
        logger.addHandler(fileHandler);
        SimpleFormatter formatter = new SimpleFormatter();
        fileHandler.setFormatter(formatter);

    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:cn.org.once.cstack.cli.processor.LoggerPostProcessor.java

public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {
    ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {

        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {

            if (field.getAnnotation(InjectLogger.class) != null && field.getType().equals(Logger.class)) {
                ReflectionUtils.makeAccessible(field);
                Logger logger = Logger.getLogger(bean.getClass().getName());

                field.set(bean, logger);

                StreamHandler fileHandler;
                try {

                    FileOutputStream fileOutputStream = new FileOutputStream(new File("errors.log"), true);
                    fileHandler = new StreamHandler(fileOutputStream, new SimpleFormatter());
                    fileHandler.setLevel(Level.SEVERE);
                    logger.addHandler(fileHandler);

                } catch (SecurityException | IOException e) {
                    throw new IllegalArgumentException(e);
                }/*  www. jav  a 2s.  com*/

            }
        }
    });

    return bean;
}

From source file:nl.minvenj.pef.stream.LiveCapture.java

/**
 * Initializes a logger.//  w  w w . j a  v  a  2s.  com
 *
 * @param logPath The location and name of the log file
 * @throws SecurityException on opening the log file
 * @throws IOException on opening the log file
 */
private static void initLogger(final String logPath)
        throws SecurityException, IOException, IllegalArgumentException {
    logFileHandler = new FileHandler(logPath, true);
    Logger initLogger = Logger.getLogger("");
    logFileHandler.setFormatter(new SimpleFormatter());
    initLogger.addHandler(logFileHandler);
    initLogger.setLevel(Level.CONFIG);
}

From source file:fr.ippon.wip.util.WIPLogging.java

private WIPLogging() {
    try {//  w  ww . ja va2s .c  om
        // FileHandler launch an exception if parent path doesn't exist, so
        // we make sure it exists
        File logDirectory = new File(HOME + "/wip");
        if (!logDirectory.exists() || !logDirectory.isDirectory())
            logDirectory.mkdirs();

        accessFileHandler = new FileHandler("%h/wip/access.log", true);
        accessFileHandler.setLevel(Level.INFO);
        accessFileHandler.setFormatter(new SimpleFormatter());
        Logger.getLogger("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog").addHandler(accessFileHandler);

        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setFilter(new Filter() {

            public boolean isLoggable(LogRecord record) {
                return !record.getLoggerName().equals("fr.ippon.wip.http.hc.HttpClientExecutor.AccessLog");
            }
        });

        Logger.getLogger("fr.ippon.wip").addHandler(consoleHandler);

        // For HttpClient debugging
        // FileHandler fileHandler = new
        // FileHandler("%h/wip/httpclient.log", true);
        // fileHandler.setLevel(Level.ALL);
        // Logger.getLogger("org.apache.http.headers").addHandler(fileHandler);
        // Logger.getLogger("org.apache.http.headers").setLevel(Level.ALL);

    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.norvelle.addressdiscoverer.AddressDiscoverer.java

@SuppressWarnings("LeakingThisInConstructor")
public AddressDiscoverer() throws Exception {
    AddressDiscoverer.application = this;

    // First setup our logger. The ORMLite logger is prolix and useless,
    // so we redirect it to a temp file.
    System.setProperty(LocalLog.LOCAL_LOG_FILE_PROPERTY,
            System.getProperty("java.io.tmpdir") + File.separator + "addressdiscoverer.ormlite.log");
    this.checkSettingsDirExists();
    logger.setLevel(Level.SEVERE);
    FileHandler fh = new FileHandler(this.settingsDirname + File.separator + "debug.log", 8096, 1, true);
    logger.addHandler(fh);//from w w w .j  a  v a 2s.  c  o m
    SimpleFormatter formatter = new SimpleFormatter();
    fh.setFormatter(formatter);
    logger.info("Starting AddressDiscoverer");

    // Load our properties and attach the database, creating it if it doesn't exist
    this.loadProperties();
    this.attachDatabase();
    KnownLastName.initialize(this.settingsDirname);
    KnownFirstName.initialize(this.settingsDirname);
    KnownSpanishWord.initialize(this.settingsDirname);
    Abbreviations.initialize(this.settingsDirname);
    GrammarParticles.initialize(this.settingsDirname);
    GenderDeterminer.initialize(this.settingsDirname);

    // Create our GUI
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    window = new MainWindow(this);
    window.setTitle("AddressDiscoverer");
    window.setExtendedState(window.getExtendedState() | java.awt.Frame.MAXIMIZED_BOTH);
    window.setVisible(true);
}

From source file:org.hillview.utils.HillviewLogger.java

/**
 * Create a Hillview logger.//from w  w  w  . ja va  2s  . co  m
 * @param role      Who is doing the logging: web server, worker, test, etc.
 * @param filename  File where logs are to be written.  If null logs will be written to the
 *                  console.
 */
private HillviewLogger(String role, @Nullable String filename) {
    // Disable all default logging
    LogManager.getLogManager().reset();
    this.logger = Logger.getLogger("Hillview");
    this.machine = this.checkCommas(Utilities.getHostName());
    this.role = this.checkCommas(role);
    this.logger.setLevel(Level.INFO);

    Formatter form = new SimpleFormatter() {
        final String[] components = new String[5];
        final String newline = System.lineSeparator();
        private final DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");

        @Override
        public synchronized String format(LogRecord record) {
            this.components[0] = HillviewLogger.this.checkCommas(df.format(new Date(record.getMillis())));
            this.components[1] = HillviewLogger.this.role;
            this.components[2] = HillviewLogger.this.checkCommas(record.getLevel().toString());
            this.components[3] = HillviewLogger.this.machine;
            this.components[4] = record.getMessage();
            String result = String.join(",", components);
            return result + this.newline;
        }
    };

    Handler handler;
    if (filename != null) {
        try {
            handler = new FileHandler(filename);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        handler = new ConsoleHandler();
    }
    handler.setFormatter(form);
    logger.addHandler(handler);
    File currentDirectory = new File(new File(".").getAbsolutePath());
    this.info("Starting logger", "Working directory: {0}", currentDirectory);
}

From source file:plugins.GerritTriggerTest.java

@Before
public void setUpLogger() {
    LOGGER.setLevel(Level.ALL);/*from  w w w. ja  v a  2 s  . co  m*/
    LOGGER.setUseParentHandlers(false);
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(new SimpleFormatter());
    handler.setLevel(Level.ALL);
    LOGGER.addHandler(handler);
}