Skip to content

Commit

Permalink
fix logging config reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Matchlighter committed Feb 29, 2024
1 parent e8f87f5 commit 097d4b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/hypervisor/application_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ export class ApplicationInstance extends BaseInstance<AppConfiguration, Applicat
throw new RequireRestart()
}

handle("logging", () => this._updateLogConfig())
handle("logging", () => {
this.options.logging = ncfg.logging;
this._updateLogConfig();
})
});
const disposer = this.hypervisor.watchConfigEntry<AppConfiguration>(`apps.${this.id}`, handler);
this.cleanups.append(disposer);
Expand Down Expand Up @@ -232,7 +235,7 @@ export class ApplicationInstance extends BaseInstance<AppConfiguration, Applicat

this.resumableStore = new ResumableStore({
file: path.join(this.operating_directory, ".resumable_state.json"),
logger: this.logger,
logMessage: (...rest) => this.logMessage(...rest),
}, {
"APPLICATION": this._instance,
})
Expand Down
12 changes: 8 additions & 4 deletions src/hypervisor/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,14 @@ export function createDomainLogger(opts: LoggerOptions) {

export type LogAMessage = typeof logMessage;

/** Log a message to the app stream */
export function logClientMessage(level: LogLevel, ...rest: any[]) {
const ctx = current.application;
const logger = ctx?.userSpaceLogger || UNKNOWN_LOGGER
logger.logMessage(level, rest);
}

/** Log a message from an app-bound plugin to the app stream */
export function logPluginClientMessage(plugin: any, level: LogLevel, ...rest: any[]) {
if (!(plugin instanceof PluginInstance)) plugin = plugin[HyperWrapper];

Expand All @@ -297,14 +299,16 @@ export function logPluginClientMessage(plugin: any, level: LogLevel, ...rest: an
logger.logMessage(level, ["[" + chalk.blueBright`${plugin.id}` + "]", ...rest], {});
}

export function logMessage(level: LogLevel, ...rest: any[]) {
const ctx = current.application || current.hypervisor;
/** Log a message to the HV stream */
export function logHVMessage(level: LogLevel, ...rest: any[]) {
const ctx = current.hypervisor;
const logger = ctx?.logger || UNKNOWN_LOGGER
logger.logMessage(level, rest);
}

export function logHVMessage(level: LogLevel, ...rest: any[]) {
const ctx = current.hypervisor;
/** Log a message to the app stream if present, else to the HV stream */
export function logMessage(level: LogLevel, ...rest: any[]) {
const ctx = current.application || current.hypervisor;
const logger = ctx?.logger || UNKNOWN_LOGGER
logger.logMessage(level, rest);
}
Expand Down
7 changes: 5 additions & 2 deletions src/hypervisor/plugin_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class PluginInstance extends BaseInstance<PluginConfiguration, Plugin> {

// Self-watch for config changes
if (this.options.watch?.config) {
const handler = configChangeHandler(this, async ({ handle }) => {
handle("logging", () => this._updateLogConfig())
const handler = configChangeHandler(this, async ({ handle, ncfg, ocfg }) => {
handle("logging", () => {
this.options.logging = ncfg.logging;
this._updateLogConfig();
});
});
const disposer = this.hypervisor.watchConfigEntry<PluginConfiguration>(`plugins.${this.id}`, handler);
this.cleanups.append(disposer);
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/resumable/resumable_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TrackerEntry {

interface StoreOptions {
file: string,
logger: ExtendedLoger;
logMessage: ExtendedLoger['logMessage'];
}

export class ResumableStore {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class ResumableStore {
}

protected logMessage(level: LogLevel, ...rest) {
this.opts.logger.logMessage(level, rest);
this.opts.logMessage(level, rest);
}

private async _loadWithLookups(serialized: any) {
Expand Down

0 comments on commit 097d4b0

Please sign in to comment.