about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.native.tsx1
-rw-r--r--src/lib/bitdrift.ts7
-rw-r--r--src/logger/index.ts24
3 files changed, 32 insertions, 0 deletions
diff --git a/src/App.native.tsx b/src/App.native.tsx
index 0d8d7a92e..bc38eec79 100644
--- a/src/App.native.tsx
+++ b/src/App.native.tsx
@@ -1,5 +1,6 @@
 import 'react-native-url-polyfill/auto'
 import '#/lib/sentry' // must be near top
+import '#/lib/bitdrift' // must be near top
 import '#/view/icons'
 
 import React, {useEffect, useState} from 'react'
diff --git a/src/lib/bitdrift.ts b/src/lib/bitdrift.ts
new file mode 100644
index 000000000..2b22155e7
--- /dev/null
+++ b/src/lib/bitdrift.ts
@@ -0,0 +1,7 @@
+import {init} from '@bitdrift/react-native'
+
+const BITDRIFT_API_KEY = process.env.BITDRIFT_API_KEY
+
+if (BITDRIFT_API_KEY) {
+  init(BITDRIFT_API_KEY, {url: 'https://api-bsky.bitdrift.io'})
+}
diff --git a/src/logger/index.ts b/src/logger/index.ts
index 7bd812af0..e4adc48e2 100644
--- a/src/logger/index.ts
+++ b/src/logger/index.ts
@@ -1,3 +1,9 @@
+import {
+  debug as bdDebug,
+  error as bdError,
+  info as bdInfo,
+  warn as bdWarn,
+} from '@bitdrift/react-native'
 import format from 'date-fns/format'
 import {nanoid} from 'nanoid/non-secure'
 
@@ -131,6 +137,20 @@ export const consoleTransport: Transport = (
   }
 }
 
+export const bitdriftTransport: Transport = (level, message) => {
+  const log = (
+    {
+      [LogLevel.Debug]: bdDebug,
+      [LogLevel.Info]: bdInfo,
+      [LogLevel.Log]: bdInfo,
+      [LogLevel.Warn]: bdWarn,
+      [LogLevel.Error]: bdError,
+    } as const
+  )[level]
+
+  log(message.toString())
+}
+
 export const sentryTransport: Transport = (
   level,
   message,
@@ -328,6 +348,10 @@ export class Logger {
  */
 export const logger = new Logger()
 
+if (!env.IS_TEST) {
+  logger.addTransport(bitdriftTransport)
+}
+
 if (env.IS_DEV && !env.IS_TEST) {
   logger.addTransport(consoleTransport)