Skip to content

Commit d5fa658

Browse files
committed
Log major events in tests
1 parent ffe88fb commit d5fa658

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

app/src/androidTest/java/com/orgzly/android/OrgzlyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ private void setPreferencesForTests() {
138138

139139
/* Start with the light theme. */
140140
AppPreferences.colorTheme(context, "light");
141+
142+
/* Log major events. */
143+
AppPreferences.logMajorEvents(context, true);
141144
}
142145

143146
/**

app/src/main/java/com/orgzly/android/prefs/AppPreferences.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ public static boolean logMajorEvents(Context context) {
337337
context.getResources().getBoolean(R.bool.pref_default_log_major_events));
338338
}
339339

340+
public static void logMajorEvents(Context context, boolean value) {
341+
String key = context.getResources().getString(R.string.pref_key_log_major_events);
342+
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
343+
}
344+
340345
public static boolean showSyncNotifications(Context context) {
341346
return getDefaultSharedPreferences(context).getBoolean(
342347
context.getResources().getString(R.string.pref_key_show_sync_notifications),

app/src/main/java/com/orgzly/android/reminders/RemindersBroadcastReceiver.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,35 @@ class RemindersBroadcastReceiver : BroadcastReceiver() {
103103
private fun notifyForRemindersSinceLastRun(context: Context, now: DateTime, lastRun: LastRun?) {
104104
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG)
105105

106-
val msg = if (lastRun != null) {
106+
if (lastRun != null) {
107107
val notes = NoteReminders.getNoteReminders(
108108
context, dataRepository, now, lastRun, NoteReminders.INTERVAL_FROM_LAST_TO_NOW)
109109

110110
if (notes.isNotEmpty()) {
111111
// TODO: Show less, show summary
112112
val lastNotes = notes.takeLast(20)
113113

114-
"Triggered: Found ${notes.size} notes (showing ${lastNotes.size}) between $lastRun and $now".also {
115-
RemindersNotifications.showNotifications(context, lastNotes)
114+
if (LogMajorEvents.isEnabled()) {
115+
LogMajorEvents.log(
116+
LogMajorEvents.REMINDERS,
117+
"Since last run: Found ${notes.size} notes (showing ${lastNotes.size}) between $lastRun and $now")
116118
}
117119

120+
RemindersNotifications.showNotifications(context, lastNotes)
121+
118122
} else {
119-
"Triggered: No notes found between $lastRun and $now"
123+
if (LogMajorEvents.isEnabled()) {
124+
LogMajorEvents.log(
125+
LogMajorEvents.REMINDERS,
126+
"Since last run: No notes found between $lastRun and $now")
127+
}
120128
}
121129

122130
} else {
123-
"Triggered: No previous run"
124-
}
125-
126-
if (LogMajorEvents.isEnabled()) {
127-
LogMajorEvents.log(LogMajorEvents.REMINDERS, msg)
131+
if (LogMajorEvents.isEnabled()) {
132+
LogMajorEvents.log(LogMajorEvents.REMINDERS, "Since last run: No previous run")
133+
}
128134
}
129-
130-
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, msg)
131135
}
132136

133137
/**
@@ -156,7 +160,7 @@ class RemindersBroadcastReceiver : BroadcastReceiver() {
156160
val inS = inMs.userFriendlyPeriod()
157161
LogMajorEvents.log(
158162
LogMajorEvents.REMINDERS,
159-
"Next: Found ${notes.size} notes between $lastRun and $now and scheduling the first one in $inS ($inMs ms): \"$title\" (id:$id)"
163+
"Next: Found ${notes.size} notes from $now and scheduling first in $inS ($inMs ms): \"$title\" (id:$id)"
160164
)
161165
}
162166

app/src/main/java/com/orgzly/android/reminders/RemindersNotifications.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ object RemindersNotifications {
114114
notificationManager.notify(notificationTag, Notifications.REMINDER_ID, builder.build())
115115

116116
if (LogMajorEvents.isEnabled()) {
117+
val note = "\"${noteReminder.payload.title}\" (id:${noteReminder.payload.noteId})"
117118
LogMajorEvents.log(
118119
LogMajorEvents.REMINDERS,
119-
"Notified (tag:$notificationTag id:${Notifications.REMINDER_ID}): ${noteReminder.payload.title}"
120+
"Notified! (tag:$notificationTag id:${Notifications.REMINDER_ID}): $note"
120121
)
121122
}
122123
}

app/src/main/java/com/orgzly/android/util/LogMajorEvents.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import android.util.Log
44
import com.orgzly.BuildConfig
55
import com.orgzly.android.App
66
import com.orgzly.android.prefs.AppPreferences
7-
import org.joda.time.Instant
7+
import org.joda.time.DateTime
88
import java.io.File
99
import java.io.FileOutputStream
1010
import java.io.OutputStreamWriter
@@ -27,7 +27,7 @@ object LogMajorEvents {
2727

2828
// Append to file
2929
OutputStreamWriter(FileOutputStream(file, true)).use {
30-
val msg = "${Instant.now()} $name $str\n"
30+
val msg = "${DateTime.now()} $name $str\n"
3131
it.append(msg)
3232
}
3333

0 commit comments

Comments
 (0)