Skip to content

Commit

Permalink
fix: Logging level is now configurable via config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlustra committed Jun 28, 2021
1 parent 3a2aac7 commit a1870e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const readFile = promisify(_readFile);


export interface ServerConfig {
loggingLevel?: string;
agent?: AgentConfig;
connectors: ConnectorConfig[] | ConnectorConfig;
}
Expand Down
17 changes: 15 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ApolloServer } from "apollo-server-express";
import { Logger, createLogger, transports, format } from "winston";
import { ContextDependencies, serverOptions } from "./schema";
import { getServerConfig } from "./config";
import { map, share, tap } from "rxjs/operators";
import { filter, map, share, tap } from "rxjs/operators";
import { getConnector } from "./connectors";
import { createConnectionPool } from "./connection-pool";
import { createItemServer } from "./item-server";
Expand Down Expand Up @@ -53,7 +53,12 @@ function watchConfig(filePath: string, logger: Logger) {
)
);
const agentConfig$ = config$.pipe(map((config) => config.agent));
const loggingLevel$ = config$.pipe(
map((config) => config.loggingLevel),
filter(Boolean)
);
return {
loggingLevel$,
connectors$,
agentConfig$,
};
Expand Down Expand Up @@ -124,7 +129,14 @@ async function startServer() {
],
});
logger.verbose("watchConfig");
const { connectors$, agentConfig$ } = watchConfig(localConfigFile, logger);
const { connectors$, agentConfig$, loggingLevel$ } = watchConfig(
localConfigFile,
logger
);

const loggingLevelSubscription = loggingLevel$.subscribe(
(level) => (logger.level = level)
);

logger.verbose("createConnectionPool");
const connectionPool = createConnectionPool(logger);
Expand Down Expand Up @@ -164,6 +176,7 @@ async function startServer() {
tryQuietly(frontend.close);
tryQuietly(connectorSubscription.unsubscribe);
tryQuietly(agentSubscription.unsubscribe);
tryQuietly(loggingLevelSubscription.unsubscribe);
tryQuietly(api.stop);
tryQuietly(() => httpServer.close(() => logger.info("HTTP Server Closed")));
logger.crit("Server Stopped");
Expand Down

0 comments on commit a1870e0

Please sign in to comment.