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

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

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • The Impact of Asynchronous Work on Engineering Innovation
  • Oracle: Migrate PDB to Another Database
  • Remote Control With Node.js, React.js, and Raspberry Pi
  • How To Protect RDP From Ransomware Attacks

Trending

  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • A Modern Stack for Building Scalable Systems
  • Streamlining Event Data in Event-Driven Ansible
  • GDPR Compliance With .NET: Securing Data the Right Way
  1. DZone
  2. Coding
  3. Java
  4. Direct Logs to Remote System With Log4j

Direct Logs to Remote System With Log4j

If an application is running on a remote system, you need the logs on your local machine. Learn how to do direct logs to whichever machine you desire.

By 
Merghoob Khan user avatar
Merghoob Khan
·
May. 10, 17 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
24.2K Views

Join the DZone community and get the full member experience.

Join For Free

Logging is one of the most important aspects of developing programs. Logs provide us with information about the behavior of programs, whether the behavior is expected or not.

Log4j is a very popular package for logging purpose written in Java. (Note: This article assumes that you are familiar with Log4j and already using Log4j.)

Sometimes, we need the logs on different machines. Let's consider that the application is running on a remote system and we need the logs on our local machine.

Hence, the following question arises.

How Can I Direct Logs to a Desirable Machine?

There are some simple steps to do this:

Change the log4j.properties files on the sender side. Use SocketAppender to direct logs to another machine. See the following log4j.properties files:

log4j.rootLogger=DEBUG, server
log4j.appender.server=org.apache.log4j.net.SocketAppender
log4j.appender.server.Port=4712
log4j.appender.server.RemoteHost=loghost
log4j.appender.server.ReconnectionDelay=10000

Modify the log4j-reciever.properties files on the reciever side. See the following file:

log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n

Run the following command on the reciever side:

java -classpath log4j-path.jar org.apache.log4j.net.SimpleSocketServer 4712 log4j-reciever.properties

After this setup, run your program/application, and you will get logs at your desirable machine.

Log4j remote

Opinions expressed by DZone contributors are their own.

Related

  • The Impact of Asynchronous Work on Engineering Innovation
  • Oracle: Migrate PDB to Another Database
  • Remote Control With Node.js, React.js, and Raspberry Pi
  • How To Protect RDP From Ransomware Attacks

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!