feat: keep the multiline log in single log (#4281)

This commit is contained in:
DarkSky
2023-09-08 17:33:46 +08:00
committed by GitHub
parent 157ce7ac69
commit a97fd486c3
5 changed files with 18 additions and 18 deletions
@@ -28,13 +28,12 @@ export class ExceptionLogger implements ExceptionFilter {
); );
this.logger.error( this.logger.error(
new Error( new Error(
`${requestId ? `requestId-${requestId}:` : ''}${exception.message}`, `${requestId ? `requestId-${requestId}: ` : ''}${exception.message}${
shouldVerboseLog ? '\n' + exception.stack : ''
}}`,
{ cause: exception } { cause: exception }
) )
); );
if (shouldVerboseLog) {
this.logger.error(exception.stack);
}
if (host.getType<GqlContextType>() === 'graphql') { if (host.getType<GqlContextType>() === 'graphql') {
return; return;
@@ -141,7 +141,7 @@ export class NextAuthController {
} }
if (redirect?.endsWith('api/auth/error?error=AccessDenied')) { if (redirect?.endsWith('api/auth/error?error=AccessDenied')) {
this.logger.log('Early access redirect headers ', req.headers); this.logger.log(`Early access redirect headers: ${req.headers}`);
this.metrics.authFailCounter(1, { this.metrics.authFailCounter(1, {
reason: 'no_early_access_permission', reason: 'no_early_access_permission',
}); });
+8 -8
View File
@@ -74,8 +74,9 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
} }
} catch (e) { } catch (e) {
this.logger.error( this.logger.error(
`Failed to apply updates, index: ${i}`, `Failed to apply updates, index: ${i}\nUpdate: ${updates
updates.map(u => u.toString('hex')) .map(u => u.toString('hex'))
.join('\n')}`
); );
} }
}); });
@@ -109,13 +110,12 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
} }
} catch (e) { } catch (e) {
this.metrics.jwstCodecFail(1, {}); this.metrics.jwstCodecFail(1, {});
this.logger.warn(`jwst apply update failed for :${guid}`, e); this.logger.warn(`jwst apply update failed for ${guid}: ${e}`);
log = true; log = true;
} finally { } finally {
if (log) { if (log) {
this.logger.warn( this.logger.warn(
'Updates:', `Updates: ${updates.map(u => u.toString('hex')).join('\n')}`
updates.map(u => u.toString('hex'))
); );
} }
} }
@@ -288,7 +288,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
.catch( .catch(
// transaction failed, it's safe to ignore // transaction failed, it's safe to ignore
e => { e => {
this.logger.error('Failed to fetch updates', e); this.logger.error(`Failed to fetch updates: ${e}`);
} }
); );
@@ -322,7 +322,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
await this.upsert(workspaceId, id, merged); await this.upsert(workspaceId, id, merged);
} catch (e) { } catch (e) {
// failed to merge updates, put them back // failed to merge updates, put them back
this.logger.error('Failed to merge updates', e); this.logger.error(`Failed to merge updates: ${e}`);
await this.db.update await this.db.update
.createMany({ .createMany({
@@ -334,7 +334,7 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
}) })
.catch(e => { .catch(e => {
// failed to recover, fallback TBD // failed to recover, fallback TBD
this.logger.error('Fetal: failed to put updates back to db', e); this.logger.error(`Fetal: failed to put updates back to db: ${e}`);
}); });
} }
} }
+2 -3
View File
@@ -140,12 +140,11 @@ export class RedisDocManager extends DocManager {
.ltrim(updateKey, updates.length, -1) .ltrim(updateKey, updates.length, -1)
// safe, fallback to mergeUpdates // safe, fallback to mergeUpdates
.catch(e => { .catch(e => {
this.logger.error('Failed to remove merged updates from Redis', e); this.logger.error(`Failed to remove merged updates from Redis: ${e}`);
}); });
} catch (e) { } catch (e) {
this.logger.error( this.logger.error(
`Failed to merge updates with snapshot for ${pendingDoc}`, `Failed to merge updates with snapshot for ${pendingDoc}: ${e}`
e
); );
await this.redis.sadd(pending, `${workspaceId}:${id}`).catch(() => null); // safe await this.redis.sadd(pending, `${workspaceId}:${id}`).catch(() => null); // safe
} finally { } finally {
@@ -41,7 +41,9 @@ export class WorkspacesController {
const blob = await this.storage.getBlob(workspaceId, name); const blob = await this.storage.getBlob(workspaceId, name);
if (!blob) { if (!blob) {
throw new NotFoundException('Blob not found'); throw new NotFoundException(
`Blob not found in workspace ${workspaceId}: ${name}`
);
} }
res.setHeader('content-type', blob.contentType); res.setHeader('content-type', blob.contentType);
@@ -78,6 +80,6 @@ export class WorkspacesController {
res.setHeader('content-type', 'application/octet-stream'); res.setHeader('content-type', 'application/octet-stream');
res.send(update); res.send(update);
this.logger.debug('workspaces doc api: ', format(process.hrtime(start))); this.logger.debug(`workspaces doc api: ${format(process.hrtime(start))}`);
} }
} }