@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
60 lines • 3.12 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2017 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { ContainerModule, Container } from 'inversify';
import { ILoggerServer, loggerPath, ConsoleLogger } from '../common/logger-protocol.js';
import { ILogger, Logger, LoggerFactory, setRootLogger, LoggerName } from '../common/logger.js';
import { LoggerWatcher } from '../common/logger-watcher.js';
import { WebSocketConnectionProvider } from './messaging/index.js';
import { FrontendApplicationContribution } from './frontend-application-contribution.js';
import { EncodingError } from '../common/message-rpc/rpc-message-encoder.js';
import { bindCommonLogger } from '../common/logger-binding.js';
export const loggerFrontendModule = new ContainerModule(bind => {
bind(FrontendApplicationContribution).toDynamicValue(ctx => ({
initialize() {
setRootLogger(ctx.container.get(ILogger));
}
}));
bindCommonLogger(bind);
bind(ILoggerServer).toDynamicValue(ctx => {
const loggerWatcher = ctx.container.get(LoggerWatcher);
const connection = ctx.container.get(WebSocketConnectionProvider);
const target = connection.createProxy(loggerPath, loggerWatcher.getLoggerClient());
function get(_, property) {
if (property === 'log') {
return (name, logLevel, message, params) => {
ConsoleLogger.log(name, logLevel, message, params);
return target.log(name, logLevel, message, params).catch(err => {
if (err instanceof EncodingError) {
// In case of an EncodingError no RPC call is sent to the backend `ILoggerServer`. Nevertheless, we want to continue normally.
return;
}
throw err;
});
};
}
return target[property];
}
return new Proxy(target, { get });
}).inSingletonScope();
bind(LoggerFactory).toFactory(ctx => (name) => {
const child = new Container({ defaultScope: 'Singleton' });
child.parent = ctx.container;
child.bind(ILogger).to(Logger).inTransientScope();
child.bind(LoggerName).toConstantValue(name);
return child.get(ILogger);
});
});
//# sourceMappingURL=logger-frontend-module.js.map