mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-29 21:01:27 +00:00
dev: improve actor logs
This commit adds the concept of a toLogFields method on objects which will determine how they're turned into log fields in LogService. This method is now implemented on actor to prevent errors when the object is passed to log functions without being stringified first.
This commit is contained in:
@@ -30,6 +30,7 @@ const winston = require('winston');
|
||||
const { Context } = require('../../util/context');
|
||||
const BaseService = require('../../services/BaseService');
|
||||
const { stringify_log_entry } = require('./lib/log');
|
||||
const { whatis } = require('../../util/langutil');
|
||||
require('winston-daily-rotate-file');
|
||||
|
||||
const WINSTON_LEVELS = {
|
||||
@@ -99,12 +100,18 @@ class LogContext {
|
||||
}
|
||||
if ( ! fields.actor && x && x.get('actor') ) {
|
||||
try {
|
||||
fields.actor = x.get('actor').uid;
|
||||
fields.actor = x.get('actor');
|
||||
} catch (e) {
|
||||
console.log('error logging actor (this is probably fine):', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( const k in fields ) {
|
||||
if (
|
||||
whatis(fields[k]) === 'object' &&
|
||||
typeof fields[k].toLogFields === 'function'
|
||||
) fields[k] = fields[k].toLogFields();
|
||||
}
|
||||
this.logService.log_(
|
||||
log_level,
|
||||
this.crumbs,
|
||||
|
||||
@@ -91,6 +91,15 @@ class Actor extends AdvancedBase {
|
||||
get uid () {
|
||||
return this.type.uid;
|
||||
}
|
||||
|
||||
toLogFields () {
|
||||
return {
|
||||
uid: this.type.uid,
|
||||
...(this.type.user ? {
|
||||
username: this.type.user.username,
|
||||
} : {})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cryptographically-secure deterministic UUID
|
||||
|
||||
Reference in New Issue
Block a user