I tried integrating my SpringBoot Application with Splunk, but could not get the logs. There is no Error in Console. Kindly help
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="%style{%d{ISO8601}} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{10}}{bright,yellow}: %msg%n%throwable" />
</Console>
<SplunkHttp
name="student-service-token"
url="https://prd-p-wyalk.splunkcloud.com:8080"
token="*********************************"
host="localhost"
index="student_idex_api"
type="raw"
source="http-event-logs"
sourcetype="log4j"
messageFormat="text"
disableCertificateValidation="true">
<PatternLayout pattern="%m" />
</SplunkHttp>
</Appenders>
<Loggers>
<!-- LOG everything at INFO level -->
<Root level="info">
<AppenderRef ref="console" />
<AppenderRef ref="splunkhttp" />
</Root>
</Loggers>
</Configuration>
Related
I have this controller class and log4j2 .
But I am not able to receive email in myemail#gmail.com.
What I am doing wrong? I am using latest version of spring boot.
// Logger statement in controller class
LOGGER.info(" send email : " + EMAIL);
LOGGER.error(" send email : " + EMAIL);
LOGGER.warn(" send email : " + EMAIL);
This is my log4j2.xml file under resources folder
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="omnichannel">
<Properties>
<Property name="LOG_CONSOLE">
%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{%5p} ${hostName} --- [%15.15t] %-40.40c{1.} : %m%n%ex
</Property>
</Properties>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_CONSOLE}"/>
</Console>
<SMTP name="SMTPAppender"
from="myemail#gmail.com"
to="myemail#gmail.com"
subject="hi"
smtpHost="smtp.gmail.com"
smtpPort="587"
smtpProtocol="smtp"
smtpUsername="myemail#gmail.com"
smtpPassword="mypassword"
bufferSize="1"
smtpDebug="false">
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<HTMLLayout charset="UTF-8" title="Error Logs" contentType="text/html"/>
</SMTP>
<Async name="AsyncSMTP" bufferSize="1">
<AppenderRef ref="SMTPAppender"/>
</Async>
</Appenders>
<Loggers>
<Logger name="com.satish.central.docs.person.web.controller" level="debug" additivity="false">
<AppenderRef ref="ConsoleAppender" />
<!--<AppenderRef ref="AsyncSMTP" />-->
</Logger>
<Root level="info">
<AppenderRef ref="ConsoleAppender" />
<!--<AppenderRef ref="AsyncSMTP" />-->
</Root>
</Loggers>
</Configuration>
Your example shows 3 log events with a comment that they are generated in the controller class. Your logging configuration shows that the Logger associated with the Controller is being routed to the ConsoleAppender. Your example above has nothing routed to the SmtpAppender.
I want to do graylog integration in java by using "gelf" library. I added config parameters in order to connect graylog server into "log4j_Appender.xml"
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" packages="org.graylog2.log4j2">
<Appenders>
<GELF name="gelfAppender" server="graylog.llm.com" port="12212" hostname="llmtest.llm.com" protocol="UDP" includeThreadContext="true">
<KeyValuePair key="grayloggroup" value="LLMFIGHTTEST" />
<KeyValuePair key="application" value="baggagebustest" />
<KeyValuePair key="environment" value="baggagebustest" />
<!-- <Filters> -->
<!-- <Filter type="MakerFilter" marker="FLOW" onMatch="DENY" onMismatch="NEUTRAL"></Filter> -->
<!-- <Filter type="MakerFilter" marker="EXCEPTION" onMatch="DENY" onMismatch="ACCEPT"></Filter> -->
<!-- </Filters> -->
<PatternLayout pattern="%m%n"/>
</GELF>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="gelfAppender" />
</Root>
</Loggers>
</Configuration>
But I can not connect to "graylog.llm.com" and I don't add a log into "LLMFIGHTTEST" stream.
I am using this project in github.
We should use add appender into log4j.xml file and add dependency log4j2-gelf as maven dependency.
Dependency,
<dependency> <groupId>org.graylog2.log4j2</groupId> <artifactId>log4j2-gelf</artifactId> <version>1.3.2-SNAPSHOT</version> </dependency>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" packages="org.graylog2.log4j2">
<Appenders>
<GELF name="gelfAppender" server="graylog.test.com" port="12212" hostname="test.th.com" protocol="UDP" includeThreadContext="true">
<KeyValuePair key="ORDERID" value="$${ctx:ORDERID}"/>
<Filters>
<Filter type="MakerFilter" marker="PARENT" onMatch="DENY" onMismatch="NEUTRAL"></Filter>
<Filter type="MakerFilter" marker="TEST" onMatch="DENY" onMismatch="ACCEPT"></Filter>
</Filters>
<PatternLayout pattern="ORDERID : $${ctx:ORDERID} %msg%n" />
</GELF>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [%thread] [%c{1.}] - %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="gelfAppender" />
<AppenderRef ref="STDOUT" />
<AppenderRef ref="Error-Appender" level="error"/>
</Root>
</Loggers>
</Configuration>
Created the custom filter by extending AbstractFilter.
Created log4j2.xml as per below code
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30"
packages="com.smp.marker">
<Properties>
<Property name="DEFAULT_LOG_PATTERN">%d %-5p %m%n [:%L]</Property>
</Properties>
<Appenders>
<Console name="CLOG" target="SYSTEM_OUT">
<PatternLayout alwaysWriteExceptions="false" pattern="%d %-5p
[%c{5}.%M():%L] %m%n" />
<Filters>
<SmpClogAppenderFilter level="ALL" onMatch="ACCEPT"
onMismatch="DENY"/>
</Filters>
</Console>
<Console name="DEFAULT" target="SYSTEM_OUT">
<PatternLayout alwaysWriteExceptions="false"
pattern="${DEFAULT_LOG_PATTERN}" />
<Filters>
<SmpClogAppenderFilter level="ALL" onMatch="DENY"
onMismatch="ACCEPT"/>
</Filters>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="CLOG" />
<AppenderRef ref="DEFAULT" />
</Root>
</Loggers>
</Configuration>
This is working as expetced.
But in our project we need log4j2.properties.
Unable to create the property file with custom filter.Mainly need propety value for filter section.
<Filters>
<SmpClogAppenderFilter level="ALL" onMatch="ACCEPT"
onMismatch="DENY"/>
Could some one please help me to resolve this issue.
The automatic reload was working up until I added a second file to the log4j.configurationFile property. I now get this error when updating the log4j2.xml file, or rather I get the same error message twice...
2017-10-02 12:06:44,461 Log4j2-TF-2-ConfiguratonFileWatcher-2 ERROR No logging configuration
2017-10-02 12:06:44,462 Log4j2-TF-2-ConfiguratonFileWatcher-2 ERROR No logging configuration
Here's the problematic property...
-Dlog4j.configurationFile=log4j2.xml,c:\tmp\override-log4j2.xml
Note, this only affects reload. Initially, the composite configuration works fine.
This is a maven project, ran in eclipse using jetty:run and log4j2 2.9.0.
Is this a bug? Is there a workaround?
Here's the log4j2.xml...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration monitorInterval="5">
<appenders>
<console name="console" target="SYSTEM_OUT">
<patternLayout pattern="%d %5p [%t] [%X{users}] (%F:%L) - %m%n" />
</console>
<rollingFile name="rollingFile" fileName="myApp.log" filePattern="myApp.log">
<patternLayout pattern="%d %5p [%t] [%X{users}] (%F:%L) - %m%n" />
<policies>
<SizeBasedTriggeringPolicy size="10mb" />
</policies>
<defaultRolloverStrategy max="10" />
</rollingFile>
</appenders>
<loggers>
<root level="warn">
<appenderRef ref="console" />
<appenderRef ref="rollingFile" />
</root>
<logger name="com.mycompany" level="info" />
</loggers>
</configuration>
Here's override-log4j2.xml...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<loggers>
<root level="warn" />
</loggers>
</configuration>
Thanks for the update #gaurav.
Apparently, (I've not tested) the ticket was resolved in 2.10.0.
I'm trying to achive the following using log4j2:
Log all general content to console, but log MarkerFilter.FILTERED only to a specific file, not to console.
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<RollingFile name="FILTERED" fileName="filtered.txt" />
<MarkerFilter marker="FILTERED" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="CONSOLE" />
<AppenderRef ref="FILTERED" />
</Root>
</Loggers>
</Configuration>
The following works in general, BUT logs any FILTERED content to console additionally.
But when I remove the <AppenderRef ref="FILTERED" /> form <root> loggers, nothing is logged to the file anymore!
How about using the marker filter on the console appender with a DENY action?
You can set the level on the appender-ref, so you don't need to use a ThresholdFilter for that.
<Configuration status="warn">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<MarkerFilter marker="FILTERED" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<RollingFile name="FILTERED" fileName="filtered.txt" />
<MarkerFilter marker="FILTERED" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="CONSOLE" level="info" />
<AppenderRef ref="FILTERED" />
</Root>
</Loggers>
</Configuration>