UNPKG

3.45 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.loggerFrontendModule = void 0;
19const inversify_1 = require("inversify");
20const logger_protocol_1 = require("../common/logger-protocol");
21const logger_1 = require("../common/logger");
22const logger_watcher_1 = require("../common/logger-watcher");
23const messaging_1 = require("./messaging");
24const frontend_application_1 = require("./frontend-application");
25const rpc_message_encoder_1 = require("../common/message-rpc/rpc-message-encoder");
26exports.loggerFrontendModule = new inversify_1.ContainerModule(bind => {
27 bind(frontend_application_1.FrontendApplicationContribution).toDynamicValue(ctx => ({
28 initialize() {
29 (0, logger_1.setRootLogger)(ctx.container.get(logger_1.ILogger));
30 }
31 }));
32 bind(logger_1.LoggerName).toConstantValue(logger_1.rootLoggerName);
33 bind(logger_1.ILogger).to(logger_1.Logger).inSingletonScope().whenTargetIsDefault();
34 bind(logger_watcher_1.LoggerWatcher).toSelf().inSingletonScope();
35 bind(logger_protocol_1.ILoggerServer).toDynamicValue(ctx => {
36 const loggerWatcher = ctx.container.get(logger_watcher_1.LoggerWatcher);
37 const connection = ctx.container.get(messaging_1.WebSocketConnectionProvider);
38 const target = connection.createProxy(logger_protocol_1.loggerPath, loggerWatcher.getLoggerClient());
39 function get(_, property) {
40 if (property === 'log') {
41 return (name, logLevel, message, params) => {
42 logger_protocol_1.ConsoleLogger.log(name, logLevel, message, params);
43 return target.log(name, logLevel, message, params).catch(err => {
44 if (err instanceof rpc_message_encoder_1.EncodingError) {
45 // In case of an EncodingError no RPC call is sent to the backend `ILoggerServer`. Nevertheless, we want to continue normally.
46 return;
47 }
48 throw err;
49 });
50 };
51 }
52 return target[property];
53 }
54 return new Proxy(target, { get });
55 }).inSingletonScope();
56 bind(logger_1.LoggerFactory).toFactory(ctx => (name) => {
57 const child = new inversify_1.Container({ defaultScope: 'Singleton' });
58 child.parent = ctx.container;
59 child.bind(logger_1.ILogger).to(logger_1.Logger).inTransientScope();
60 child.bind(logger_1.LoggerName).toConstantValue(name);
61 return child.get(logger_1.ILogger);
62 });
63});
64//# sourceMappingURL=logger-frontend-module.js.map
\No newline at end of file