<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why am I unable to send the logs to Splunk  through log4j2? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592320#M10506</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244573"&gt;@se123987&lt;/a&gt;&amp;nbsp;- Please check this out.&lt;/P&gt;&lt;P&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enableloghttpjava/" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enableloghttpjava/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;----------&lt;BR /&gt;Please consider upvote if this helps you!!!&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2022 06:37:11 GMT</pubDate>
    <dc:creator>VatsalJagani</dc:creator>
    <dc:date>2022-04-05T06:37:11Z</dc:date>
    <item>
      <title>Why am I unable to send the logs to Splunk  through log4j2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592237#M10505</link>
      <description>&lt;P&gt;I'm trying to send my logs from java to splunk through log4j2 . I'm doing log4j2 configuration programatically.&lt;/P&gt;
&lt;P&gt;I know this is not the correct way to do so. But I'm still doing this for learning purpose.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After execution of my java code I see the console appender logs in console but not the splunk appender logs in splunk. I don't know what I'm missing here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried with postman with same url and token. In this case it works well.&lt;/P&gt;
&lt;P&gt;code of my POM file is here ==&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;dependencies&amp;gt;
		&amp;lt;!-- https://mvnrepository.com/artifact/com.splunk/splunk-sdk-java --&amp;gt;
		&amp;lt;dependency&amp;gt;
			&amp;lt;groupId&amp;gt;com.splunk.logging&amp;lt;/groupId&amp;gt;
			&amp;lt;artifactId&amp;gt;splunk-library-javalogging&amp;lt;/artifactId&amp;gt;
			&amp;lt;version&amp;gt;1.11.4&amp;lt;/version&amp;gt;
		&amp;lt;/dependency&amp;gt;
		&amp;lt;dependency&amp;gt;
			&amp;lt;groupId&amp;gt;org.apache.logging.log4j&amp;lt;/groupId&amp;gt;
			&amp;lt;artifactId&amp;gt;log4j-core&amp;lt;/artifactId&amp;gt;
			&amp;lt;version&amp;gt;2.11.2&amp;lt;/version&amp;gt;
		&amp;lt;/dependency&amp;gt;


		&amp;lt;dependency&amp;gt;
			&amp;lt;groupId&amp;gt;org.apache.logging.log4j&amp;lt;/groupId&amp;gt;
			&amp;lt;artifactId&amp;gt;log4j-api&amp;lt;/artifactId&amp;gt;
			&amp;lt;version&amp;gt;2.11.2&amp;lt;/version&amp;gt;
		&amp;lt;/dependency&amp;gt;
		&amp;lt;dependency&amp;gt;
			&amp;lt;groupId&amp;gt;com.splunk&amp;lt;/groupId&amp;gt;
			&amp;lt;artifactId&amp;gt;splunk&amp;lt;/artifactId&amp;gt;
			&amp;lt;version&amp;gt;1.6.5.0&amp;lt;/version&amp;gt;
		&amp;lt;/dependency&amp;gt;

	&amp;lt;/dependencies&amp;gt;

	&amp;lt;repositories&amp;gt;
		&amp;lt;repository&amp;gt;
			&amp;lt;id&amp;gt;splunk-artifactory&amp;lt;/id&amp;gt;
			&amp;lt;name&amp;gt;Splunk Releases&amp;lt;/name&amp;gt;
			&amp;lt;url&amp;gt;https://splunk.jfrog.io/splunk/ext-releases-local&amp;lt;/url&amp;gt;
		&amp;lt;/repository&amp;gt;
	&amp;lt;/repositories&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my java code is here =&amp;gt;&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;import java.util.*;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.layout.PatternLayout;
import com.splunk.logging.*;
import java.io.*;

public class Main {
	private static final Logger log;

	static {
	  configureLog4J();
	  
	  log = LogManager.getLogger(Main.class);
	}
	public static void configureLog4J() {
		  ConfigurationBuilder&amp;lt;BuiltConfiguration&amp;gt; builder =
				  ConfigurationBuilderFactory.newConfigurationBuilder();

		  // configure a splunk appender
		  builder.add(	  
		      builder.newAppender("splunk", "SplunkHttp")
		          .add(
		              builder.newLayout(PatternLayout.class.getSimpleName())
		                  .addAttribute(
		                      "pattern",
		                      "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"
		                  )
		          )
		          .addAttribute("sourcetype", "log4j")
		          .addAttribute("index", "main")
		          .addAttribute("url", "http://localhost:8088/services/collector")
		          .addAttribute("token", "XXX")
		          .addAttribute("host", "java")
		          
		          
		          
		          
		  );
		  
		//configure console appender
		  builder.add(
		  builder.newAppender("console", "Console")
          .add(
              builder.newLayout(PatternLayout.class.getSimpleName())
                  .addAttribute(
                      "pattern",
                      "%logger{36}-%msg%n"
                  )
          ));

		  // configure the root logger
		  builder.add(
		      builder.newRootLogger(Level.INFO)
		          .add(builder.newAppenderRef("splunk"))
		          .add(builder.newAppenderRef(("console")))
		  );

		  // apply the configuration
		  Configurator.initialize(builder.build());

		}
	
	public static void main(String ar[]) {
		System.out.println("START");
		log.info("ok");
		log.log(Level.INFO, "BY from log4j2");
		
		log.log(Level.ERROR, "BY Error from log4j2");
		System.out.println("END");
	}
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 16:11:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592237#M10505</guid>
      <dc:creator>se123987</dc:creator>
      <dc:date>2022-04-04T16:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to send the logs to Splunk  through log4j2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592320#M10506</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244573"&gt;@se123987&lt;/a&gt;&amp;nbsp;- Please check this out.&lt;/P&gt;&lt;P&gt;&lt;A href="https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enableloghttpjava/" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/devtools/java/logging-java/howtouseloggingjava/enableloghttpjava/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;----------&lt;BR /&gt;Please consider upvote if this helps you!!!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 06:37:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592320#M10506</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2022-04-05T06:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to send the logs to Splunk  through log4j2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592381#M10507</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/93915"&gt;@VatsalJagani&lt;/a&gt;&amp;nbsp;I cannot relate this with my problem. If u know which I miss please tell the exact solution.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 10:21:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592381#M10507</guid>
      <dc:creator>se123987</dc:creator>
      <dc:date>2022-04-05T10:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I unable to send the logs to Splunk  through log4j2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592389#M10508</link>
      <description>&lt;P&gt;The obvious approach in such case is to:&lt;/P&gt;&lt;P&gt;1) Trace your program and see what methods are called and what they return.&lt;/P&gt;&lt;P&gt;2) I never used log4j2 but I supposed that due to what it does it would probably catch and silently "drop" many of its own internal exceptions. Check if you can enable internal log4j2 debugging.&lt;/P&gt;&lt;P&gt;3) Verify network traffic to check whether your program is indeed connecting to your indexer and tries to send something or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 10:36:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-unable-to-send-the-logs-to-Splunk-through-log4j2/m-p/592389#M10508</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-04-05T10:36:55Z</dc:date>
    </item>
  </channel>
</rss>

