Skip to content

Commit 48a7233

Browse files
cortinicofacebook-github-bot
authored andcommitted
Convert RNLog to Kotlin
Summary: Convert RNLog to Kotlin Changelog: [Internal] [Changed] - Convert RNLog to Kotlin Reviewed By: mdvacca Differential Revision: D54010172 fbshipit-source-id: eff124f094248563a2b80575d5ca9e8dae2563f7
1 parent 8bced4b commit 48a7233

File tree

3 files changed

+116
-123
lines changed

3 files changed

+116
-123
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5603,20 +5603,20 @@ public abstract interface class com/facebook/react/util/RCTLog : com/facebook/re
56035603
public abstract fun logIfNoNativeHook (Ljava/lang/String;Ljava/lang/String;)V
56045604
}
56055605

5606-
public class com/facebook/react/util/RNLog {
5606+
public final class com/facebook/react/util/RNLog {
56075607
public static final field ADVICE I
56085608
public static final field ERROR I
5609+
public static final field INSTANCE Lcom/facebook/react/util/RNLog;
56095610
public static final field LOG I
56105611
public static final field MINIMUM_LEVEL_FOR_UI I
56115612
public static final field TRACE I
56125613
public static final field WARN I
5613-
public fun <init> ()V
5614-
public static fun a (Ljava/lang/String;)V
5615-
public static fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
5616-
public static fun e (Ljava/lang/String;)V
5617-
public static fun l (Ljava/lang/String;)V
5618-
public static fun t (Ljava/lang/String;)V
5619-
public static fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
5614+
public static final fun a (Ljava/lang/String;)V
5615+
public static final fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
5616+
public static final fun e (Ljava/lang/String;)V
5617+
public static final fun l (Ljava/lang/String;)V
5618+
public static final fun t (Ljava/lang/String;)V
5619+
public static final fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
56205620
}
56215621

56225622
public class com/facebook/react/viewmanagers/ActivityIndicatorViewManagerDelegate : com/facebook/react/uimanager/BaseViewManagerDelegate {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/util/RNLog.java

Lines changed: 0 additions & 115 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.util
9+
10+
import android.util.Log
11+
import com.facebook.common.logging.FLog
12+
import com.facebook.react.bridge.ReactContext
13+
import com.facebook.react.common.ReactConstants
14+
15+
/** Logging wrapper for FLog with LogBox support. */
16+
object RNLog {
17+
18+
const val MINIMUM_LEVEL_FOR_UI = Log.WARN
19+
const val LOG = Log.VERBOSE
20+
const val TRACE = Log.DEBUG
21+
const val ADVICE = Log.INFO
22+
const val WARN = Log.WARN
23+
const val ERROR = Log.ERROR
24+
25+
/**
26+
* Log a log level message tagged as React Native to the console.
27+
*
28+
* @param message The message to log.
29+
*/
30+
@JvmStatic
31+
fun l(message: String) {
32+
FLog.i(ReactConstants.TAG, message)
33+
}
34+
35+
/**
36+
* Log a trace level message tagged as React Native to the console.
37+
*
38+
* @param message The message to log.
39+
*/
40+
@JvmStatic
41+
fun t(message: String) {
42+
FLog.i(ReactConstants.TAG, message)
43+
}
44+
45+
/**
46+
* Log a warning level message tagged as React Native to the console. This warning will not be
47+
* shown in LogBox.
48+
*
49+
* @param message The message to log.
50+
*/
51+
@JvmStatic
52+
fun a(message: String) {
53+
FLog.w(ReactConstants.TAG, "(ADVICE)$message")
54+
}
55+
56+
/**
57+
* Log a warning level message tagged as React Native to the console and display in the app.
58+
*
59+
* @param context The React context of the application use to display the warning.
60+
* @param message The message to log.
61+
*/
62+
@JvmStatic
63+
fun w(context: ReactContext?, message: String) {
64+
logInternal(context, message, WARN)
65+
FLog.w(ReactConstants.TAG, message)
66+
}
67+
68+
/**
69+
* Log an error level message tagged as React Native to the console and display in the app.
70+
*
71+
* @param context The React context of the application use to display the error.
72+
* @param message The message to log.
73+
*/
74+
@JvmStatic
75+
fun e(context: ReactContext?, message: String) {
76+
logInternal(context, message, ERROR)
77+
FLog.e(ReactConstants.TAG, message)
78+
}
79+
80+
/**
81+
* Log an error level message tagged as React Native to the console. This error will not be shown
82+
* in LogBox.
83+
*
84+
* @param message The message to log.
85+
*/
86+
@JvmStatic
87+
fun e(message: String) {
88+
FLog.e(ReactConstants.TAG, message)
89+
}
90+
91+
private fun logInternal(context: ReactContext?, message: String?, level: Int) {
92+
if (level >= MINIMUM_LEVEL_FOR_UI) {
93+
if (context?.hasActiveReactInstance() == true && message != null) {
94+
context.getJSModule(RCTLog::class.java).logIfNoNativeHook(levelToString(level), message)
95+
}
96+
}
97+
}
98+
99+
private fun levelToString(level: Int): String =
100+
when (level) {
101+
LOG,
102+
TRACE -> "log"
103+
ADVICE,
104+
WARN -> "warn"
105+
ERROR -> "error"
106+
else -> "none"
107+
}
108+
}

0 commit comments

Comments
 (0)