LoggingUtils.kt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Nextcloud Talk application
  3. *
  4. * @author Mario Danic
  5. * Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.talk.utils
  21. import android.content.Context
  22. // TODO: improve log handling. https://github.com/nextcloud/talk-android/issues/1376
  23. // writing logs to a file is temporarily disabled to avoid huge logfiles.
  24. object LoggingUtils {
  25. fun writeLogEntryToFile(context: Context, logEntry: String) {
  26. // val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ROOT)
  27. // val date = Date()
  28. // val logEntryWithDateTime = dateFormat.format(date) + ": " + logEntry + "\n"
  29. //
  30. // try {
  31. // val outputStream = context.openFileOutput(
  32. // "nc_log.txt",
  33. // Context.MODE_PRIVATE or Context.MODE_APPEND
  34. // )
  35. // outputStream.write(logEntryWithDateTime.toByteArray())
  36. // outputStream.flush()
  37. // outputStream.close()
  38. // } catch (e: FileNotFoundException) {
  39. // e.printStackTrace()
  40. // } catch (e: IOException) {
  41. // e.printStackTrace()
  42. // }
  43. }
  44. fun sendMailWithAttachment(context: Context) {
  45. // val logFile = context.getFileStreamPath("nc_log.txt")
  46. // val emailIntent = Intent(Intent.ACTION_SEND)
  47. // val mailto = "android@nextcloud.com"
  48. // emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mailto))
  49. // emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs")
  50. // emailIntent.type = "text/plain"
  51. // emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
  52. // val uri: Uri
  53. //
  54. // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
  55. // uri = Uri.fromFile(logFile)
  56. // } else {
  57. // uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile)
  58. // }
  59. //
  60. // emailIntent.putExtra(Intent.EXTRA_STREAM, uri)
  61. // emailIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
  62. // context.startActivity(emailIntent)
  63. }
  64. }