Amazon-Cloudwatch [SOLVED]: How can I get our nginx access_log to not put a : in the timezone offset?

Amazon-Cloudwatch [SOLVED]: How can I get our nginx access_log to not put a : in the timezone offset?

Home Forums Amazon Web Services Amazon Cloudwatch Amazon-Cloudwatch [SOLVED]: How can I get our nginx access_log to not put a : in the timezone offset?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #201345

    Cloudy Point
    Keymaster

    QuestionQuestion

    nginx outputs the correct ISO860 standard in this format:

    2017-09-29T15:39:06+00:00
    

    Which is GREAT except AWS CloudWatch only works when the : is not in the timezone offset. Like this:

    2017-09-29T15:39:06+0000
    

    We need to output a time format which CloudWatch can interpret. CloudWatch is “broken” since it uses the time functions in python 2.7.

    #201346

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    There is no direct way as such. But it is possible to customize logs format and change variables. So we can use that to workout this

    events {
        worker_connections  1024;
    }
    http {
    
    map $time_iso8601 $time_aws {
       ~(.*):(00)  "$1$2";
    }
    
    log_format new_format '$remote_addr - $remote_user [$time_aws] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';
    access_log /dev/stdout  new_format;
    server {
       listen 80;
       location / {
          return 200 "test";
       }
    }
    
    }
    

    This give me below access log

    172.19.0.1 - - [2017-09-29T16:43:55+0000] "GET /tarun HTTP/1.1" 200 51 "-" "curl/7.47.0"
    

    So now you just need to match the format to the way you want

    Source: https://stackoverflow.com/questions/46492505/how-can-i-get-our-nginx-access-log-to-not-put-a-in-the-timezone-offset
    Author: Tarun Lalwani
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.