Search the Community
Showing results for tags 'logger'.
Found 2 results
-
I made this out of bordem, my desktop computer is in the shop so my java version is outdated a bit, so anything in there like double catch clauses, that's why. [CODE]package org.intel.utils; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; /** * @author Taylor Moon * * @since Oct 24, 2012 */ public class Logging { /** * Constructs the logger. * @param name - The name of this logger * @param on - true if the logger is on, false otherwise */ public Logging(String name, boolean on) { logger = Logger.getLogger(name); logs = new ConcurrentHashMap<String, String>(); isOn = on; } /**Determines if the logger is on or not */ private boolean isOn; /**Creates a new Logger to store messages */ private Logger logger; /**Represents a map of system logs */ private ConcurrentHashMap<String, String> logs; /** * Shows an exception message on the CMD and wites it to the logs * @param e - Exception being thrown * @param message - the message to display */ public void documentException(Exception e, String extraMessage) { if(isOn) { Date date = Calendar.getInstance().getTime(); String message = "[" + date + "] Exception at thread " + Thread.currentThread().getName() + ": " + extraMessage + " - " +e.getMessage(); logger.warning(message); logs.put("[" + date, message); record(message); } } /** * Shows a message on the CMD and writes it to the logs * @param log - the message to log */ public void log(String log) { if(isOn) { Date date = Calendar.getInstance().getTime(); logger.log(new LogRecord(Level.INFO, "[" + date + "] " + log)); logs.put("[" + date, log); record("[" + date + "] " + log); } } /** * Shows a message on the CMD and writes it to the logs. * If the logger is turned off, it will bypass it. * @param log - the message to log */ public void forceLog(String log) { Date date = Calendar.getInstance().getTime(); logger.log(new LogRecord(Level.INFO, "[" + date + "] " + log)); System.out.println("[Force Logged]"); logs.put("[" + date, log); record("[" + date + "] " + log); } /** * Sets the logger state to on, * allowing it to log messages * @param on - true if on, false otherwise */ public void turnOn(boolean on) { isOn = on; } /** * Shuts down the logger and sets * all attrivutes to null */ public void shutDown() { isOn = false; logs = null; logger = null; } /** * Removes all logs from the entryset */ public void flushLogs() { for(Object i : logs.entrySet()) logs.remove(i); } /** * Shows a list of the logs to the prompt */ public void showLogs() { if(logs.isEmpty()) { try { throw new Exception("Logging Exception"); } catch (Exception e) { e.printStackTrace(); } } for(Object log : logs.entrySet()) { System.out.println(log); } } /** * Writes a logging message to a text file * @param message - the message to write */ private void record(String message) { try { BufferedWriter stream = new BufferedWriter(new FileWriter("data/logs.txt")); stream.write(message); stream.newLine(); stream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } [/CODE]
-
is there anyway to tell if you have a keylogger?