In the previous article, we modified the code to implement log persistence from the source point of view. In this article, we will implement fabric log persistence based on the X-appender project and implement log hierarchical output persistence.

Compile X-ray appender

GOOS=linux GOARCH=amd64 go build
Copy the code

Modify the mirror

Appender binary file based on fabric-peer native image, and modify CMD Dockerfile as follows:

FROM hyperledger/fabric-peer:1.4.3
ADD x-appender /usr/bin/
CMD peer node start 2>&1|x-appender
Copy the code

Using a mirror

Mirror usage and official slightly different, as follows:

  1. There is no need to overwrite the CMD of the image in the YAML file

  2. Appender added four environment variables to control the behavior of the X-appender:

    • XAPPENDER_LOG_NAME_FORMAT Format of the log file name, for example, %Y-%m-% D

    • XAPPENDER_LOG_ROOT_PATH Log persistence directory, such as /var/logs

    • XAPPENDER_LOG_MAX_AGE Maximum log retention time, expressed in days, for example, 30

    • XAPPENDER_LOG_ROTATION Log cutting time (unit: hour, for example, 24)

The sample

Peer-. yaml, I have uploaded the image to docker Hub, if you are too bothered, there is no need to make the image.

services:
  peer-00:
    image: Tianrandailoving/fabric - peer - x - appender: 1.4.3
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_byfn
      - FABRIC_LOGGING_SPEC=INFO
      #- FABRIC_LOGGING_SPEC=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
      - XAPPENDER_LOG_NAME_FORMAT=%Y-%m-%d
      - XAPPENDER_LOG_ROOT_PATH=/var/logs
      - XAPPENDER_LOG_MAX_AGE=30
      - XAPPENDER_LOG_ROTATION=24
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
Copy the code