mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-31 15:56:15 -06:00
include calling function name in log entries
This commit is contained in:
parent
ddc27dd983
commit
e86e663aa7
2 changed files with 23 additions and 9 deletions
|
|
@ -42,6 +42,7 @@ func (p *Processor) GetTargetAccountBy(
|
|||
// Fetch the target account from db.
|
||||
target, err := getTargetFromDB()
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
err := gtserror.Newf("error getting from db: %w", err)
|
||||
return nil, false, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +58,7 @@ func (p *Processor) GetTargetAccountBy(
|
|||
// Check whether target account is visible to requesting account.
|
||||
visible, err = p.visFilter.AccountVisible(ctx, requester, target)
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error checking visibility: %w", err)
|
||||
return nil, false, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +130,8 @@ func (p *Processor) GetVisibleTargetAccount(
|
|||
return target, nil
|
||||
}
|
||||
|
||||
// GetAPIAccount fetches the appropriate API account model depending on whether requester = target.
|
||||
// GetAPIAccount fetches the appropriate API account
|
||||
// model depending on whether requester = target.
|
||||
func (p *Processor) GetAPIAccount(
|
||||
ctx context.Context,
|
||||
requester *gtsmodel.Account,
|
||||
|
|
@ -148,14 +151,15 @@ func (p *Processor) GetAPIAccount(
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error converting account: %w", err)
|
||||
err := gtserror.Newf("error converting: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
return apiAcc, nil
|
||||
}
|
||||
|
||||
// GetAPIAccountBlocked fetches the limited "blocked" account model for given target.
|
||||
// GetAPIAccountBlocked fetches the limited
|
||||
// "blocked" account model for given target.
|
||||
func (p *Processor) GetAPIAccountBlocked(
|
||||
ctx context.Context,
|
||||
targetAcc *gtsmodel.Account,
|
||||
|
|
@ -165,7 +169,7 @@ func (p *Processor) GetAPIAccountBlocked(
|
|||
) {
|
||||
apiAccount, err := p.converter.AccountToAPIAccountBlocked(ctx, targetAcc)
|
||||
if err != nil {
|
||||
err = gtserror.Newf("error converting account: %w", err)
|
||||
err := gtserror.Newf("error converting: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
return apiAccount, nil
|
||||
|
|
@ -182,7 +186,7 @@ func (p *Processor) GetAPIAccountSensitive(
|
|||
) {
|
||||
apiAccount, err := p.converter.AccountToAPIAccountSensitive(ctx, targetAcc)
|
||||
if err != nil {
|
||||
err = gtserror.Newf("error converting account: %w", err)
|
||||
err := gtserror.Newf("error converting: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
return apiAccount, nil
|
||||
|
|
@ -226,8 +230,7 @@ func (p *Processor) getVisibleAPIAccounts(
|
|||
) []*apimodel.Account {
|
||||
// Start new log entry with
|
||||
// the above calling func's name.
|
||||
l := log.
|
||||
WithContext(ctx).
|
||||
l := log.WithContext(ctx).
|
||||
WithField("caller", log.Caller(calldepth+1))
|
||||
|
||||
// Preallocate slice according to expected length.
|
||||
|
|
|
|||
|
|
@ -194,6 +194,10 @@ func (p *Processor) GetAPIStatus(
|
|||
// GetVisibleAPIStatuses converts a slice of statuses to API
|
||||
// model statuses, filtering according to visibility to requester
|
||||
// along with given filter context, filters and user mutes.
|
||||
//
|
||||
// Please note that all errors will be logged at ERROR level,
|
||||
// but will not be returned. Callers are likely to run into
|
||||
// show-stopping errors in the lead-up to this function.
|
||||
func (p *Processor) GetVisibleAPIStatuses(
|
||||
ctx context.Context,
|
||||
requester *gtsmodel.Account,
|
||||
|
|
@ -202,6 +206,13 @@ func (p *Processor) GetVisibleAPIStatuses(
|
|||
filters []*gtsmodel.Filter,
|
||||
userMutes []*gtsmodel.UserMute,
|
||||
) []apimodel.Status {
|
||||
|
||||
// Start new log entry with
|
||||
// the calling function name
|
||||
// as a field in each entry.
|
||||
l := log.WithContext(ctx).
|
||||
WithField("caller", log.Caller(3))
|
||||
|
||||
// Compile mutes to useable user mutes for type converter.
|
||||
compUserMutes := usermute.NewCompiledUserMuteList(userMutes)
|
||||
|
||||
|
|
@ -215,7 +226,7 @@ func (p *Processor) GetVisibleAPIStatuses(
|
|||
status,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, "error checking visibility: %v", err)
|
||||
l.Errorf("error checking visibility: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +243,7 @@ func (p *Processor) GetVisibleAPIStatuses(
|
|||
compUserMutes,
|
||||
)
|
||||
if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) {
|
||||
log.Errorf(ctx, "error converting: %v", err)
|
||||
l.Errorf("error converting: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue