Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate apache access log in php image: 7.4-apache #1174

Closed
samuelrac opened this issue Jun 28, 2021 · 4 comments
Closed

How to generate apache access log in php image: 7.4-apache #1174

samuelrac opened this issue Jun 28, 2021 · 4 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@samuelrac
Copy link

Dear, I would like to clear a doubt with the community.

I am deploying a staging environment and would like to implement observability to collect application logs and would like to collect apache access logs but I noticed that the php:7.4-apache image does not generate access log when I use tail -f /var/ log/apache2/access.log has no output, I would like to know how to activate this feature in the image, could you help me?

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Jun 28, 2021
@wglambert
Copy link

# logs should go to stdout / stderr
ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"

Because docker logs are read from /dev/stderr and /dev/stdout these get redirected #863 (comment)

@samuelrac
Copy link
Author

# logs should go to stdout / stderr
ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"

Because docker logs are read from /dev/stderr and /dev/stdout these get redirected #863 (comment)

Thank you very much for the reply, in that case do I run the commands in the Dockerfile?

@yosifkit
Copy link
Member

Since it is already logging access to stdout, you can just get it with docker logs (or wherever you configure log-driver to point to).

@samuelrac
Copy link
Author

samuelrac commented Jun 29, 2021

I managed to solve the problem as follows:

docker run -v /var/log/lumen:/var/www/html/storage/logs --log-driver gelf --log-opt gelf-address=udp://:12201 -d -p "8080:80 " --name ms-products --network devnet

As I'm running an application in lumen in this container I chose to use logstash using the input file to capture error logs and gelf to capture apache's access log.

My logstash configuration file to read log files generated by lumen is:

input {
    file {
        path => "/var/log/applog/*.log"
        start_position => "beginning"
        ignore_older => 0
        codec => multiline { pattern => "\[[\d]{4}" negate => "true" what => "previous" }
    }
}

filter {
  grok {
    match => { "message" => "\[%{TIMESTAMP_ISO8601:timestamp}\] %{DATA:env}\.%{DATA:severity}: %{DATA:message}" }
  }
}

output {
  elasticsearch {
    hosts => ["http://${ELASTIC_HOST:elasticsearch}:9200"]
    index => "${ELASTIC_LOG_INDEX:logs-services}"
    user => "${ELASTIC_USER:elastic}"
    password => "${ELASTIC_PASS:changeme}"
  }
  stdout { }
}

My configuration file for apache access log listening:

input {
    gelf {
      port => 12201
    }
}

filter {
  grok {
    match => { "message" => "%{COMMONAPACHELOG} %{QS:referrer} %{QS:agent}" }
  }
}

output {
  elasticsearch {
    hosts => ["http://${ELASTIC_HOST:elasticsearch}:9200"]
    index => "${ELASTIC_LOG_INDEX:access-logs-services}"
    user => "${ELASTIC_USER:elastic}"
    password => "${ELASTIC_PASS:changeme}"
  }
  stdout { }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

3 participants