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

Keep native DateTime, Date and Time struct encoding #125

Merged
merged 4 commits into from
Jul 30, 2024

Conversation

imricardoramos
Copy link
Contributor

Right now dates and times are encoded with the struct encoder which makes the logs be very verbose about dates (I'm using Grafana Loki to view logs and it makes it hard to parse visually):

%{level: :info, msg: {:string, "some message"}, meta: %{
  datetime: DateTime.utc_now(), 
  date: Date.utc_today(), 
  time: Time.utc_now
}}
|> LoggerJSON.Formatters.Basic.format(metadata: [:datetime, :date, :time]) 
|> IO.chardata_to_string()
|> Jason.decode! 
|> Jason.encode!(pretty: true) 
|> IO.puts 
{                                                                                                                                                           
  "message": "some message",                                                                                                                 
  "metadata": {                                                                                                                              
    "date": {                                                                                                                                
      "calendar": "Elixir.Calendar.ISO",                                                                                                     
      "day": 29,                                                                                                                             
      "month": 7,                                                                                                                            
      "year": 2024                                                                                                                           
    },                                                                                                                                       
    "datetime": {                                                                                                                            
      "calendar": "Elixir.Calendar.ISO",                                                                                                     
      "day": 29,                                                                                                                             
      "hour": 16,                                                                                                                            
      "microsecond": [                                                                                                                       
        744919,                                                                                                                              
        6                                                                                                                                    
      ],                                                                                                                                     
      "minute": 45,                                                                                                                          
      "month": 7,     
      "second": 0,           
      "std_offset": 0,
      "time_zone": "Etc/UTC",
      "utc_offset": 0,                 
      "year": 2024,                    
      "zone_abbr": "UTC"               
    },                                 
    "time": {                          
      "calendar": "Elixir.Calendar.ISO",                                      
      "hour": 16,                      
      "microsecond": [                 
        744951,                        
        6                              
      ],                               
      "minute": 45,                    
      "second": 0                      
    }                                  
  },                                   
  "severity": "info",                  
  "time": "2024-07-29T16:45:00.744Z"                                          
} 

I propose to keep those as-is and let them be encoded by their native Jason encoding. They don't present any sensitive data and therefore they don't need to be checked for redacted fields.

{                                                                                                                                                           
  "message": "some message",                                                                                                                                
  "metadata": {                                                                                                                                             
    "date": "2024-07-29",                                                                                                                                   
    "datetime": "2024-07-29T16:44:50.502282Z",                                                                                                              
    "time": "16:44:50.502331"                                                                                                                               
  },                                                                                                                                                        
  "severity": "info",                                                                                                                                       
  "time": "2024-07-29T16:44:50.502Z"                                                                                                                        
} 

Copy link
Member

@AndrewDryga AndrewDryga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@coveralls
Copy link

coveralls commented Jul 30, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling ba2e014 on imricardoramos:fix-date-time-encoding
into 222e612 on Nebo15:master.

@AndrewDryga
Copy link
Member

@imricardoramos
Copy link
Contributor Author

Done

@AndrewDryga AndrewDryga merged commit cad5979 into Nebo15:master Jul 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants