From 7bb809da9c3533e516cff1df8df6b8be7b482b62 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:49:56 +0800 Subject: [PATCH] Server log (#173) * chore: update log * chore: update log * chore: redirect log --- deploy/server.ts | 29 +++++++++++++++++++---------- docker/Dockerfile.ssr | 5 +++++ docker/entrypoint-ssr.sh | 6 ++++++ docker/supervisord-ssr.conf | 6 ++++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/deploy/server.ts b/deploy/server.ts index 36485c85..0a8c2c73 100644 --- a/deploy/server.ts +++ b/deploy/server.ts @@ -20,14 +20,16 @@ const setOrUpdateMetaTag = ($: CheerioAPI, selector: string, attribute: string, } }; -const logger = pino({ - transport: { - target: 'pino-pretty', - options: { - colorize: true, - translateTime: 'SYS:standard', - }, +const prettyTransport = { + target: 'pino-pretty', + options: { + colorize: true, + translateTime: 'SYS:standard', }, +}; + +const logger = pino({ + transport: process.env.NODE_ENV === 'production' ? undefined : prettyTransport, level: process.env.LOG_LEVEL || 'info', }); @@ -35,11 +37,16 @@ const logRequestTimer = (req: Request) => { const start = Date.now(); const pathname = new URL(req.url).pathname; - logger.info(`Incoming request: ${pathname}`); + if (!pathname.startsWith('/health')) { + logger.info(`Incoming request: ${pathname}`); + } + return () => { const duration = Date.now() - start; - logger.info(`Request for ${pathname} took ${duration}ms`); + if (!pathname.startsWith('/health')) { + logger.info(`Request for ${pathname} took ${duration}ms`); + } }; }; @@ -76,7 +83,9 @@ const createServer = async (req: Request) => { const reqUrl = new URL(req.url); const hostname = req.headers.get('host'); - logger.info(`Request URL: ${hostname}${reqUrl.pathname}`); + if (!reqUrl.pathname.startsWith('/health')) { + logger.info(`Request URL: ${hostname}${reqUrl.pathname}`); + } if (reqUrl.pathname === '/') { timer(); diff --git a/docker/Dockerfile.ssr b/docker/Dockerfile.ssr index 690feea7..43ae5fdb 100644 --- a/docker/Dockerfile.ssr +++ b/docker/Dockerfile.ssr @@ -2,6 +2,7 @@ # Build stage - Build the React application FROM node:20.12.0-alpine AS builder +ARG VERSION=dev ENV NODE_ENV=production WORKDIR /app @@ -46,6 +47,10 @@ COPY docker/entrypoint-ssr.sh /docker-entrypoint.sh # Make entrypoint executable RUN chmod +x /docker-entrypoint.sh +# Set version as environment variable (from build arg) +ARG VERSION +ENV APP_VERSION=${VERSION} + # Expose port 80 EXPOSE 80 diff --git a/docker/entrypoint-ssr.sh b/docker/entrypoint-ssr.sh index 6b120784..a021e770 100644 --- a/docker/entrypoint-ssr.sh +++ b/docker/entrypoint-ssr.sh @@ -1,6 +1,12 @@ #!/bin/sh set -e +# Print version banner +echo "════════════════════════════════════════════════════════════════════" +echo " AppFlowy Web v${APP_VERSION:-dev}" +echo "════════════════════════════════════════════════════════════════════" +echo "" + # Backward compatibility: Map old environment variable names to new ones if [ -n "${AF_BASE_URL}" ] && [ -z "${APPFLOWY_BASE_URL}" ]; then echo "⚠️ WARNING: AF_BASE_URL is deprecated. Please use APPFLOWY_BASE_URL instead." diff --git a/docker/supervisord-ssr.conf b/docker/supervisord-ssr.conf index e445d944..8fade87e 100644 --- a/docker/supervisord-ssr.conf +++ b/docker/supervisord-ssr.conf @@ -19,7 +19,9 @@ priority=10 command=bun run /app/server.ts autostart=true autorestart=true -stdout_logfile=/var/log/bun.out.log -stderr_logfile=/var/log/bun.err.log +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 environment=NODE_ENV="production" priority=20 \ No newline at end of file