Merge pull request #1813 from bluesky-social/eric/app-903-extract-logger-into-singleton
Add new logger
This commit is contained in:
commit
e49a3d8a56
70 changed files with 1109 additions and 176 deletions
|
@ -25,7 +25,7 @@ export async function setupState(serviceUri = DEFAULT_SERVICE) {
|
|||
rootStore.log.debug('Initial hydrate', {hasSession: !!data.session})
|
||||
rootStore.hydrate(data)
|
||||
} catch (e: any) {
|
||||
rootStore.log.error('Failed to load state from storage', e)
|
||||
rootStore.log.error('Failed to load state from storage', {error: e})
|
||||
}
|
||||
rootStore.attemptSessionResumption()
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ export class FeedSourceModel {
|
|||
try {
|
||||
await this.rootStore.preferences.addSavedFeed(this.uri)
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to save feed', error)
|
||||
this.rootStore.log.error('Failed to save feed', {error})
|
||||
} finally {
|
||||
track('CustomFeed:Save')
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ export class FeedSourceModel {
|
|||
try {
|
||||
await this.rootStore.preferences.removeSavedFeed(this.uri)
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to unsave feed', error)
|
||||
this.rootStore.log.error('Failed to unsave feed', {error})
|
||||
} finally {
|
||||
track('CustomFeed:Unsave')
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ export class FeedSourceModel {
|
|||
try {
|
||||
await this.rootStore.preferences.addPinnedFeed(this.uri)
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to pin feed', error)
|
||||
this.rootStore.log.error('Failed to pin feed', {error})
|
||||
} finally {
|
||||
track('CustomFeed:Pin', {
|
||||
name: this.displayName,
|
||||
|
@ -194,7 +194,7 @@ export class FeedSourceModel {
|
|||
} catch (e: any) {
|
||||
this.likeUri = undefined
|
||||
this.likeCount = (this.likeCount || 1) - 1
|
||||
this.rootStore.log.error('Failed to like feed', e)
|
||||
this.rootStore.log.error('Failed to like feed', {error: e})
|
||||
} finally {
|
||||
track('CustomFeed:Like')
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ export class FeedSourceModel {
|
|||
} catch (e: any) {
|
||||
this.likeUri = uri
|
||||
this.likeCount = (this.likeCount || 0) + 1
|
||||
this.rootStore.log.error('Failed to unlike feed', e)
|
||||
this.rootStore.log.error('Failed to unlike feed', {error: e})
|
||||
} finally {
|
||||
track('CustomFeed:Unlike')
|
||||
}
|
||||
|
|
|
@ -339,7 +339,7 @@ export class ListModel {
|
|||
try {
|
||||
await this.rootStore.preferences.addPinnedFeed(this.uri)
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to pin feed', error)
|
||||
this.rootStore.log.error('Failed to pin feed', {error})
|
||||
} finally {
|
||||
track('CustomFeed:Pin', {
|
||||
name: this.data?.name || '',
|
||||
|
@ -455,10 +455,12 @@ export class ListModel {
|
|||
this.error = cleanError(err)
|
||||
this.loadMoreError = cleanError(loadMoreErr)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user items', err)
|
||||
this.rootStore.log.error('Failed to fetch user items', {error: err})
|
||||
}
|
||||
if (loadMoreErr) {
|
||||
this.rootStore.log.error('Failed to fetch user items', loadMoreErr)
|
||||
this.rootStore.log.error('Failed to fetch user items', {
|
||||
error: loadMoreErr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ export class PostThreadModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch post thread', err)
|
||||
this.rootStore.log.error('Failed to fetch post thread', {error: err})
|
||||
}
|
||||
this.notFound = err instanceof GetPostThread.NotFoundError
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ export class ProfileModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch profile', err)
|
||||
this.rootStore.log.error('Failed to fetch profile', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ export class FeedsDiscoveryModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch popular feeds', err)
|
||||
this.rootStore.log.error('Failed to fetch popular feeds', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ export class SuggestedActorsModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch suggested actors', err)
|
||||
this.rootStore.log.error('Failed to fetch suggested actors', {error: err})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ export class NotificationsFeedItemModel {
|
|||
}
|
||||
this.rootStore.log.warn(
|
||||
'app.bsky.notifications.list served an unsupported record type',
|
||||
v,
|
||||
{record: v},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,9 @@ export class NotificationsFeedModel {
|
|||
this._setQueued(this._filterNotifications(queueModels))
|
||||
this._countUnread()
|
||||
} catch (e) {
|
||||
this.rootStore.log.error('NotificationsModel:syncQueue failed', {e})
|
||||
this.rootStore.log.error('NotificationsModel:syncQueue failed', {
|
||||
error: e,
|
||||
})
|
||||
} finally {
|
||||
this.lock.release()
|
||||
}
|
||||
|
@ -481,7 +483,9 @@ export class NotificationsFeedModel {
|
|||
this.lastSync ? this.lastSync.toISOString() : undefined,
|
||||
)
|
||||
} catch (e: any) {
|
||||
this.rootStore.log.warn('Failed to update notifications read state', e)
|
||||
this.rootStore.log.warn('Failed to update notifications read state', {
|
||||
error: e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -501,13 +505,12 @@ export class NotificationsFeedModel {
|
|||
this.error = cleanError(error)
|
||||
this.loadMoreError = cleanError(loadMoreError)
|
||||
if (error) {
|
||||
this.rootStore.log.error('Failed to fetch notifications', error)
|
||||
this.rootStore.log.error('Failed to fetch notifications', {error})
|
||||
}
|
||||
if (loadMoreError) {
|
||||
this.rootStore.log.error(
|
||||
'Failed to load more notifications',
|
||||
loadMoreError,
|
||||
)
|
||||
this.rootStore.log.error('Failed to load more notifications', {
|
||||
error: loadMoreError,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,17 +42,16 @@ export class PostsFeedItemModel {
|
|||
} else {
|
||||
this.postRecord = undefined
|
||||
this.richText = undefined
|
||||
rootStore.log.warn(
|
||||
'Received an invalid app.bsky.feed.post record',
|
||||
valid.error,
|
||||
)
|
||||
rootStore.log.warn('Received an invalid app.bsky.feed.post record', {
|
||||
error: valid.error,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.postRecord = undefined
|
||||
this.richText = undefined
|
||||
rootStore.log.warn(
|
||||
'app.bsky.feed.getTimeline or app.bsky.feed.getAuthorFeed served an unexpected record type',
|
||||
this.post.record,
|
||||
{record: this.post.record},
|
||||
)
|
||||
}
|
||||
this.reply = v.reply
|
||||
|
@ -133,7 +132,7 @@ export class PostsFeedItemModel {
|
|||
track('Post:Like')
|
||||
}
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to toggle like', error)
|
||||
this.rootStore.log.error('Failed to toggle like', {error})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +167,7 @@ export class PostsFeedItemModel {
|
|||
track('Post:Repost')
|
||||
}
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to toggle repost', error)
|
||||
this.rootStore.log.error('Failed to toggle repost', {error})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +181,7 @@ export class PostsFeedItemModel {
|
|||
track('Post:ThreadMute')
|
||||
}
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to toggle thread mute', error)
|
||||
this.rootStore.log.error('Failed to toggle thread mute', {error})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,7 +190,7 @@ export class PostsFeedItemModel {
|
|||
await this.rootStore.agent.deletePost(this.post.uri)
|
||||
this.rootStore.emitPostDeleted(this.post.uri)
|
||||
} catch (error) {
|
||||
this.rootStore.log.error('Failed to delete post', error)
|
||||
this.rootStore.log.error('Failed to delete post', {error})
|
||||
} finally {
|
||||
track('Post:Delete')
|
||||
}
|
||||
|
|
|
@ -324,13 +324,12 @@ export class PostsFeedModel {
|
|||
this.knownError = detectKnownError(this.feedType, error)
|
||||
this.loadMoreError = cleanError(loadMoreError)
|
||||
if (error) {
|
||||
this.rootStore.log.error('Posts feed request failed', error)
|
||||
this.rootStore.log.error('Posts feed request failed', {error})
|
||||
}
|
||||
if (loadMoreError) {
|
||||
this.rootStore.log.error(
|
||||
'Posts feed load-more request failed',
|
||||
loadMoreError,
|
||||
)
|
||||
this.rootStore.log.error('Posts feed load-more request failed', {
|
||||
error: loadMoreError,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,9 @@ export class InvitedUsers {
|
|||
})
|
||||
this.rootStore.me.follows.hydrateMany(this.profiles)
|
||||
} catch (e) {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch profiles for invited users',
|
||||
e,
|
||||
)
|
||||
this.rootStore.log.error('Failed to fetch profiles for invited users', {
|
||||
error: e,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ export class ActorFeedsModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
this.rootStore.log.error('Failed to fetch user followers', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ export class BlockedAccountsModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
this.rootStore.log.error('Failed to fetch user followers', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ export class LikesModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch likes', err)
|
||||
this.rootStore.log.error('Failed to fetch likes', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,10 +204,12 @@ export class ListsListModel {
|
|||
this.error = cleanError(err)
|
||||
this.loadMoreError = cleanError(loadMoreErr)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user lists', err)
|
||||
this.rootStore.log.error('Failed to fetch user lists', {error: err})
|
||||
}
|
||||
if (loadMoreErr) {
|
||||
this.rootStore.log.error('Failed to fetch user lists', loadMoreErr)
|
||||
this.rootStore.log.error('Failed to fetch user lists', {
|
||||
error: loadMoreErr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ export class MutedAccountsModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
this.rootStore.log.error('Failed to fetch user followers', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ export class RepostedByModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch reposted by view', err)
|
||||
this.rootStore.log.error('Failed to fetch reposted by view', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ export class UserFollowersModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
this.rootStore.log.error('Failed to fetch user followers', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,13 +110,17 @@ export class MeModel {
|
|||
await this.fetchProfile()
|
||||
this.mainFeed.clear()
|
||||
/* dont await */ this.mainFeed.setup().catch(e => {
|
||||
this.rootStore.log.error('Failed to setup main feed model', e)
|
||||
this.rootStore.log.error('Failed to setup main feed model', {error: e})
|
||||
})
|
||||
/* dont await */ this.notifications.setup().catch(e => {
|
||||
this.rootStore.log.error('Failed to setup notifications model', e)
|
||||
this.rootStore.log.error('Failed to setup notifications model', {
|
||||
error: e,
|
||||
})
|
||||
})
|
||||
/* dont await */ this.notifications.setup().catch(e => {
|
||||
this.rootStore.log.error('Failed to setup notifications model', e)
|
||||
this.rootStore.log.error('Failed to setup notifications model', {
|
||||
error: e,
|
||||
})
|
||||
})
|
||||
this.myFeeds.clear()
|
||||
/* dont await */ this.myFeeds.saved.refresh()
|
||||
|
@ -184,7 +188,9 @@ export class MeModel {
|
|||
})
|
||||
})
|
||||
} catch (e) {
|
||||
this.rootStore.log.error('Failed to fetch user invite codes', e)
|
||||
this.rootStore.log.error('Failed to fetch user invite codes', {
|
||||
error: e,
|
||||
})
|
||||
}
|
||||
await this.rootStore.invitedUsers.fetch(this.invites)
|
||||
}
|
||||
|
@ -199,7 +205,9 @@ export class MeModel {
|
|||
this.appPasswords = res.data.passwords
|
||||
})
|
||||
} catch (e) {
|
||||
this.rootStore.log.error('Failed to fetch user app passwords', e)
|
||||
this.rootStore.log.error('Failed to fetch user app passwords', {
|
||||
error: e,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +228,7 @@ export class MeModel {
|
|||
})
|
||||
return res.data
|
||||
} catch (e) {
|
||||
this.rootStore.log.error('Failed to create app password', e)
|
||||
this.rootStore.log.error('Failed to create app password', {error: e})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +243,7 @@ export class MeModel {
|
|||
this.appPasswords = this.appPasswords.filter(p => p.name !== name)
|
||||
})
|
||||
} catch (e) {
|
||||
this.rootStore.log.error('Failed to delete app password', e)
|
||||
this.rootStore.log.error('Failed to delete app password', {error: e})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ export class ImageModel implements Omit<RNImage, 'size'> {
|
|||
this.cropped = cropped
|
||||
})
|
||||
} catch (err) {
|
||||
this.rootStore.log.error('Failed to crop photo', err)
|
||||
this.rootStore.log.error('Failed to crop photo', {error: err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import {createContext, useContext} from 'react'
|
|||
import {DeviceEventEmitter, EmitterSubscription} from 'react-native'
|
||||
import {z} from 'zod'
|
||||
import {isObj, hasProp} from 'lib/type-guards'
|
||||
import {LogModel} from './log'
|
||||
import {SessionModel} from './session'
|
||||
import {ShellUiModel} from './ui/shell'
|
||||
import {HandleResolutionsCache} from './cache/handle-resolutions'
|
||||
|
@ -23,6 +22,7 @@ import {ImageSizesCache} from './cache/image-sizes'
|
|||
import {MutedThreads} from './muted-threads'
|
||||
import {Reminders} from './ui/reminders'
|
||||
import {reset as resetNavigation} from '../../Navigation'
|
||||
import {logger} from '#/logger'
|
||||
|
||||
// TEMPORARY (APP-700)
|
||||
// remove after backend testing finishes
|
||||
|
@ -41,7 +41,7 @@ export type AppInfo = z.infer<typeof appInfo>
|
|||
export class RootStoreModel {
|
||||
agent: BskyAgent
|
||||
appInfo?: AppInfo
|
||||
log = new LogModel()
|
||||
log = logger
|
||||
session = new SessionModel(this)
|
||||
shell = new ShellUiModel(this)
|
||||
preferences = new PreferencesModel(this)
|
||||
|
@ -130,7 +130,7 @@ export class RootStoreModel {
|
|||
})
|
||||
this.updateSessionState()
|
||||
} catch (e: any) {
|
||||
this.log.warn('Failed to initialize session', e)
|
||||
this.log.warn('Failed to initialize session', {error: e})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ export class RootStoreModel {
|
|||
await this.me.updateIfNeeded()
|
||||
await this.preferences.sync()
|
||||
} catch (e: any) {
|
||||
this.log.error('Failed to fetch latest state', e)
|
||||
this.log.error('Failed to fetch latest state', {error: e})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ export class CreateAccountModel {
|
|||
} catch (err: any) {
|
||||
this.rootStore.log.warn(
|
||||
`Failed to fetch service description for ${this.serviceUrl}`,
|
||||
err,
|
||||
{error: err},
|
||||
)
|
||||
this.setError(
|
||||
'Unable to contact your service. Please check your Internet connection.',
|
||||
|
@ -127,7 +127,7 @@ export class CreateAccountModel {
|
|||
errMsg =
|
||||
'Invite code not accepted. Check that you input it correctly and try again.'
|
||||
}
|
||||
this.rootStore.log.error('Failed to create account', e)
|
||||
this.rootStore.log.error('Failed to create account', {error: e})
|
||||
this.setIsProcessing(false)
|
||||
this.setError(cleanError(errMsg))
|
||||
throw e
|
||||
|
|
|
@ -223,10 +223,14 @@ export class ProfileUiModel {
|
|||
await Promise.all([
|
||||
this.profile
|
||||
.setup()
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch profile', err)),
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch profile', {error: err}),
|
||||
),
|
||||
this.feed
|
||||
.setup()
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch feed', err)),
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch feed', {error: err}),
|
||||
),
|
||||
])
|
||||
runInAction(() => {
|
||||
this.isAuthenticatedUser =
|
||||
|
@ -237,7 +241,9 @@ export class ProfileUiModel {
|
|||
this.lists.source = this.profile.did
|
||||
this.lists
|
||||
.loadMore()
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch lists', err))
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch lists', {error: err}),
|
||||
)
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
|
|
|
@ -126,7 +126,7 @@ export class SavedFeedsModel {
|
|||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user feeds', err)
|
||||
this.rootStore.log.error('Failed to fetch user feeds', {err})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue