SHARE
TWEET

ResourceLogger

a guest Nov 14th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package utils;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8.  
  9. public class ResourceLogger {
  10.  
  11.     private static ResourceLogger instance;
  12.     List<String> log = new LinkedList<>();
  13.  
  14.     private ResourceLogger() {
  15.     }
  16.  
  17.     public static ResourceLogger getInstance() {
  18.         if (instance == null) {
  19.             instance = new ResourceLogger();
  20.         }
  21.         return instance;
  22.     }
  23.  
  24.     public synchronized void add(String entry) {
  25.         log.add(entry);
  26.     }
  27.  
  28.     public void writeLogToFile() throws IOException {
  29.         BufferedWriter writer = new BufferedWriter(new FileWriter("resource_log.txt"));
  30.  
  31.         for (String entry : log) {
  32.             writer.write(entry);
  33.         }
  34.  
  35.         writer.close();
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top