1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.loggerFrontendModule = void 0;
|
19 | const inversify_1 = require("inversify");
|
20 | const logger_protocol_1 = require("../common/logger-protocol");
|
21 | const logger_1 = require("../common/logger");
|
22 | const logger_watcher_1 = require("../common/logger-watcher");
|
23 | const messaging_1 = require("./messaging");
|
24 | const frontend_application_contribution_1 = require("./frontend-application-contribution");
|
25 | const rpc_message_encoder_1 = require("../common/message-rpc/rpc-message-encoder");
|
26 | exports.loggerFrontendModule = new inversify_1.ContainerModule(bind => {
|
27 | bind(frontend_application_contribution_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 |
|
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 |
|
\ | No newline at end of file |