Skip to content

Commit f88ada5

Browse files
Merge pull request #19 from flyingfish162/main
Add JC content for tutorial 3,4,5,6,9 against BTP android SDK 24.8
2 parents a103779 + fd6a244 commit f88ada5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1034
-55
lines changed
220 KB
Loading
67.6 KB
Loading
Binary file not shown.
-119 KB
Loading
-10.6 KB
Binary file not shown.
72.2 KB
Loading

tutorials/sdk-android-wizard-app-logging/sdk-android-wizard-app-logging.md

Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,47 @@ time: 15
2626

2727
### Use the logging component
2828

29+
[OPTION BEGIN [Jetpack Compose-based UI]]
2930

30-
1. In Android Studio, on Windows, press **`Ctrl+N`**, or, on a Mac, press **`command+O`**, and enter **`EntitySetListActivity`** to open `EntitySetListActivity.kt`.
31+
1. In Android Studio, on Windows, press **`Ctrl+N`**, or on a Mac, press **`command+O`**, and enter **`SettingsViewModel`** to open `SettingsViewModel.kt`.
3132

32-
2. On Windows, press **`Ctrl+F12`**, or, on a Mac, press **`command+F12`**, and enter **`onOptionsItemSelected`** to move to the `onOptionsItemSelected` method.
33+
2. On Windows, press **`Ctrl+F`**, or on a Mac, press **`command+F`**, and enter **`init`** to navigate to the `init` block.
34+
35+
Note that the following code block contains two logger statements:
36+
37+
```Kotlin
38+
init {
39+
//init from shared preference
40+
viewModelScope.launch(Dispatchers.Default) {
41+
preferencesFlow.collect { userReference ->
42+
logger.debug("get preference as {}", userReference.logSetting)
43+
_settingUIState.update { uiState ->
44+
uiState.copy(level = LogPolicy.getLogLevel(userReference.logSetting))
45+
}
46+
}
47+
}
48+
49+
val consentUsage = UserSecureStoreDelegate.getInstance().getConsentStatus(ConsentType.USAGE)
50+
val consentCrashReport =
51+
UserSecureStoreDelegate.getInstance().getConsentStatus(ConsentType.CRASH_REPORT)
52+
logger.debug(
53+
"init consent data : consentUsage {}, consentCrashReport {}",
54+
consentUsage,
55+
consentCrashReport
56+
)
57+
58+
... ...
59+
```
60+
61+
These messages will be logged when the app's log level is set to **Debug** or **Path** and the app's **Settings** menu item is opened.
62+
63+
[OPTION END]
64+
65+
[OPTION BEGIN [View-based UI]]
66+
67+
1. In Android Studio, on Windows, press **`Ctrl+N`**, or on a Mac, press **`command+O`**, and enter **`EntitySetListActivity`** to open `EntitySetListActivity.kt`.
68+
69+
2. On Windows, press **`Ctrl+F12`**, or on a Mac, press **`command+F12`**, and enter **`onOptionsItemSelected`** to navigate to the `onOptionsItemSelected` method.
3370

3471
Note that the following method contains two LOGGER statements:
3572

@@ -48,25 +85,56 @@ time: 15
4885

4986
These messages will be logged when the app's log level is set to **Debug** or **Path** and the app's **Settings** menu item is opened.
5087

88+
[OPTION END]
89+
5190

5291
### Change the log level
5392

93+
[OPTION BEGIN [Jetpack Compose-based UI]]
5494

5595
1. Navigate to the entity list screen and open the app's menu.
5696
5797
![Settings menu button](settings_menu_button.png)
5898
5999
2. Choose **Settings**.
60100
61-
![Settings menu opened](settings_menu.png)
101+
3. Select **Log Level** displayed in **Logging** on the **Settings** screen.
62102
63-
3. Select **Log Level**.
103+
4. Set the level to **Debug**.
64104
65-
![Log level settings option](log_level_option.png)
105+
5. Navigate back to the entity list screen, then back into the **Settings** screen to see the effect of changing the log level.
66106
67-
4. Set the level to **Debug**.
107+
![Settings menu opened](settings_menu_jc.png)
108+
109+
6. Examine the **Logcat** (located at the bottom of the Android Studio screen, click it and you can see the logs). In the filter, add the name of the class that we are interested in seeing the log from: **`com.sap.wizapp.ui.odata.viewmodel.SettingsViewModel`**.
110+
111+
Notice that the messages were logged since the log level of the app was set to **Debug** or **Path**.
112+
113+
![Debug log level output](debug_log_jc.png)
114+
115+
---
116+
117+
The SDK libraries also log output based on the app's log level.
118+
119+
1. Change the filter to **`com.sap.cloud.mobile.foundation`**.
120+
121+
2. Press **Back** to exit the app and you will see the logged lines from the foundation library.
122+
123+
![Debug log level output for foundation](debug_log_foundation_jc.png)
124+
125+
[OPTION END]
126+
127+
[OPTION BEGIN [View-based UI]]
128+
129+
1. Navigate to the entity list screen and open the app's menu.
130+
131+
![Settings menu button](settings_menu_button.png)
132+
133+
2. Choose **Settings**.
68134
69-
![Debug log level option](debug_log_level_option.png)
135+
3. Select **Log Level** displayed in **Logging** on the **Settings** screen.
136+
137+
4. Set the level to **Debug**.
70138
71139
5. Navigate back to the entity list screen, then back into the **Settings** screen to see the effect of changing the log level.
72140
@@ -88,13 +156,44 @@ The SDK libraries also log output based on the app's log level.
88156

89157
![Debug log level output for foundation](debug_log_foundation.png)
90158

159+
[OPTION END]
160+
91161

92162
### Upload and view the log
93163

164+
[OPTION BEGIN [Jetpack Compose-based UI]]
165+
166+
1. Navigate back to the **Settings** screen in the app, and this time tap **Upload Log** right below **Log Level**.
167+
168+
A Toast message is displayed confirming that the upload succeeded.
169+
170+
![Log upload succeeded](log_uploaded_jc.png)
171+
172+
2. In the **Mobile Services cockpit**, navigate to **Mobile Applications** > **Native/MDK** > **com.sap.wizapp** > **Mobile Client Log Upload**.
173+
174+
![Mobile Applications > Native/MDK > com.sap.wizapp > Mobile Client Log Upload](select_and_download_log.png)
175+
176+
3. Select the **Error Logs** tab and you will see the log you just uploaded in the **Error** level list. If the log doesn't appear immediately, wait for a few moments, then click **Go** to refresh the view.
177+
178+
4. You can inspect the log details in the browser by clicking on its table entry.
179+
180+
5. Select the **Log Files** tab and you will see the log files you just uploaded in the list. You can download the files by clicking **Download**.
181+
182+
![View log details](view_log_files.png)
183+
184+
6. Additionally, you can access the logs locally on an emulator. You can browse the file system of an Android emulator using the **Device Explorer** to view the log files as shown below: **data** > **data** > **com.sap.wizapp** (or the package name of your project) > **files**.
185+
186+
![View logs in emulator](local_log_location.png)
187+
188+
7. You can manage the initial log level of the application and the ability for mobile services to accept logs on the **Configuration** page, as shown below.
189+
190+
![Log Policy](client_policies.png)
191+
192+
[OPTION END]
94193
95-
1. Navigate back to the **Settings** menu in the app, and this time tap **Upload Log**.
194+
[OPTION BEGIN [View-based UI]]
96195
97-
![Upload log button in settings menu](upload_log_button.png)
196+
1. Navigate back to the **Settings** menu in the app, and this time tap **Upload Log** right below **Log Level**.
98197
99198
A Toast message is displayed confirming that the upload succeeded.
100199
@@ -120,6 +219,7 @@ The SDK libraries also log output based on the app's log level.
120219

121220
![Log Policy](client_policies.png)
122221

222+
[OPTION END]
123223

124224
>For further information on logging, see [Logging](https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/features/logging/overview.html).
125225

25.6 KB
Loading
-10.5 KB
Binary file not shown.
9.16 KB
Loading

0 commit comments

Comments
 (0)