Utilizing the docker-compose JSON logging driver with custom environment labels

My goal is to retrieve logs in the following format:

{"log":"Using CATALINA_BASE:   /opt/apache-tomcat-7.0.76\r\n","stream":"stdout","time":"2017-04-19T04:28:33.608418994Z","attrs":{"production_status":"testing","os":"ubuntu"}}

I have set up my docker-compose.yml as shown below:

version: '2.1'
services:
  web:
    image: hello-world/web:latest
    container_name: api
    ports:
      - "80:8080"
logging:
  driver: "json-file"
  options:
    max-size: 10m
    max-file: "3"
    labels: testing
    env: ubuntu

However, I am unable to see the "attrs" key in the logs. Can someone please advise on what I might be doing wrong?

Answer №1

During my experimentation, I discovered that there are two components required to display the labels/environment variables in the logs.

  1. Specify which labels/environment variables should be shown in the logs
  2. Assign those labels/environment variables to the container

To achieve your desired outcome, you must update the docker-compose.yml file with the following configuration:

version: '2.1'
services:
  web:
    image: hello-world/web:latest
    container_name: api
    ports:
      - "80:8080"
    logging:
      driver: "json-file"
      options:
        max-size: 10m
        max-file: "3"
        labels: "production_status"
        env: "os"
    labels:
      production_status: "testing"
    environment:
      - os=ubuntu

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to break down nested arrays into multiple arrays in Swift 4?

Using JSON parsing in my news API development brought about significant improvements. Here's how the JSON data structure is organized: > { "status": "ok", "source": "associated-press", "sortBy": "top", -"articles": [ -{ "author": "CHRISTINA A. CA ...

"Utilizing PHP MySQL queries to generate an array and encode it into JSON format for

Below is the code snippet that I am having trouble with: $objDbResultByModel = $objDatabase->Query($modelQuery); $return_arr = array(); echo "<h3>Total Model No<br></h3><strong>"; while ($mixRow = $objDbResultByModel->FetchAr ...

sending a JSON object from the controller to a JSP page

I need to transfer all the data from my database in the form of a JSON array to a JSP page so that it can be retrieved using AJAX. EmployeeController public class EmployeeController { @Autowired private EmployeeService employeeService; @RequestMapping( ...

Is it possible to accept a number in string format in the request body?

I have a specific API spec that outlines the parameter account_id as being a string within the request body. If a request is received with a value for this field either as a number or even a boolean, such as: "account_id": 1234567890 or "account_id": t ...

Steps to retrieve JSON data from a webpage

Exploring the realm of handling JSON data from a web API is new to me. I'm eager to delve into its intricacies and understand how it operates. Despite my online research, I am still unclear about the process. As far as I know, the general procedure i ...

Building a JSON tree model in a Spring application using a list

I'm struggling with JSON. I have a user_id from the client-side and need to check the groups associated with this user_id. After retrieving data from the database, I place it into a list. I have included this annotation in my xml file: <mvc:anno ...

Error encountered while parsing data in Internet Explorer versions 7, 8, 9, and 10 due to an invalid character. The status

This block of code is functioning correctly on Chrome and Firefox, however it seems to be having issues with Internet Explorer! It involves a simple JSON file call, fetching data, and then displaying it on an HTML webpage. Here's the code snippet: $. ...

Unable to retrieve JSON data from a PHP file hosted on the server

I have a server-side database with a table called "customers" and a column named "names". My goal is to send a request to the server asking for the first two records in the "customers" table. However, when I execute the program, the browser does not displa ...

Accessing an item within a JSON object using jQuery

Trying to access an element within a JSON object, part of the code is shown below: { " academy": { "business": { "E-commerce": [ I have successfully accessed the academy as the first element using the following code: $.getJSON("p ...

Java: Combine values of the same type into a single JSON object

Let's say I have 3 different dates like this: try { DateDetails GetDateDetailsResp = GET.getDateDetails; Date date1 = GetDateDetailsResp.dateDetails.date1; Date date2 = GetDateDetailsResp.dateDetails.date2; Date date3 = GetDateDetai ...

Javascript: A guide on passing an object through multiple nested functions

Hey fellow developers, I'm facing a challenge in my code and seeking advice from the experts out there. I'm attempting to retrieve JSON data from a specific URL, as shown below, and utilize it in a React component outside of the getWeather() fun ...

Utilize ScriptControl for JSON parsing in VBA: convert output into dictionaries and collections

Looking to utilize Microsoft ScriptControl in VBA for parsing a JSON string and converting the resulting Object into Dictionary and Collection objects. While I have the parsing aspect down with ScriptControl, I'm struggling with how to translate the r ...

A basic structure for a JSON array

Perhaps my next question may appear silly, but I'll ask it anyway :) Here is the structure in question: { "name": "Erjet Malaj", "first_name": "Erjet", "work": [ { "employer": { "id": "110108059015688 ...

Exploring Angular 2's ngFor Directive with JSON Data

Recently diving into Angular2, I've been trying to extract data from a JSON file. While I have successfully retrieved the file using a REST client, stored it in a local variable within a component, and accessed certain properties of that variable, I&a ...

Achieving JSON element sorting in the most effective way

https://i.stack.imgur.com/NQbdN.png Each array contains the following information: {{ id: 39, treaty_number: "qwe", insurant_name: "222", belonging_to_the_holding_company: "test", date_start: "2016-04-15", etc }} Is there a way to sort each array in asc ...

Is the issue with AJAX and a global variable a result of my misunderstanding?

My goal is to use AJAX to load client data onto a page and then replace a company ID with the corresponding name from a different company table in the same database. However, I am facing an issue where the global JavaScript variable is not being updated wi ...

Using Node.js, I am utilizing a Javascript API to perform a POST request, reading data

Utilizing JavaScript, we perform an API POST request using an external JSON file. The setup involves two main files: order.json and app.js Server information: Ubuntu 22.04 Node v19.2.0 npm 8.19.3 The script retrieves data from the order.js file using the ...

Issues with parsing JSON data within PowerShell

While working with JSON, I encountered a specific issue that I need help with. The JSON snippet provided below illustrates the problem: Although I have experimented with various examples of JSON manipulation, most of them focus on simple key/value pairs. ...

Discovering the key within a complicated JSON file using C# and the Newtonsoft library

{ "items": [ { "_id": { "$oid": "5968dd23fc13ae04d9000001" }, "item_name": "sildenafil citrate", "supplier": "Wisozk Inc", "quantity": 261, "unit_cost": "$1 ...

Could there be a glitch within the handling of json data types in mysql 5.7?

Working on a laravel project that utilizes mysql, I recently updated my ubuntu system. However, ever since the update, I have been encountering an error when trying to fetch data from the mysql database using the json_extract() method in the where clause. ...