Skip to content

Commit

Permalink
refactor: adjust things
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackDark committed Oct 9, 2024
1 parent 94a1883 commit 041ab95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ RUN apt-get update && apt-get install -y \
WORKDIR /app
COPY package.json pnpm-lock.yaml /app/

# Do it here to add the packageManager field to the package.json
RUN corepack enable \
&& corepack prepare pnpm@9 --activate \
&& corepack use pnpm@9

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

FROM base AS builder
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY . .
RUN pnpm run build


FROM base AS dev
WORKDIR /app
ENV CONFIG_LOCATION=/app/config/config.yml
ENV SECRETS_LOCATION=/app/config/secrets.yml
CMD [ "pnpm", "start" ]

# https://github.com/evanw/esbuild/issues/1921
FROM node:20-alpine
FROM node:22-alpine
WORKDIR /app

#USER node
Expand Down
24 changes: 22 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { pino } from "pino";
import { levels, pino } from "pino";
import pretty from "pino-pretty";

export const LOG_LEVEL = process.env.LOG_LEVEL ?? `info`;

import pretty from "pino-pretty";
const maxArrayLength = Object.values(levels.labels).reduce((maxLength, currentArray) => {
return Math.max(maxLength, currentArray.length);
}, 0);

// Function to format a level string by appending spaces
const neededSpaces = (level: string): string => {
const spacesNeeded = maxArrayLength - level.length;
const spaces = " ".repeat(spacesNeeded > 0 ? spacesNeeded : 0);
return `${spaces}`;
};

const transformedLevelMap = Object.entries(levels.values).reduce((p, [key, value]) => {
p.set(key.toUpperCase(), neededSpaces(key));

return p;
}, new Map<string, string>());

const stream = pretty({
levelFirst: true,
ignore: "hostname,pid",
// @ts-ignore Temporary weird error
customPrettifiers: {
level: (level, key, log, { colors, label, labelColorized }) => `${labelColorized}${transformedLevelMap.get(label)}`,
},
});

export const logger = pino(
Expand Down

0 comments on commit 041ab95

Please sign in to comment.