Pass logging level to AVM (#158)

This commit is contained in:
Pavel 2022-07-07 12:52:32 +03:00 committed by GitHub
parent 2b752492c1
commit f0906066c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 11 deletions

View File

@ -20,7 +20,8 @@ import { FluencePeer, PeerConfig } from './internal/FluencePeer';
export { PeerStatus } from './internal/FluencePeer'; export { PeerStatus } from './internal/FluencePeer';
export { KeyPair } from './internal/KeyPair'; export { KeyPair } from './internal/KeyPair';
export { FluencePeer, MarineLoglevel as AvmLoglevel, PeerConfig } from './internal/FluencePeer'; export { FluencePeer, PeerConfig } from './internal/FluencePeer';
export { MarineLoglevel as AvmLoglevel } from './internal/utils';
export { PeerIdB58, CallParams } from './internal/commonTypes'; export { PeerIdB58, CallParams } from './internal/commonTypes';
export { loadWasmFromFileSystem, loadWasmFromNpmPackage, loadWasmFromServer } from '@fluencelabs/marine-js'; export { loadWasmFromFileSystem, loadWasmFromNpmPackage, loadWasmFromServer } from '@fluencelabs/marine-js';

View File

@ -20,7 +20,7 @@ import { PeerIdB58 } from './commonTypes';
import { FluenceConnection } from './FluenceConnection'; import { FluenceConnection } from './FluenceConnection';
import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle'; import { Particle, ParticleExecutionStage, ParticleQueueItem } from './Particle';
import { KeyPair } from './KeyPair'; import { KeyPair } from './KeyPair';
import { throwIfNotSupported, dataToString, jsonify } from './utils'; import { throwIfNotSupported, dataToString, jsonify, MarineLoglevel, marineLogLevelToEnvs } from './utils';
import { concatMap, filter, pipe, Subject, tap } from 'rxjs'; import { concatMap, filter, pipe, Subject, tap } from 'rxjs';
import log from 'loglevel'; import log from 'loglevel';
import { builtInServices } from './builtins/common'; import { builtInServices } from './builtins/common';
@ -40,12 +40,6 @@ type Node = {
multiaddr: string; multiaddr: string;
}; };
/**
* Enum representing the log level used in Aqua VM.
* Possible values: 'info', 'trace', 'debug', 'info', 'warn', 'error', 'off';
*/
export type MarineLoglevel = LogLevel;
const DEFAULT_TTL = 7000; const DEFAULT_TTL = 7000;
/** /**
@ -242,7 +236,12 @@ export class FluencePeer {
? await loadMarineAndAvm(config.marineJS.marineWasmPath, config.marineJS.avmWasmPath) ? await loadMarineAndAvm(config.marineJS.marineWasmPath, config.marineJS.avmWasmPath)
: await loadDefaults(); : await loadDefaults();
await this._fluenceAppService.init(marineDeps.marine); await this._fluenceAppService.init(marineDeps.marine);
await this._fluenceAppService.createService(marineDeps.avm, 'avm'); await this._fluenceAppService.createService(
marineDeps.avm,
'avm',
undefined,
marineLogLevelToEnvs(this._marineLogLevel),
);
this._avmRunner = config?.avmRunner || new AVM(this._fluenceAppService); this._avmRunner = config?.avmRunner || new AVM(this._fluenceAppService);
await this._avmRunner.init(config?.avmLogLevel || 'off'); await this._avmRunner.init(config?.avmLogLevel || 'off');
@ -309,8 +308,12 @@ export class FluencePeer {
throw new Error(`Service with '${serviceId}' id already exists`); throw new Error(`Service with '${serviceId}' id already exists`);
} }
const envs = this._marineLogLevel ? { WASM_LOG: this._marineLogLevel } : undefined; await this._fluenceAppService.createService(
await this._fluenceAppService.createService(wasm, serviceId, undefined, envs); wasm,
serviceId,
undefined,
marineLogLevelToEnvs(this._marineLogLevel),
);
this._marineServices.add(serviceId); this._marineServices.add(serviceId);
} }

View File

@ -19,6 +19,7 @@ import platform from 'platform';
import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from './commonTypes'; import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from './commonTypes';
import { FluencePeer } from './FluencePeer'; import { FluencePeer } from './FluencePeer';
import { LogLevel } from '@fluencelabs/avm';
import { ParticleExecutionStage } from './Particle'; import { ParticleExecutionStage } from './Particle';
import Buffer from './Buffer'; import Buffer from './Buffer';
@ -162,3 +163,12 @@ export function throwIfNotSupported() {
} }
} }
} }
/**
* Enum representing the log level used in Aqua VM.
* Possible values: 'info', 'trace', 'debug', 'info', 'warn', 'error', 'off';
*/
export type MarineLoglevel = LogLevel;
export const marineLogLevelToEnvs = (marineLogLevel: MarineLoglevel | undefined) =>
marineLogLevel ? { WASM_LOG: marineLogLevel } : undefined;