0

I got this docker-compose file:

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'

I got this moleculer file config:

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}"
        }
    },
],
...

When I launch the moleculer runner with visual code or using node directly in the system, the "this.logger" object works perfectly, it does not use the console log and uses only the file log. But when I use this with docker, the process uses console log when my config file says that does wat console, and no file is write inside the docker execution.

This is my Dockfile.

The rest of the properties of the moleculer file works perfectly (and yes, the application uses that moleculer config file).

    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"]
dlopezgonzalez
  • 4,217
  • 5
  • 31
  • 42
  • To make a quick guess, the docker-compose bind mount `volumes:` `- logdata:/logs/moleculer` is overriding the container's log dir with an empty dir from the host machine. That's just how bind mounts work. Can you try commenting the `volumes:` bit out, restarting the container, then viewing the log files with `docker exec -it ls /logs/moleculer`? I suspect you'll see the logs. Relevant Q&A's: https://stackoverflow.com/q/36107442/4161471 https://stackoverflow.com/q/47664107/4161471 – aSemy Sep 01 '21 at 20:02
  • No, i dont see the logs. How i say, in "/logs/moleculer" inside the docker there are not log files (only files created for testing in the dockfile. Thus, outside of the docker, in the host os i see the files under /logs/moleculer (volumes works). – dlopezgonzalez Sep 01 '21 at 22:02

2 Answers2

1

I have been struggling with this same issue for a couple of hours, and even if this is old, I didn't find a complete enough answer. As ZhuRong have said, you have the enviroment variable LOGGER set to some value, probably true. The short answer, delete this lines in docker-compose.env

LOGGER=true
LOGLEVEL=info

The moleculer init command generates docker files by default, and among those is a file with enviroment variables docker-compose.env which is referenced in the docker-compose.yml file. In the generated env file the enviroment variable LOGGER is by default set to true. This makes moleculer containters use the docker internal logger, an deactivates any logger set by the broker in moleculer-config.js.

Keep in mind this files will be generated in the continer. As you have made, you have to configure a docker volume to keep the changes outside the services containers.

Smax
  • 11
  • 2
0

Try to check the environment variable LOGGER. If you set LOGGER to other value, for example true, it will cover the value of logger in moleculer.config.js file.

ZhuRong
  • 1
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '21 at 05:42