Skip to content

Commit

Permalink
chore: cleanup log4js imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Tethik committed Oct 4, 2023
1 parent b94bb7f commit 449cb23
Show file tree
Hide file tree
Showing 28 changed files with 53 additions and 88 deletions.
5 changes: 2 additions & 3 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { errorWrap } from "./util/errorHandler.js";
import path from "path";
import { Role } from "@gram/core/dist/auth/models/Role.js";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { metricsMiddleware } from "./metrics/metrics.js";
import {
authRequiredMiddleware,
Expand Down Expand Up @@ -54,7 +53,7 @@ export async function createApp(dal: DataAccessLayer) {
app.use(securityHeaders());

const loggerMwOpts = {
logger: getLogger("auditHttp"),
logger: log4js.getLogger("auditHttp"),
...config.log.auditHttp,
};

Expand Down
5 changes: 2 additions & 3 deletions api/src/healthchecks/notificationsCheck.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import physical from "express-physical";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

const log = getLogger("notificationsCheck");
const log = log4js.getLogger("notificationsCheck");

export function notificationsFailedCheck(dal: DataAccessLayer) {
return async (done: any) => {
Expand Down
5 changes: 2 additions & 3 deletions api/src/healthchecks/postgresCheck.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import physical from "express-physical";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

const log = getLogger("postgresCheck");
const log = log4js.getLogger("postgresCheck");

export async function postgresSimpleQueryCheck(dal: DataAccessLayer) {
return async (done: any) => {
Expand Down
5 changes: 2 additions & 3 deletions api/src/middlewares/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import * as jwt from "@gram/core/dist/auth/jwt.js";
import * as Sentry from "@sentry/node";
import { NextFunction, Response } from "express";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { hasSentry } from "../util/sentry.js";

const log = getLogger("authMw");
const log = log4js.getLogger("authMw");

export async function validateTokenMiddleware(
req: any,
Expand Down
5 changes: 2 additions & 3 deletions api/src/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { AuthzError } from "@gram/core/dist/auth/AuthzError.js";
import {
InvalidInputError,
NotAuthenticatedError,
NotFoundError,
} from "@gram/core/dist/util/errors.js";

const log = getLogger("app");
const log = log4js.getLogger("app");

export default function errorHandler(err: any, req: any, res: any, next: any) {
if (err instanceof NotAuthenticatedError) {
Expand Down
8 changes: 3 additions & 5 deletions api/src/resources/gram/v1/admin/setRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
* @exports {function} handler
*/

import { Request, Response } from "express";
import { Role } from "@gram/core/dist/auth/models/Role.js";
import * as jwt from "@gram/core/dist/auth/jwt.js";
import pkg from "log4js";
const { getLogger } = pkg;
import { UserToken } from "@gram/core/dist/auth/models/UserToken.js";
import { Request, Response } from "express";
import log4js from "log4js";

const log = getLogger("dropRole");
const log = log4js.getLogger("dropRole");

export default async function setRoles(req: Request, res: Response) {
const { roles } = req.body;
Expand Down
4 changes: 0 additions & 4 deletions api/src/resources/gram/v1/controls/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
* @exports {function} handler
*/
import { Request, Response } from "express";
import pkg from "log4js";
const { getLogger } = pkg;
import { Permission } from "@gram/core/dist/auth/authorization.js";
import Control from "@gram/core/dist/data/controls/Control.js";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import Mitigation from "@gram/core/dist/data/mitigations/Mitigation.js";
import { validateUUID } from "@gram/core/dist/util/uuid.js";

const log = getLogger("controls.create");

export function create(dal: DataAccessLayer) {
return async (req: Request, res: Response) => {
const { title, description, componentId, threatIds } = req.body;
Expand Down
5 changes: 2 additions & 3 deletions api/src/resources/gram/v1/token/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import IdentityProviderRegistry from "@gram/core/dist/auth/IdentityProviderRegis
import * as jwt from "@gram/core/dist/auth/jwt.js";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import { UserToken } from "@gram/core/dist/auth/models/UserToken.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

const log = getLogger("getAuthToken");
const log = log4js.getLogger("getAuthToken");

export const getAuthToken =
(dal: DataAccessLayer) => async (req: Request, res: Response) => {
Expand Down
5 changes: 2 additions & 3 deletions api/src/util/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { RewriteFrames } from "@sentry/integrations";
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";
import { Express } from "express";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { config } from "@gram/core/dist/config/index.js";
import { version } from "./version.js";

const log = getLogger("sentry");
const log = log4js.getLogger("sentry");

// TODO: move to configuration
const ALLOWED_HEADERS = [
Expand Down
5 changes: 2 additions & 3 deletions api/src/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { IncomingMessage, Server } from "http";
import url from "url";
import WebSocket from "ws";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { ModelWebsocketServer } from "./model.js";
import { config } from "@gram/core/dist/config/index.js";

const log = getLogger("wss");
const log = log4js.getLogger("wss");
const wssRegistry = new Map<string, ModelWebsocketServer>();

function validateRequestOrigin(request: IncomingMessage) {
Expand Down
5 changes: 2 additions & 3 deletions api/src/ws/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
import { UserToken } from "@gram/core/dist/auth/models/UserToken.js";
import { DataAccessLayer } from "@gram/core/dist/data/dal.js";
import Model from "@gram/core/dist/data/models/Model.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import * as jwt from "@gram/core/dist/auth/jwt.js";

// Hack to easily mock the permissions for testing.
Expand All @@ -21,7 +20,7 @@ export class ModelWebsocketServer {
this.model = model;
this.dal = dal;
this.server = new WebSocket.Server({ noServer: true });
this.log = getLogger(`ModelWebsocketServer [${this.id}]`);
this.log = log4js.getLogger(`ModelWebsocketServer [${this.id}]`);
this.bind();
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/config/ExposedSecret.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Secret } from "./Secret.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

const log = getLogger("ExposedSecret");
const log = log4js.getLogger("ExposedSecret");

export class ExposedSecret implements Secret {
constructor(public value: string) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { GramConfiguration } from "./GramConfiguration.js";
import { configurationMap } from "./configMap.js";

const log = getLogger("config");
const log = log4js.getLogger("config");

export function loadConfig() {
let env = process.env.NODE_ENV;
Expand Down
5 changes: 2 additions & 3 deletions core/src/data/component-classes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

export type ComponentType = "process" | "datastore" | "external";
export const ComponentTypes = ["process", "datastore", "external"];
Expand Down Expand Up @@ -36,7 +35,7 @@ export class ComponentClassHandler {
constructor() {
this.lookup = new Map();
ComponentTypes.forEach((ct) => this.lookup.set(ct as ComponentType, []));
this.log = getLogger("ComponentClassHandler");
this.log = log4js.getLogger("ComponentClassHandler");
}

lookup: Map<ComponentType, ComponentClass[]>;
Expand Down
5 changes: 2 additions & 3 deletions core/src/data/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pg from "pg";
import metricsClient from "prom-client";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { config } from "../config/index.js";

const log = getLogger("postgres");
const log = log4js.getLogger("postgres");

type Transaction<T> = (client: pg.PoolClient) => Promise<T>;

Expand Down
5 changes: 2 additions & 3 deletions core/src/data/suggestions/SuggestionDataService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EventEmitter } from "events";
import { Pool, QueryResult } from "pg";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import {
EngineSuggestedResult,
SuggestionID,
Expand Down Expand Up @@ -51,7 +50,7 @@ function convertToSuggestionThreat(row: any) {
export class SuggestionDataService extends EventEmitter {
constructor(private pool: Pool, private dal: DataAccessLayer) {
super();
this.log = getLogger("SuggestionDataService");
this.log = log4js.getLogger("SuggestionDataService");
}

log: any;
Expand Down
5 changes: 2 additions & 3 deletions core/src/data/system-property/SystemPropertyHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { RequestContext } from "../providers/RequestContext.js";
import { SystemProperty, SystemPropertyValue } from "./types.js";
import { SystemPropertyProvider } from "./SystemPropertyProvider.js";
Expand All @@ -9,7 +8,7 @@ export class SystemPropertyHandler {
this.providers = [];
this.properties = new Map();
this.providedBy = new Map();
this.log = getLogger("SystemPropertyHandler");
this.log = log4js.getLogger("SystemPropertyHandler");
}

log: any;
Expand Down
5 changes: 2 additions & 3 deletions core/src/data/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pg from "pg";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";

const log = getLogger("UtilsDataService");
const log = log4js.getLogger("UtilsDataService");

export async function _deleteAllTheThings(pool: pg.Pool) {
if (process.env.NODE_ENV !== "test") {
Expand Down
4 changes: 0 additions & 4 deletions core/src/notifications/TemplateHandler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { NotificationTemplateKey } from "../data/notifications/NotificationInput.js";
import pkg from "log4js";
const { getLogger } = pkg;
import {
NotificationTemplate,
NotificationVariables,
} from "./NotificationTemplate.js";

const log = getLogger("TemplateHandler");

export class TemplateHandler {
private templates: Map<NotificationTemplateKey, NotificationTemplate> =
new Map();
Expand Down
5 changes: 2 additions & 3 deletions core/src/notifications/email.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Message, SMTPClient } from "emailjs";
import { Notification } from "../data/notifications/Notification.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { TemplateHandler } from "./TemplateHandler.js";
import { sanitizeEmail } from "../util/sanitize.js";
import { config } from "../config/index.js";

const log = getLogger("email");
const log = log4js.getLogger("email");

/**
* Sanitizes recipient names by removing special email characters.
Expand Down
5 changes: 2 additions & 3 deletions core/src/suggestions/engine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DataAccessLayer } from "../data/dal.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import {
EngineSuggestedResult,
SourceSuggestedControl,
Expand All @@ -15,7 +14,7 @@ const SUGGESTION_DELAY =

export class SuggestionEngine {
public sources: SuggestionSource[] = [];
log = getLogger("SuggestionEngine");
log = log4js.getLogger("SuggestionEngine");

// One timeout per ModelID: should be threadsafe because node runs singlethreaded ;))
delayer = new Map<string, NodeJS.Timeout>();
Expand Down
5 changes: 2 additions & 3 deletions plugins/github/src/GithubAuthzProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { App } from "octokit";
import {
AllPermissions,
Expand All @@ -12,7 +11,7 @@ import { RequestContext } from "@gram/core/dist/data/providers/RequestContext.js
import { NotFoundError } from "@gram/core/dist/util/errors.js";
import { Role } from "@gram/core/dist/auth/models/Role.js";

const log = getLogger("GithubAuthzProvider");
const log = log4js.getLogger("GithubAuthzProvider");

export class GithubAuthzProvider implements AuthzProvider {
constructor(private app: App) {}
Expand Down
5 changes: 2 additions & 3 deletions plugins/github/src/GithubSystemPropertyProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { App } from "octokit";
import {
SystemProperty,
Expand All @@ -9,7 +8,7 @@ import { RequestContext } from "@gram/core/dist/data/providers/RequestContext.js
import { GithubSystemProvider } from "./GithubSystemProvider.js";
import { SystemPropertyProvider } from "@gram/core/dist/data/system-property/SystemPropertyProvider.js";

const log = getLogger("GithubSystemProvider");
const log = log4js.getLogger("GithubSystemProvider");

export class GithubSystemPropertyProvider implements SystemPropertyProvider {
constructor(private app: App, private sysProvider: GithubSystemProvider) {}
Expand Down
5 changes: 2 additions & 3 deletions plugins/github/src/GithubSystemProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { App } from "octokit";
import { SystemProperty } from "@gram/core/dist/data/system-property/types.js";
import System from "@gram/core/dist/data/systems/System.js";
Expand All @@ -11,7 +10,7 @@ import {
import { RequestContext } from "@gram/core/dist/data/providers/RequestContext.js";
import { SystemProvider } from "@gram/core/dist/data/systems/SystemProvider.js";

const log = getLogger("GithubSystemProvider");
const log = log4js.getLogger("GithubSystemProvider");

export class GithubSystemProvider implements SystemProvider {
constructor(private app: App) {}
Expand Down
5 changes: 2 additions & 3 deletions plugins/github/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createDb, migrate } from "postgres-migrations";
import { createPostgresPool } from "@gram/core/dist/data/postgres.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { config } from "@gram/core/src/config/index.js";

export async function getDatabaseName() {
Expand All @@ -11,7 +10,7 @@ export async function getDatabaseName() {
}

export async function additionalMigrations() {
const log = getLogger("gh-migrate");
const log = log4js.getLogger("gh-migrate");

const databaseName = await getDatabaseName();
const host = (await config.postgres.host.getValue()) as string;
Expand Down
5 changes: 2 additions & 3 deletions plugins/ldap/src/LDAPBasicAuthIdentityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { RequestContext } from "@gram/core/dist/data/providers/RequestContext.js
import { InvalidInputError } from "@gram/core/dist/util/errors.js";
import basicAuth from "basic-auth";
import { initLdapClient } from "./lookup.js";
import pkg from "log4js";
const { getLogger } = pkg;
import log4js from "log4js";
import { LDAPClientSettings } from "./LDAPClientSettings.js";

const log = getLogger("LDAPAuthProvider");
const log = log4js.getLogger("LDAPAuthProvider");

/**
* This identity provider uses basic auth to authenticate users against an LDAP server.
Expand Down
Loading

0 comments on commit 449cb23

Please sign in to comment.