How to configure message format to syslog in WildFly - jboss

When using JBoss 5.1 with this appender:
<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Facility" value="LOCAL7"/>
<param name="FacilityPrinting" value="true"/>
<param name="SyslogHost" value="localhost"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
I see next message for log record (in EventLog Analyzer):
local7:[13:32:45,763,SendingPool] Sending pool task executed. Pool size is [0
In WildFly 8.2.1 I have next configuration for handler:
<syslog-handler name="SYSLOG">
<level name="DEBUG"/>
<server-address value="localhost"/>
<facility value="local-use-7"/>
</syslog-handler>
Message:
1 2016-07-08T13:30:34.943+03:00 - java 910 com.mycompany.component.p - Sending pool task executed. Pool size is [0
How I can change message format for syslog?

Unfortunately there isn't a way using the syslog-handler to format the message. This was an oversight when it was created and there is a long standing JIRA to fix this.
However you can use a custom-handler and use a formatter.
/subsystem=logging/pattern-formatter=syslog-formatter:add(pattern="local7: [%d{hh:mm:ss,SSS},%c{1}] %s")
/subsystem=logging/custom-handler=syslog:add(class=org.jboss.logmanager.handlers.SyslogHandler, module=org.jboss.logmanager, named-formatter=syslog-formatter, properties={hostname="localhost", facility="LOCAL_USE_7", protocol="TCP", useCountingFraming=true})
/subsystem=logging/root-logger=ROOT:add-handler(name=syslog)
Note if you want the local7: to be printed that needs to be part of the format. There is not way to prepend the facility name to the message.
Looking at:
1 2016-07-08T13:30:34.943+03:00 - java 910 com.mycompany.component.p - Sending pool task executed. Pool size is [0
That looks like the raw message minus the priority. By default the syslog handler will use the RFC 5424 format. If you want to use RFC 3164 add syslogType=RFC3163 to the properties attribute in the above custom-handler add operation and remove the useCountingFraming=true. Note the useCountingFraming=true may need to removed anyway. It depends on your syslog server setup.

Related

Add a hook to Sentry Logback to scrub data

I'm using the Logback SDK for Java to send events to Sentry as described in the documentation.
Snippet:
<conversionRule conversionWord="CUSTOM_CONVERSION_RULE"
converterClass="clazz..." />
...
<property scope="context" name="myEnc" value="%d{ISO8601,UTC} | %-5level | %-50thread | %-55logger{55} | %CUSTOM_CONVERSION_RULE" />
...
<appender name="SENTRY" class="io.sentry.logback.SentryAppender">
<dsn>...</dsn>
<encoder>${myEnc}</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
....
The initial problem was that the events sent to Sentry were not converted by my custom conversion rule. All the other appenders such as Console that use the property myEnc containing the conversion rule parse the data as expected. But it seems that the io.sentry.logback.SentryAppender in combination with the encoder somehow doesn't do that. The filter property is working as well as the dsn one, so I get the errors in Sentry but not with my custom parsing.
The version that I use for io.sentry.sentry-logback (and transitively sentry) is 1.7.24.
I then read about before-send hook from Sentry docs which is what I want to control what data is sent to Sentry and I had to upgrade to latest for that which is 3.1.3 at the time of writing this.
The Logback XML config changed a bit:
<appender name="SENTRY" class="io.sentry.logback.SentryAppender">
<options>
<dsn>...</dsn>
<beforeSend>????</beforeSend>
</options>
...
</appender>
From what I can see the before-send hook is exactly what I need to scrub the data when required because I don't want some info to be sent to Sentry. docs
Now, the second issue is that I don't know how to ref here a method. In the Java config there is a BiFunction that takes the event and can alter it. But I want to apply this hook to all my log events, that's why the only place it is configured is in the Logback SDK.
In Spring Boot for example there is a starter for Sentry and, off course, a bean that you can inject in the auto-configuration.
But, I'm using Scala with no Spring Boot.
Also, the project is already in prod so I cannot change lots of things and I'm looking for the smallest one that will allow me to add a hook to Logback's SDK for Sentry.
Here is the appender and it looks like (I'm not sure how it works) the options can be populated from XML and than pass to init that will take all them into account, including my before send hook.
I don't know if it's accepted to have two questions and only one referenced in the title but I didn't find a nicer way to ask/explain the problem, because one thing lead to another.
To summarize the questions:
Why that custom rule is not working with Logback Sentry's appender.
How can I let the appender know about my hook and use it.
Thanks in advance!
You can configure Sentry independently from appender configuration in logback.xml. For example:
public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
static {
Sentry.init(options -> {
options.setDsn("PUT YOUR DSN HERE");
options.setBeforeSend((sentryEvent, o) -> {
sentryEvent.setTag("custom", "tag");
return sentryEvent;
});
});
}
public static void main(String[] args) {
LOGGER.error("oops");
}
}
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="sentry" class="io.sentry.logback.SentryAppender" />
<root level="debug">
<appender-ref ref="console"/>
<appender-ref ref="sentry"/>
</root>
</configuration>
Check complete code sample in github repo: https://github.com/maciej-scratches/sentry-logback-custom-config

Configuring Wildfly standalone.xml in Galleon feature-pack

I'm working on a POC for a Galleon feature-pack providing the Camunda BPM subsystem.
My current progress can be found here: https://github.com/marcus-nl/camunda-galleon-pack
This article and the linked example/template have been very helpful thus far, but unfortunately I'm stuck at a point which these don't quite cover: customizing the standalone.xml configuration.
The required additions to standalone.xml are as follows: standalone.xml. So basically there are 4 additions:
The Camunda BPM extension and subsystem. This was no problem.
The H2 driver and Camunda datasource. The wildfly-datasources-galleon-pack was very helpful for this.
A job-executor configuration.
A process-engine configuration.
I can not figure out how to achieve 3 and 4. Starting with 3, the CLI command to simply add the job-executor (without a nested job-acquisitions element) is as follows:
/subsystem=camunda-bpm-platform/job-executor=job-executor:add(core-threads=3, max-threads=5, queue-length=10)
After some experimentation I came to the following feature spec (see camunda-subsystem.xml):
<feature spec="subsystem.camunda-bpm-platform">
<param name="subsystem" value="subsystem.camunda-bpm-platform"/>
<feature spec="subsystem.camunda-bpm-platform.job-executor">
<param name="job-executor" value="default"/>
<param name="core-threads" value="3"/>
<param name="max-threads" value="5"/>
<param name="queue-length" value="10"/>
</feature>
</feature>
Leading to the error message:
Failed to build configuration model standalone named standalone.xml:
Failed to resolve feature reference subsystem.camunda-bpm-platform for
{com.github.marcus-nl.camunda-galleon}subsystem.camunda-bpm-platform.job-executor:
Foreign key parameter host of
{com.github.marcus-nl.camunda-galleon}subsystem.camunda-bpm-platform.job-executor
reference subsystem.camunda-bpm-platform does not exist
I am stuck there. IIUC this has to do with the parent-child relationship between the camunda-bpm-platform element and the job-executor element. The "foreign key parameter host" seems to refer to the "host" param in the generated spec.xml for camunda-bpm-platform (this is the one for job-executor btw), but if I try to define it as follows:
<feature spec="subsystem.camunda-bpm-platform">
<param name="host" value="subsystem.camunda-bpm-platform"/>
<param name="subsystem" value="subsystem.camunda-bpm-platform"/>
I get the error "Feature spec subsystem.camunda-bpm-platform.job-executor does not define parameter host", even though (as you can see) I defined the param in the parent "camunda-bpm-platform", not the "job-executor" child.
What am I missing here? Could someone point me in the right direction?
it seems that you ran into a bug in galleon. We are investigating it. For now you can workaround the problem by generating the features for domain as done in: https://github.com/wildfly/wildfly/blob/master/galleon-pack/wildfly-feature-pack-build.xml#L89
Thank-you.

Not create new log file once start my service with using log4j2

following is my configration of log4j2:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" name="MyApp" packages="com.swimap.base.launcher.log">
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app-${date:MM-dd-yyyy-HH-mm-ss-SSS}.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="1 KB"/>
</Policies>
<DefaultRolloverStrategy max="3"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
the issue is that each time when start up my service, a new log will be created even the old one has not reached the specific size. If the program restart frequently, i will got many log files end with ‘.log’ which never be compressed.
the logs i got like this:
/log4j2/logs
/log4j2/logs/2017-07
/log4j2/logs/2017-07/app-07-18-2017-1.log.gz
/log4j2/logs/2017-07/app-07-18-2017-2.log.gz
/log4j2/logs/2017-07/app-07-18-2017-3.log.gz
/log4j2/logs/app-07-18-2017-20-42-06-173.log
/log4j2/logs/app-07-18-2017-20-42-12-284.log
/log4j2/logs/app-07-18-2017-20-42-16-797.log
/log4j2/logs/app-07-18-2017-20-42-21-269.log
someone can tell me how can i append log to the exists log file when i start up my program? much thanks whether u can help me closer to the answer!!
I suppose that your problem it that you have fileName="logs/app-${date:MM-dd-yyyy-HH-mm-ss-SSS}.log in your log4j2 configuration file.
This fileName template means that log4j2 will create log file with name that contains current date + hours + minutes + seconds + milliseconds in its name.
You should probably remove HH-mm-ss-SSS section and this will allow you to have daily rolling file and to not create new file every app restart.
You can play with template and choose format that you need.
If you want only one log file forever - then create constant fileName, like fileName=app.log
It's not hard to implement this. There is a interface DirectFileRolloverStrategy, implement below method:
public String getCurrentFileName(RollingFileManager manager)
Mybe someone met same problem and this can help him.

Configure trace for SpringServer dm 2

According to the Spring documentation,
By default, the dm Server trace file
is called
$SERVER_HOME/serviceability/logs/dm-server/log_i.log
... The index i varies from 1 to 4, on
a rolling basis, as each log file
exceeds 10Mb.
I'm aware that the default trace file name can be changed in server.config. Is it possible to change the number of log files that are kept before rolling over and/or the maximum log file size? How?
Yes. Edit config/servicability.xml and restart the server. The Virgo (donation of dm Server to Eclipse.org) documentation gives some more detail.
The elements to edit are MaxIndex and MaxFileSize as shown in the extract below:
<appender name="${applicationName}_LOG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>serviceability/logs/${applicationName}/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<FileNamePattern>serviceability/logs/${applicationName}/log_%i.log</FileNamePattern>
<MinIndex>1</MinIndex>
<MaxIndex>4</MaxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-28.28thread %-64.64logger{64} %X{medic.eventCode} %msg %ex%n</Pattern>
</encoder>
</appender>

making server.log append=true

How do I make the log server\\log\serve.log to be appended. i.e. whenver I restart JBoss it should not override the content of the log but continue from the end of it?
Add <param name="Append" value="true"/> to the <Appender> in your conf/jboss-log4j.xml file. There may be multiple appenders defined, so make sure you get the one that handles server.log.
Try setting <param name="Append" value="true"/> in your log4j.xml. This may be on a FileAppender och RollingFileAppender section. Just look for the appender that writes to server.log.
Short answer: change the log file name (e.g. myapp.log)
Longer answer: We've also seen a case where the server.log got truncated in jboss. Somewhere, someone is truncating the server.log file in some static initialization block we couldn't find. Changing the file name seems to work and the contents was appended to.
we had the same issue on our remote Ubuntu 16.04 Linuxes running Jboss EAP 6.4.0 but not when we ran our Jboss server locally in Eclipse/Windows.
The append property was already set to true.
I finally made it work by declaring the property append before the filename in the standalone-full.xml.
<properties>
<property name="append" value="true"/>
<property name="fileName" value="${jboss.server.log.dir}/server.log"/>