Skip to content

Commit 4285fbd

Browse files
committed
♻️ Update logging
1 parent 95b08d3 commit 4285fbd

File tree

6 files changed

+30
-31
lines changed

6 files changed

+30
-31
lines changed

app/src/main/java/org/b3log/siyuan/BootActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void startMainActivity() {
8989
blockURL = blockURLUri.toString();
9090
}
9191
} catch (final Exception e) {
92-
Utils.LogError("boot", "gets block URL failed", e);
92+
Utils.logError("boot", "gets block URL failed", e);
9393
}
9494

9595
// 获取可能存在的分享数据
@@ -140,14 +140,14 @@ public void handleMessage(final Message msg) {
140140
try {
141141
FileUtils.deleteQuietly(appDirFile);
142142
} catch (final Exception e) {
143-
Utils.LogError("boot", "delete [" + appDirFile.getAbsolutePath() + "] failed", e);
143+
Utils.logError("boot", "delete [" + appDirFile.getAbsolutePath() + "] failed", e);
144144
}
145145

146146
finishAffinity();
147147
finishAndRemoveTask();
148148
Log.i("boot", "User did not accept the agreement, exit");
149149
} else {
150-
Utils.LogError("boot", "unknown agreement command [" + cmd + "]");
150+
Utils.logError("boot", "unknown agreement command [" + cmd + "]");
151151
}
152152
}
153153
};

app/src/main/java/org/b3log/siyuan/JSAndroid.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void openExternal(String url) {
186186
.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
187187
activity.startActivity(intent);
188188
} catch (Exception e) {
189-
Utils.LogError("JSAndroid", "openExternal failed", e);
189+
Utils.logError("JSAndroid", "openExternal failed", e);
190190
}
191191
}
192192

@@ -227,7 +227,7 @@ private int parseColor(String str) {
227227
}
228228
return Color.parseColor(str);
229229
} catch (final Exception e) {
230-
Utils.LogError("js", "parse color [" + str + "] failed", e);
230+
Utils.logError("js", "parse color [" + str + "] failed", e);
231231
return Color.parseColor("#212224");
232232
}
233233
}

app/src/main/java/org/b3log/siyuan/KeepLiveService.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.os.Build;
2929
import android.os.IBinder;
3030

31-
import androidx.annotation.RequiresApi;
3231
import androidx.core.app.NotificationCompat;
3332

3433
import org.apache.commons.io.FileUtils;
@@ -61,7 +60,7 @@ public void onCreate() {
6160
super.onCreate();
6261
startMyOwnForeground();
6362
} catch (final Throwable e) {
64-
Utils.LogError("keeplive", "Start foreground service failed", e);
63+
Utils.logError("keeplive", "Start foreground service failed", e);
6564
}
6665
}
6766

@@ -120,7 +119,7 @@ private String[] getNotificationTexts() {
120119
final String[] ret = new String[lines.size()];
121120
return lines.toArray(ret);
122121
} catch (final Exception e) {
123-
Utils.LogError("boot", "check version failed", e);
122+
Utils.logError("boot", "check version failed", e);
124123
return words;
125124
}
126125
}

app/src/main/java/org/b3log/siyuan/MainActivity.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private void startHttpServer() {
377377
usAscii.setAccessible(true);
378378
usAscii.set(Charsets.class, Charsets.UTF_8);
379379
} catch (final Exception e) {
380-
Utils.LogError("http", "init charset failed", e);
380+
Utils.logError("http", "init charset failed", e);
381381
}
382382

383383
server = new AsyncHttpServer();
@@ -398,20 +398,20 @@ private void startHttpServer() {
398398
info.put("updated", file.lastModified());
399399
info.put("isDir", file.isDirectory());
400400
} catch (final Exception e) {
401-
Utils.LogError("http", "walk dir failed", e);
401+
Utils.logError("http", "walk dir failed", e);
402402
}
403403
files.put(info);
404404
});
405405
data.put("files", files);
406406
final JSONObject responseJSON = new JSONObject().put("code", 0).put("msg", "").put("data", data);
407407
response.send(responseJSON);
408-
Utils.LogInfo("http", "Walk dir [" + dir + "] in [" + (System.currentTimeMillis() - start) + "] ms");
408+
Utils.logInfo("http", "Walk dir [" + dir + "] in [" + (System.currentTimeMillis() - start) + "] ms");
409409
} catch (final Exception e) {
410-
Utils.LogError("http", "walk dir failed", e);
410+
Utils.logError("http", "walk dir failed", e);
411411
try {
412412
response.send(new JSONObject().put("code", -1).put("msg", e.getMessage()));
413413
} catch (final Exception e2) {
414-
Utils.LogError("http", "walk dir failed", e2);
414+
Utils.logError("http", "walk dir failed", e2);
415415
}
416416
}
417417
});
@@ -425,7 +425,7 @@ private void startHttpServer() {
425425
// 生产环境绑定 ipv6 回环地址 [::1] 以防止被远程访问
426426
s.listen(InetAddress.getLoopbackAddress(), serverPort, server.getListenCallback());
427427
}
428-
Utils.LogInfo("http", "HTTP server is listening on port [" + serverPort + "]");
428+
Utils.logInfo("http", "HTTP server is listening on port [" + serverPort + "]");
429429
}
430430

431431
private int getAvailablePort() {
@@ -435,7 +435,7 @@ private int getAvailablePort() {
435435
ret = s.getLocalPort();
436436
s.close();
437437
} catch (final Exception e) {
438-
Utils.LogError("http", "get available port failed", e);
438+
Utils.logError("http", "get available port failed", e);
439439
}
440440
return ret;
441441
}
@@ -562,7 +562,7 @@ private void initAppearance() {
562562
try {
563563
FileUtils.deleteDirectory(new File(appDir));
564564
} catch (final Exception e) {
565-
Utils.LogError("boot", "delete dir [" + appDir + "] failed, exit application", e);
565+
Utils.logError("boot", "delete dir [" + appDir + "] failed, exit application", e);
566566
exit();
567567
return;
568568
}
@@ -573,7 +573,7 @@ private void initAppearance() {
573573
try {
574574
FileUtils.writeStringToFile(appVerFile, Utils.versionCode + "", StandardCharsets.UTF_8);
575575
} catch (final Exception e) {
576-
Utils.LogError("boot", "write version failed", e);
576+
Utils.logError("boot", "write version failed", e);
577577
}
578578

579579
setBootProgress("Booting kernel...", 80);
@@ -591,7 +591,7 @@ private void sleep(final long time) {
591591
try {
592592
Thread.sleep(time);
593593
} catch (final Exception e) {
594-
Utils.LogError("runtime", "sleep failed", e);
594+
Utils.logError("runtime", "sleep failed", e);
595595
}
596596
}
597597

@@ -723,7 +723,7 @@ private boolean needUnzipAssets() {
723723
return true;
724724
}
725725
} catch (final Exception e) {
726-
Utils.LogError("boot", "check version failed", e);
726+
Utils.logError("boot", "check version failed", e);
727727
}
728728
return ret;
729729
}
@@ -783,7 +783,7 @@ private void checkWebViewVer(final WebSettings ws) {
783783
}
784784
}
785785
} catch (final Exception e) {
786-
Utils.LogError("boot", "check webview version failed", e);
786+
Utils.logError("boot", "check webview version failed", e);
787787
Utils.showToast(this, "Check WebView version failed: " + e.getMessage());
788788
}
789789
}
@@ -814,12 +814,12 @@ public static void syncData() {
814814
@Override
815815
public void onCompleted(Exception e, com.koushikdutta.async.http.AsyncHttpResponse source, JSONObject result) {
816816
if (null != e) {
817-
Utils.LogError("sync", "data sync failed", e);
817+
Utils.logError("sync", "data sync failed", e);
818818
}
819819
}
820820
});
821821
} catch (final Throwable e) {
822-
Utils.LogError("sync", "data sync failed", e);
822+
Utils.logError("sync", "data sync failed", e);
823823
} finally {
824824
syncing = false;
825825
}

app/src/main/java/org/b3log/siyuan/ShortcutActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private void writeAssets(final List<Uri> assetUris, final String type) {
173173
input.append(content);
174174
input.setSelection(input.getText().length());
175175
} catch (final Exception e) {
176-
Utils.LogError("shortcut", "Copy file failed", e);
176+
Utils.logError("shortcut", "Copy file failed", e);
177177
Utils.showToast(this, "Failed to copy file [" + e.getMessage() + "]");
178178
}
179179
}
@@ -212,7 +212,7 @@ public void afterTextChanged(Editable s) {
212212
try {
213213
FileUtils.writeStringToFile(f, userInput, "UTF-8");
214214
} catch (final Exception e) {
215-
Utils.LogError("shortcut", "Failed to write to file", e);
215+
Utils.logError("shortcut", "Failed to write to file", e);
216216
Utils.showToast(this, "Failed to write to file [" + e.getMessage() + "]");
217217
}
218218

@@ -224,7 +224,7 @@ private void addShortcutToHome() {
224224
final ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
225225
if (!shortcutManager.isRequestPinShortcutSupported()) {
226226
Utils.showToast(this, R.string.add_to_home_failed);
227-
Utils.LogError("shortcut", "Request pin shortcut not supported");
227+
Utils.logError("shortcut", "Request pin shortcut not supported");
228228
return;
229229
}
230230

app/src/main/java/org/b3log/siyuan/Utils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static void unzipAsset(final AssetManager assetManager, final String zipN
180180
*/
181181
}
182182
} catch (final Exception e) {
183-
Utils.LogError("boot", "unzip asset [from=" + zipName + ", to=" + targetDirectory + "] failed", e);
183+
Utils.logError("boot", "unzip asset [from=" + zipName + ", to=" + targetDirectory + "] failed", e);
184184
} finally {
185185
if (null != zis) {
186186
try {
@@ -212,17 +212,17 @@ public static String getIPAddressList() {
212212
}
213213
}
214214
} catch (final Exception e) {
215-
LogError("network", "get IP list failed, returns 127.0.0.1", e);
215+
logError("network", "get IP list failed, returns 127.0.0.1", e);
216216
}
217217
list.add("127.0.0.1");
218218
return TextUtils.join(",", list);
219219
}
220220

221-
public static void LogError(final String tag, final String msg) {
222-
LogError(tag, msg, null);
221+
public static void logError(final String tag, final String msg) {
222+
logError(tag, msg, null);
223223
}
224224

225-
public static void LogError(final String tag, final String msg, final Throwable e) {
225+
public static void logError(final String tag, final String msg, final Throwable e) {
226226
synchronized (Utils.class) {
227227
if (null != e) {
228228
Log.e(tag, msg, e);
@@ -255,7 +255,7 @@ public static void LogError(final String tag, final String msg, final Throwable
255255
}
256256
}
257257

258-
public static void LogInfo(final String tag, final String msg) {
258+
public static void logInfo(final String tag, final String msg) {
259259
synchronized (Utils.class) {
260260
Log.i(tag, msg);
261261
try {

0 commit comments

Comments
 (0)