This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.spnotes.kafka; | |
import org.apache.log4j.LogManager; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* Created by sunilpatil on 11/7/16. | |
*/ | |
public class HelloKafkaLogger { | |
private static final Logger logger = LoggerFactory.getLogger(HelloKafkaLogger.class); | |
public static void main(String[] argv) { | |
logger.debug("Debug message from HelloKafkaLogger.main," ); | |
logger.info("Info message from HelloKafkaLogger.main" ); | |
logger.warn("Warn message from HelloKafkaLogger.main"); | |
logger.error("Error message from HelloKafkaLogger.main" ); | |
LogManager.shutdown(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Root logger option | |
log4j.rootLogger=DEBUG, stdout, kafka | |
log4j.logger.kafka=WARN | |
log4j.logger.org.apache.kafka=WARN | |
# Redirect log messages to console | |
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | |
log4j.appender.stdout.Target=System.out | |
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | |
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n | |
log4j.appender.kafka=org.apache.kafka.log4jappender.KafkaLog4jAppender | |
log4j.appender.kafka.brokerList=localhost:9092 | |
log4j.appender.kafka.topic=kafkalogger | |
log4j.appender.kafka.layout=org.apache.log4j.PatternLayout | |
log4j.appender.kafka.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n | |
log4j.appender.kafka.level=INFO |
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic kafkalogger
You can verify if you have topic named kafkalogger by executing following command
bin/kafka-topics.sh --list --zookeeper localhost:2181
Also you can run kafka console consumer that reads messages from Kafka and prints them to console, using following command
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkalogger
Now when you run your java program you should see messages on console like this
15 comments:
I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apache Kafka, kindly contact us http://www.maxmunus.com/contact
MaxMunus Offer World Class Virtual Instructor led training on in Apache Kafka. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us.
Nitesh Kumar
MaxMunus
E-mail: nitesh@maxmunus.com
Skype id: nitesh_maxmunus
Ph:(+91) 8553912023
http://www.maxmunus.com/
Hello Sunil,
I downloaded your project and on running it I see a warning,
No such property [level] in org.apache.kafka.log4jappender.KafkaLog4jAppender, so I just commented it out.
log4j.appender.kafka.brokerList=localhost:9092
log4j.appender.kafka.topic=kafkalogger
I changed the above two properties to point to a remote Kafka broker and I dont get any logs. I dont get any error messages either. All I see is Eclipse console showing the messages. Shouldn't I be able to see the same messages on remote Kafka topic as well? Thanks.
Dont work for me.
This is my first time I have visited here. logo designing services in Hyderabad
I found a lot of interesting stuff in your blog. keep up the impressive work.
logo designing services
logo designing in hyderabad
logo designers in hyderabad
Nice Blog
At Ideal designs, we believe that design should not just look good. It should also work well; it should be memorable and it should connect with the end-user. The success of many a business today depends on how vital a role ‘good’ design plays in their business strategy. Design is often the first thing that the consumer comes in contact with, before you can meet the company representative, you see the logo… and ‘good’ or ‘effective’ design has already started playing a vital role.Logo Design Hyderabad, Logo Design in Hyderabad, Brand Logo Design in Hyderabad, Corporate Logo Design in Hyderabad, Logo Design at Hyderabad.
Nice Blog
We are a bunch of focused individuals with strong knowledge base, collaborative insights and cutting-edge ideas. We have been working with clients across various industry sectors, helping their brands perform consistently in dynamic market scenarios. Our team of experienced advertising and design professionals embraces all methods of communication to trigger the best results for our clients. Our creative methodologies are designed to spark original ideas and new ones.
We are a bunch of focused individuals with strong knowledge base, collaborative insights and cutting-edge ideas. We have been working with clients across various industry sectors, helping their brands perform consistently in dynamic market scenarios. Our team of experienced advertising and design professionals embraces all methods of communication to trigger the best results for our clients. Our creative methodologies are designed to spark original ideas and new ones.
Nice Blog
We are a bunch of focused individuals with strong knowledge base, collaborative insights and cutting-edge ideas. We have been working with clients across various industry sectors, helping their brands perform consistently in dynamic market scenarios. Our team of experienced advertising and design professionals embraces all methods of communication to trigger the best results for our clients. Our creative methodologies are designed to spark original ideas and new ones.
visit : http://idealbranding.in/
Excellent web site you have here.. It’s hard to find good quality writing like yours these days. I truly appreciate individuals like you!
Debt Consolidation lawyer in Ontario
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Study Permit Visa for Canada
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
Notary Public Lawyer in Kitchener
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging. Body building Product Review
Nice Blog
Ideal Branding will help you Creating a unique brand identity is absolutely crucial especially if you are competing in a market that is saturated with other businesses selling the same product or service. It is increasingly vital to create brand differentiation right from the very beginning to stand-out in the market. By authentically expressing their brand identity and adopting a systematic brand-building approach, we help SMEs and start-ups build their own valuable brands for stronger sales and better business performance.
Great content it was really attractive
Construction companies often request strong, masculine logos with bold colours. Whether you’re looking for something similar or to break from the norm, we make it easy to get a design that’s right for you. Brochures are perfect for promoting and providing essential information about the business. A clean, professional, and high-impact designed brochure sets you apart from your competition and reinforces the value your company offers. Ideal Design makes brochures Design different. Unique designs and strategic objectives turn prospective leads into clients or customers.
http://idealbranding.in/
idealbranding05@gmail.com
Post a Comment