Skip to content

Commit

Permalink
feat(backend): optimize logging by making it less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 1, 2024
1 parent b454e83 commit 60b6cd3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
6 changes: 2 additions & 4 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LoggerModule } from "nestjs-pino";
import { AuthModule } from "./auth/auth.module";
import { BuilderModule } from "./builder/builder.module";
import appConfig from "./config/app.config";
import { IS_PROD } from "./constants";
import { dataSourceOptions } from "./data.source";
import { MetricsModule } from "./metrics/metrics.module";
import { MiscModule } from "./misc/misc.module";
Expand All @@ -22,9 +21,8 @@ import { TelegramModule } from "./telegram/telegram.module";
BuilderModule,
ConfigModule.forRoot({ envFilePath: ".env", isGlobal: true, load: [appConfig] }),
LoggerModule.forRoot({
pinoHttp: {
level: IS_PROD ? "info" : "debug",
},
// By default, off, but can be enabled by setting HTTP_LOGGING=true
forRoutes: process.env.HTTP_LOGGING === "true" ? undefined : [],
}),
MetricsModule,
MiscModule,
Expand Down
3 changes: 1 addition & 2 deletions backend/src/builder/moleculer.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type IORedis from "ioredis";
import type { BrokerOptions, LoggerConfig, ServiceSchema } from "moleculer";
import { IS_PROD } from "../constants";

export const MoleculerConfigCommon: Partial<BrokerOptions> = {
skipProcessEventRegistration: true,
Expand All @@ -10,7 +9,7 @@ export function MoleculerConfigLog(): LoggerConfig {
return {
type: "Pino",
options: {
level: IS_PROD ? "info" : "debug",
level: "error",
},
};
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/config/repo-manager.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { registerAs } from "@nestjs/config";

export default registerAs("repoMan", () => ({
gitlabToken: process.env.GITLAB_TOKEN,
alwaysRebuild: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "{}",
gitAuthor: process.env.GIT_AUTHOR ?? "Chaotic Temeraire",
gitEmail: process.env.GIT_EMAIL ?? "[email protected]",
gitUsername: process.env.GIT_USERNAME ?? "git",
gitlabToken: process.env.CAUR_GITLAB_TOKEN,
schedulerInterval: process.env.REPOMANAGER_SCHEDULE ?? "0 * * * *",
alwaysRebuild: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "{}",
}));
3 changes: 2 additions & 1 deletion backend/src/data.source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Build, Builder, Repo } from "./builder/builder.entity";
import { IS_PROD } from "./constants";
import { Mirror, RouterHit } from "./router/router.entity";
import { User } from "./users/users.entity";
import { ArchlinuxPackage, RepoManagerSettings } from "./repo-manager/repo-manager.entity";

export const dataSourceOptions: DataSourceOptions = {
type: "postgres",
Expand All @@ -12,7 +13,7 @@ export const dataSourceOptions: DataSourceOptions = {
password: process.env.PG_PASSWORD || "chaotic",
database: process.env.PG_DATABASE || "chaotic",
synchronize: !IS_PROD,
entities: [Builder, Build, Repo, RouterHit, Mirror, User],
entities: [Builder, Build, Repo, RouterHit, Mirror, User, ArchlinuxPackage, RepoManagerSettings],
migrations: [],
cache: true,
extra: {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || "development";
declare const module: any;

async function bootstrap(): Promise<void> {
const fastifyAdapter = new FastifyAdapter({ logger: true });
const fastifyAdapter = new FastifyAdapter();
const app: INestApplication = await NestFactory.create<NestFastifyApplication>(AppModule, fastifyAdapter, {
bufferLogs: true,
});
Expand Down Expand Up @@ -51,5 +51,5 @@ async function bootstrap(): Promise<void> {
}

bootstrap().then(() => {
Logger.log("🚀 Application has started up", "Bootstrap");
Logger.log("🚀 Application has started up.", "Bootstrap");
});
3 changes: 2 additions & 1 deletion backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class RepoManagerService {
}

class RepoManager {
status: RepoStatus = RepoStatus.INACTIVE;
status: RepoStatus
private readonly cloneDir: string = path.join(process.cwd(), "repos");
private readonly httpService: HttpService;
private readonly archlinuxRepos: string[] = ["core", "extra"];
Expand Down Expand Up @@ -159,6 +159,7 @@ class RepoManager {
this.httpService = httpService;
this.dbConnections = dbConnections;
this.repoManagerSettings = settings;
this.status = RepoStatus.INACTIVE;
Logger.log("RepoManager initialized", "RepoManager");
}

Expand Down

0 comments on commit 60b6cd3

Please sign in to comment.