FileLogger.java 750 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package de.tudarmstadt.informatik.hostage.logging;
  2. import java.io.FileOutputStream;
  3. import android.content.Context;
  4. public class FileLogger implements Logger {
  5. private FileOutputStream log = null;
  6. public FileLogger(Context context) {
  7. try {
  8. log = context.openFileOutput("hostage.log", Context.MODE_APPEND);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. }
  13. @Override
  14. public synchronized void write(Record record) {
  15. if (log != null) {
  16. try {
  17. log.write((record.toString() + "\n").getBytes());
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. }
  23. @Override
  24. public void close() {
  25. if (log != null) {
  26. try {
  27. log.flush();
  28. log.close();
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }
  34. }