0
# Configuration
1
2
Firebase SDK configuration, logging control, and React Native-specific settings management functionality.
3
4
## Capabilities
5
6
### Set Log Level
7
8
Controls the log level across all Firebase SDKs. Currently only applies to iOS, has no effect on Android.
9
10
```typescript { .api }
11
/**
12
* Sets the log level across all Firebase SDKs
13
* @param logLevel - The log level to set ('debug', 'verbose', 'info', 'warn', 'error', 'silent')
14
* Note: iOS only - Android is not affected
15
* Note: 'verbose' maps to 'debug' on iOS, 'silent' returns error if used
16
* Note: Apps from AppStore never log above 'info' regardless of setting
17
*/
18
function setLogLevel(logLevel: LogLevelString): void;
19
```
20
21
**Usage Examples:**
22
23
```typescript
24
import { setLogLevel } from '@react-native-firebase/app';
25
26
// Set log level to debug (most verbose)
27
setLogLevel('debug');
28
29
// Set log level to error (least verbose)
30
setLogLevel('error');
31
32
// Production setting
33
setLogLevel('warn');
34
```
35
36
### Set AsyncStorage
37
38
Configures the AsyncStorage implementation to use for persisting data on non-native platforms.
39
40
```typescript { .api }
41
/**
42
* Sets the AsyncStorage implementation to use for persisting data on 'Other' platforms
43
* If not specified, in memory persistence is used
44
* This is required if you want to persist things like Auth sessions, Analytics device IDs, etc.
45
* @param asyncStorage - The AsyncStorage implementation to use
46
*/
47
function setReactNativeAsyncStorage(asyncStorage: ReactNativeAsyncStorage): void;
48
```
49
50
**Usage Examples:**
51
52
```typescript
53
import { setReactNativeAsyncStorage } from '@react-native-firebase/app';
54
import AsyncStorage from '@react-native-async-storage/async-storage';
55
56
// Set AsyncStorage for persistence
57
setReactNativeAsyncStorage(AsyncStorage);
58
59
// Custom AsyncStorage implementation
60
const customStorage = {
61
setItem: async (key: string, value: string) => {
62
// Custom implementation
63
console.log(`Setting ${key} = ${value}`);
64
},
65
getItem: async (key: string) => {
66
// Custom implementation
67
console.log(`Getting ${key}`);
68
return null;
69
},
70
removeItem: async (key: string) => {
71
// Custom implementation
72
console.log(`Removing ${key}`);
73
}
74
};
75
76
setReactNativeAsyncStorage(customStorage);
77
```
78
79
### Log Handler
80
81
Sets a custom log handler for Firebase SDKs. Currently only supported for VertexAI module.
82
83
```typescript { .api }
84
/**
85
* Sets log handler for Firebase SDKs (currently only VertexAI)
86
* @param logCallback - The callback function to handle logs
87
* @param options - Optional settings for log handling
88
*/
89
function onLog(logCallback: (params: LogCallbackParams) => void, options?: any): void;
90
```
91
92
**Usage Examples:**
93
94
```typescript
95
import { onLog } from '@react-native-firebase/app';
96
97
// Set up custom log handler
98
onLog((params) => {
99
console.log(`[${params.level}] ${params.message}`, params.args);
100
101
// Custom logging logic
102
if (params.level === 'error') {
103
// Send error to crash reporting
104
crashlytics().recordError(new Error(params.message));
105
}
106
});
107
108
// Advanced log handling with filtering
109
onLog((params) => {
110
// Only log warnings and errors in production
111
if (__DEV__ || ['warn', 'error'].includes(params.level)) {
112
console.log(`${params.type}: ${params.message}`);
113
}
114
}, {
115
// Options object (structure depends on implementation)
116
captureLevel: 'warn'
117
});
118
```
119
120
## Traditional Firebase API
121
122
Configuration functions are also available through the traditional Firebase API:
123
124
```typescript
125
import firebase from '@react-native-firebase/app';
126
127
// Set log level (traditional style)
128
firebase.setLogLevel('debug');
129
130
// Set AsyncStorage (traditional style)
131
firebase.setReactNativeAsyncStorage(AsyncStorage);
132
```
133
134
## Types
135
136
```typescript { .api }
137
type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
138
139
interface LogCallbackParams {
140
level: LogLevelString;
141
message: string;
142
args: unknown[];
143
type: string;
144
}
145
146
interface ReactNativeAsyncStorage {
147
setItem: Function;
148
getItem: Function;
149
removeItem: Function;
150
[key: string]: any;
151
}
152
```
153
154
## Platform Considerations
155
156
- **Log Levels**: Only effective on iOS. Android logging is controlled through native configuration.
157
- **AsyncStorage**: Required for data persistence on web and other non-native platforms. Native platforms have built-in persistence.
158
- **Log Handler**: Currently only supported for VertexAI module. Other modules may add support in future versions.
159
160
## Best Practices
161
162
```typescript
163
import { setLogLevel, setReactNativeAsyncStorage, onLog } from '@react-native-firebase/app';
164
import AsyncStorage from '@react-native-async-storage/async-storage';
165
166
// Configure Firebase at app startup
167
export function initializeFirebaseConfig() {
168
// Set appropriate log level
169
if (__DEV__) {
170
setLogLevel('debug');
171
} else {
172
setLogLevel('warn');
173
}
174
175
// Configure AsyncStorage for persistence
176
setReactNativeAsyncStorage(AsyncStorage);
177
178
// Set up error logging
179
onLog((params) => {
180
if (params.level === 'error') {
181
// Log to crash reporting service
182
console.error('Firebase Error:', params.message, params.args);
183
}
184
});
185
}
186
```