0

我得到了这个 docker-compose 文件:

version: "3.3"

services:

  api:
    restart: always
    build:
      context: .
    image: foo-platform:1.0.0.0
    env_file: docker-compose-test.env
    environment:
      SERVICES: api,$node,foo-service
    labels:
      - "traefik.enable=false"
      - "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
      - "traefik.http.services.api-gw.loadbalancer.server.port=8090"
    networks:
      - internal
    volumes:
      - logdata:/logs/moleculer
    ports:
      - "5680:5680"
      - "5683:5683"
      - "5684:5684"
      - "5685:5685"
      - "5686:5686"
      

networks:
  internal:

volumes:
  logdata:
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: '/var/log/tdcp'

我得到了这个分子文件配置:

const brokerConfig: BrokerOptions = {
// Namespace of nodes to segment your nodes on the same network.
namespace: process.env.NAMESPACE,

// Unique node identifier. Must be unique in a namespace.
nodeID: null,

// Custom metadata store. Store here what you want. Accessing: `this.broker.metadata`
metadata: {},

// Enable/disable logging or use custom logger. More info: https://moleculer.services/docs/0.14/logging.html
// Available logger types: "Console", "File", "Pino", "Winston", "Bunyan", "debug", "Log4js", "Datadog"
logger: [
    //{
    //    type: "Console",
    //    options: {
    //        level: "info",
    //    }
    //},
    {             
        type: "File",
        options: {
            level: "info",
            folder: "/logs/moleculer",
            filename: "log-{date}.log",
            formatter: "{timestamp} {level} {nodeID}/{mod}: {msg}"
        }
    },
],
...

当我使用可视代码或直接在系统中使用节点启动分子运行器时,“this.logger”对象完美运行,它不使用控制台日志而仅使用文件日志。但是当我将它与 docker 一起使用时,当我的配置文件说确实是 wat 控制台时,该进程使用控制台日志,并且在 docker 执行中没有写入任何文件。

这是我的 Dockfile。

分子文件的其余属性完美运行(是的,应用程序使用该分子配置文件)。

    FROM node:lts-alpine

# Working directory
WORKDIR /app

# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci --silent

# Copy source
COPY . .

# Build and cleanup
ENV NODE_ENV=production
RUN npm run build \
 && npm prune \
 && mkdir -p /logs/moleculer \
 && touch /logs/moleculer/this_is_a_volumen

# Start server
CMD ["node", "./node_modules/moleculer/bin/moleculer-runner.js"]
4

1 回答 1

0

尝试检查环境变量LOGGER。如果将 LOGGER 设置为其他值,例如 true,它将覆盖分子 .config.js 文件中 logger 的值。

于 2021-10-25T04:37:38.567 回答