DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Adding a Gas Station Map to a React and Go/Gin/Gorm Application
  • How To Check for JSON Insecure Deserialization (JID) Attacks With Java
  • Migration of Microservice Applications From WebLogic to Openshift
  • Aggregating REST APIs Calls Using Apache Camel

Trending

  • Mastering Advanced Aggregations in Spark SQL
  • Integration Isn’t a Task — It’s an Architectural Discipline
  • Metrics at a Glance for Production Clusters
  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Step-By-Step Guide To Enable JSON Logging on OpenShift

Step-By-Step Guide To Enable JSON Logging on OpenShift

JSON log parsing is important for the application to create a custom index in Elasticsearch. Learn here how to enable JSON logging on Red Hat OpenShift 4.

By 
shailendra singh user avatar
shailendra singh
·
Nov. 09, 21 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
5.0K Views

Join the DZone community and get the full member experience.

Join For Free

OpenShift Logging’s API enables you to parse JSON logs into a structured object and forward them to either OpenShift Logging-managed Elasticsearch or any other third-party system.

Prerequisites

You will need to install the following technologies before beginning this exercise:

  • Red Hat OpenShift Container Platform 4.9

  • Sample application printing the logs in JSON format

Deploy Sample Application

Deploy the sample application in the demo namespace. Below is the log for the application:

{"Thread":"Camel (MyCamel) thread #1 - timer://foo", "Level":"INFO ", "Logger":"simple-route" , "Message":">>> 957"}

Normally, the ClusterLogForwarder custom resource (CR) forwards that log entry in the message field. The message field contains the JSON-quoted string equivalent of the JSON log entry, as shown in the following example.

{"message":"{\"Thread\":\"Camel (MyCamel) thread #1 - timer://foo\", \"Level\":\"INFO \",\ "Logger\":\"simple-route\" ,\ "Message\":\">>> 957\"}”

After enabling JSON parse, the JSON-structured log entry is in a structured field, as shown in the following example. This does not modify the original message field.

{"structured":{"Thread":"Camel (MyCamel) thread #1 - timer://foo", "Level":"INFO ", "Logger":"simple-route" , "Message":">>> 957"

Verify the Logs in Kibana

Verify the logs in Kibana

The application logs are represented in the message field.

Enable JSON Logging

Enable the JSON parse using the  ClusterLogForwarder. Below is the sample CR which enables JSON for applications deployed in demo namesapce. 

YAML
 
apiVersion: logging.openshift.io/v1
kind: ClusterLogForwarder
metadata:
 name: instance
 namespace: openshift-logging
spec:
 inputs:
 - application:
     namespaces:
     - demo
   name: input-demo
 outputDefaults:
   elasticsearch:
     structuredTypeKey: kubernetes.namespace_name
     structuredTypeName: demo-index-name
 pipelines:
 - inputRefs:
   - input-demo
   name: pipeline-a
   outputRefs:
   - default
   parse: json
 - inputRefs:
   - infrastructure
   - application
   - audit
   outputRefs:
   - default

Refer to the document to know about the parameter and other options. 

Verify the Logs in Kibana

After enabling the JSON parse, the fluend create the separate index for demo application and parse the logs to additional structured fields.

#Application Log

{"Thread":"Camel (MyCamel) thread #1 - timer://foo", "Level":"INFO ", "Logger":"simple-route" , "Message":">>> 221"}

#Kibana

Additional structured fields are created based on the logs.

 
t structured.Level                         INFO
t structured.Logger                        simple-route
t structured.Message                       >>> 221
t structured.Thread                        Camel (MyCamel) thread #1 - timer://foo

Structured fields

Conclusion

Thanks for reading! I hope this article helps you get started with the JSON logging on OpenShift.

JSON OpenShift application

Opinions expressed by DZone contributors are their own.

Related

  • Adding a Gas Station Map to a React and Go/Gin/Gorm Application
  • How To Check for JSON Insecure Deserialization (JID) Attacks With Java
  • Migration of Microservice Applications From WebLogic to Openshift
  • Aggregating REST APIs Calls Using Apache Camel

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!