refactor(audit): unify computerName source to cached os.hostname()
Export cachedHostname from audit-logger and use it in process-guards, replacing process.env.COMPUTERNAME so all audit entries use the same value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
import logger from '../services/logger/index'
|
import logger from '../services/logger/index'
|
||||||
import { logAudit, closeAuditLogger } from '../services/logger/audit-logger'
|
import { logAudit, closeAuditLogger, cachedHostname } from '../services/logger/audit-logger'
|
||||||
import { AuditAction, AuditStatus } from '../types/audit.types'
|
import { AuditAction, AuditStatus } from '../types/audit.types'
|
||||||
import { serializeError } from '../services/logger/error-utils'
|
import { serializeError } from '../services/logger/error-utils'
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ export function setupProcessGuards(): void {
|
|||||||
try {
|
try {
|
||||||
logAudit(AuditAction.SYSTEM_CRASH, 'system', {
|
logAudit(AuditAction.SYSTEM_CRASH, 'system', {
|
||||||
username: 'system',
|
username: 'system',
|
||||||
computerName: process.env.COMPUTERNAME || 'unknown',
|
computerName: cachedHostname,
|
||||||
resource: 'main-process',
|
resource: 'main-process',
|
||||||
status: AuditStatus.FAILURE,
|
status: AuditStatus.FAILURE,
|
||||||
metadata: { error: err.message, stack: err.stack }
|
metadata: { error: err.message, stack: err.stack }
|
||||||
@@ -29,7 +29,7 @@ export function setupProcessGuards(): void {
|
|||||||
try {
|
try {
|
||||||
logAudit(AuditAction.SYSTEM_ERROR, 'system', {
|
logAudit(AuditAction.SYSTEM_ERROR, 'system', {
|
||||||
username: 'system',
|
username: 'system',
|
||||||
computerName: process.env.COMPUTERNAME || 'unknown',
|
computerName: cachedHostname,
|
||||||
resource: 'main-process',
|
resource: 'main-process',
|
||||||
status: AuditStatus.FAILURE,
|
status: AuditStatus.FAILURE,
|
||||||
metadata: errorMeta
|
metadata: errorMeta
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export function logAudit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Cached hostname — invariant for the app lifecycle */
|
/** Cached hostname — invariant for the app lifecycle */
|
||||||
const cachedHostname = hostname()
|
export const cachedHostname = hostname()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audit log shortcut that auto-resolves the current user context.
|
* Audit log shortcut that auto-resolves the current user context.
|
||||||
|
|||||||
Reference in New Issue
Block a user