How to delete lines in xml using logstash - logstash

everybody.
I am new to logstash. I've been studying filters in logstash for a week, but no result.
I want to parse xml. I have the following xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<ContinentLogs>
<Cryptogateways>
<cgw id="1" cssid="0" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">ЦУС</cgw>
<cgw id="2" cssid="50556" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">DP.152FZ.DA01</cgw>
<cgw id="3" cssid="50557" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">M1.152FZ.DA01</cgw>
<cgw id="4" cssid="51358" ip="0.0.0.0" tz="RCPTZ 00:00 RCPTZS 00:00,M0.0.0/00:00:00,M0.0.0/00:00:00">3D Get</cgw>
<cgw id="5" cssid="51491" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">М1.152FZ.CUS02</cgw>
<cgw id="6" cssid="51845" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">DP.152FZ.FW01</cgw>
<cgw id="7" cssid="51847" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">M1.152FZ.FW01</cgw>
<cgw id="8" cssid="53840" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">M1.152FZ.FW02</cgw>
<cgw id="9" cssid="68604" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">TNC MIG</cgw>
<cgw id="10" cssid="69007" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">HAKR</cgw>
<cgw id="11" cssid="111846" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">ALT MOT</cgw>
<cgw id="12" cssid="111978" ip="0.0.0.0" tz="RCPTZ -3:00 RCPTZS -4:00,M0.0.0/00:00:00,M0.0.0/00:00:00">GPB RIM</cgw>
</Cryptogateways>
<FilterRules>
<rule id="-8" deleted="false">Pravil</rule>
<rule id="-5" deleted="false">(?) Neopredelen</rule>
<rule id="-3" deleted="false">Udalenni pravila</rule>
<rule id="-2" deleted="false">SD prav</rule>
<rule id="-1" deleted="false">Slygeb prav</rule>
<rule id="0" deleted="false">Ne sootvetsvyet</rule>
<rule id="17" deleted="false">Mon => Mail Server</rule>
</FilterRules>
</ContinentLogs>
I want to remove lines that have «cgw id="3"» и «cgw id="7"» in the section.
And remove the lines that have «rule id="-5"» и «rule id="0"» in the section.
Write everything back to xml without changing anything else.
Help how to do this through Logstash?
Thank you in advance.

if your logstash is feeding the ELK, then your solution should be in Prune blacklist
first, add the item you want in the xpath
for example
let my Xml file be like
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.foo.Bar" level="trace">
<AppenderRef ref="Console" />
</Logger>
<Logger name="com.foo.Bar.test.2.error" level="error">
<AppenderRef ref="Console" />
</Logger>
<Root level="error">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
and now in the configuration file use the filter as the following.
filter {
xml {
source => "message"
store_xml => false
target => "rec"
xpath => [
"/Configuration /#status", "Configuration_LEVEL" // defining my item to delete
]
}
prune {
blacklist_names => ["Configuration_LEVEL"] // delete the item using prune blacklist
}
}
I hope it helped you.

Related

"The remote name could not be resolved" when running an Azure DevOps self-hosted build agent in Service Fabric

I can successfully start a self-hosted agent on my Windows 10 machine following this article:
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#windows
However when I try to start the very same Docker image in Service Fabric with Windows Server 20H2 nodes, I get these container log entries:
1. Determining matching Azure Pipelines agent...
Invoke-RestMethod : The remote name could not be resolved: 'dev.azure.com'
At C:\azp\start.ps1:34 char:12
+ $package = Invoke-RestMethod -Headers #{Authorization=("Basic $base64 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeRestMethodCommand
Dockerfile
FROM mcr.microsoft.com/windows/servercore:20H2
WORKDIR /azp
COPY start.ps1 .
CMD powershell .\start.ps1
ApplicationManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="build-agent-20H2" ApplicationTypeVersion="20201228.5"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Package" ServiceManifestVersion="20201228.5" />
<EnvironmentOverrides CodePackageRef="buildagent.Code">
<EnvironmentVariable Name="AZP_URL" Value="https://dev.azure.com/myaccount" />
<EnvironmentVariable Name="AZP_TOKEN" Value="mypat" />
<EnvironmentVariable Name="AZP_AGENT_NAME" Value="myagentname" />
<EnvironmentVariable Name="AZP_POOL" Value="mypoolname" />
</EnvironmentOverrides>
<Policies>
<ServicePackageResourceGovernancePolicy CpuCores="1"/>
<ResourceGovernancePolicy CodePackageRef="buildagent.Code" MemoryInMB="1024" />
<ContainerHostPolicies CodePackageRef="buildagent.Code" UseTokenAuthenticationCredentials="true">
<HealthConfig IncludeDockerHealthStatusInSystemHealthReport="true" RestartContainerOnUnhealthyDockerHealthStatus="false" TreatContainerUnhealthyStatusAsError="false" />
</ContainerHostPolicies>
</Policies>
</ServiceManifestImport>
<DefaultServices>
<Service Name="buildagent">
<StatelessService ServiceTypeName="buildagentType" InstanceCount="1">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
ServiceManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Package" Version="20201228.5"
xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="buildagentType" UseImplicitHost="true">
</StatelessServiceType>
</ServiceTypes>
<CodePackage Name="buildagent.Code" Version="20201228.5">
<EntryPoint>
<ContainerHost>
<ImageName>myacr.azurecr.io/build-agent-20h2:20201228.5</ImageName>
<Commands>
</Commands>
</ContainerHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="AZP_URL" Value="" />
<EnvironmentVariable Name="AZP_TOKEN" Value="" />
<EnvironmentVariable Name="AZP_AGENT_NAME" Value="" />
<EnvironmentVariable Name="AZP_POOL" Value="" />
</EnvironmentVariables>
</CodePackage>
</ServiceManifest>
I also tried without these specs:
ServicePackageResourceGovernancePolicy
ResourceGovernancePolicy
HealthConfig
and I wonder whether I can bring up a container in Service Fabric without having a HTTP or TCP endpoint.
EDIT:
another observation: When I SSH/remote onto one of the nodes where I deployed the image to and docker run -it the image directly, the remote name can be resolved and the installation procedure works (?). So it seams SF starts the container differently.
EDIT 2:
Tried with a simplified start.ps1
Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.2.402/dotnet-sdk-2.2.402-win-x64.zip
Read-Host
brings same error. Comparing docker inspect on SF controlled container and directly started container I see a deviation which maybe relevant:
SF (not working)
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
...
"Networks": {
"nat": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "b52a59a54d97f56f8fc866c0f742588023333ff1cb10b2c536be21d6745d609d",
"EndpointID": "bc20ebb2124467f5135aefeefd7e3d38c14338479f7a5dbd04fd274dd0fa3ddf",
"Gateway": "192.168.80.1",
"IPAddress": "192.168.81.196",
"IPPrefixLen": 24,
direct (working)
"Dns": [
"10.1.0.211"
],
"DnsOptions": [
"ndots:1"
],
"DnsSearch": [
"build-agent-20H2"
],
...
"Networks": {
"nat": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "b52a59a54d97f56f8fc866c0f742588023333ff1cb10b2c536be21d6745d609d",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
When deploying the same image with compose deployment network resolution was working fine and build agent installed & started successfully.
Comparing manifests I added endpoints and it was working:
ApplicationManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest ApplicationTypeName="build-agent-20H2" ApplicationTypeVersion="20201228.5"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceManifestImport>
<ServiceManifestRef ServiceManifestName="Package" ServiceManifestVersion="20201228.5" />
<EnvironmentOverrides CodePackageRef="buildagent.Code">
<EnvironmentVariable Name="AZP_URL" Value="https://dev.azure.com/myaccount" />
<EnvironmentVariable Name="AZP_TOKEN" Value="mypat" />
<EnvironmentVariable Name="AZP_AGENT_NAME" Value="myagentname" />
<EnvironmentVariable Name="AZP_POOL" Value="mypoolname" />
</EnvironmentOverrides>
<Policies>
<ServicePackageResourceGovernancePolicy CpuCores="1"/>
<ResourceGovernancePolicy CodePackageRef="buildagent.Code" MemoryInMB="1024" />
<ContainerHostPolicies CodePackageRef="buildagent.Code" UseTokenAuthenticationCredentials="true">
<PortBinding ContainerPort="80" EndpointRef="agentEndpoint" />
<PortBinding ContainerPort="443" EndpointRef="agentEndpoint1" />
</ContainerHostPolicies>
</Policies>
</ServiceManifestImport>
<DefaultServices>
<Service Name="buildagent">
<StatelessService ServiceTypeName="buildagentType" InstanceCount="1">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
</ApplicationManifest>
ServiceManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Package" Version="20201228.5"
xmlns="http://schemas.microsoft.com/2011/01/fabric">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="buildagentType" UseImplicitHost="true">
</StatelessServiceType>
</ServiceTypes>
<CodePackage Name="buildagent.Code" Version="20201228.5">
<EntryPoint>
<ContainerHost>
<ImageName>myacr.azurecr.io/build-agent-20h2:20201228.5</ImageName>
<Commands>
</Commands>
</ContainerHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="AZP_URL" Value="" />
<EnvironmentVariable Name="AZP_TOKEN" Value="" />
<EnvironmentVariable Name="AZP_AGENT_NAME" Value="" />
<EnvironmentVariable Name="AZP_POOL" Value="" />
</EnvironmentVariables>
</CodePackage>
<Resources>
<Endpoints>
<Endpoint Name="agentEndpoint" UriScheme="http" />
<Endpoint Name="agentEndpoint1" UriScheme="https" />
</Endpoints>
</Resources>
</ServiceManifest>

dotnet core nlog running on Linux logs only one entry

I am running an aspnet core site on Linux using Kestrel. I have set up nlog to log to csv files. All is well in my Windows development environment, but when I run it on Linux I only get one entry in the log file. I turned on nlog tracing and found the following error in the output:
2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/own-log.20160908.csv' already exists.
at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/all-log.20160907.csv' already exists.
at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
at System.IO.File.Move(String sourceFileName, String destFileName)
at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
This is my nlog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<!--enable NLog.Web for ASP.NET Core-->
<add assembly="NLog.Web.AspNetCore"/>
</extensions>
<targets>
<!-- https://github.com/nlog/nlog/wiki/File-target -->
<!-- http://stackoverflow.com/questions/34679727/use-nlog-in-asp-net-5-application -->
<target name="allfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target name="allfile" xsi:type="File"
fileName="${basedir}/logs/all-logfile.csv"
archiveFileName="${basedir}/logs/archives/all-log.{#}.csv"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="28"
concurrentWrites="true"
keepFileOpen="false"
encoding="utf-8">
<layout xsi:type="CSVLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}" />
<column name="authtype" layout="${aspnet-user-authtype}" />
<column name="identity" layout="${aspnet-user-identity}" />
<column name="level" layout="${uppercase:${level}}" />
<column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
</layout>
</target>
</target>
<target name="ownfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target name="ownfile" xsi:type="File"
fileName="${basedir}/logs/own-logfile.csv"
archiveFileName="${basedir}/logs/archives/own-log.{#}.csv"
archiveEvery="Day"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="28"
concurrentWrites="true"
keepFileOpen="false"
encoding="utf-8">
<layout xsi:type="CSVLayout">
<column name="time" layout="${longdate}" />
<column name="logger" layout="${logger}" />
<column name="authtype" layout="${aspnet-user-authtype}" />
<column name="identity" layout="${aspnet-user-identity}" />
<column name="level" layout="${uppercase:${level}}" />
<column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
</layout>
</target>
</target>
<target xsi:type="Null" name="blackhole" />
</targets>
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Debug" writeTo="allfile" />
<!--Skip Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
<logger name="*" minlevel="Debug" writeTo="ownFile" />
</rules>
</nlog>
I have concurrent writes true and keepFileOpen false which seems necessary as kestrel forks multiple dotnet processes on Linux.
Is this a bug or is my configuration incorrect?

Check security header in Mule http:listener

I have a need to check some security HTTP header (called for example X-MyApp-Security) value before processing it after Mule http:listener. Header should be checked like basic auth header but more simply.
I found some Mule documentation about this but don't understand how to use it my simple flow:
<http:listener-config name="HTTP_Listener_Configuration" host="${httpServer.host}" port="${httpServer.port}" doc:name="HTTP Listener Configuration" />
<flow name="planadoWebhookFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP" allowedMethods="POST"/>
<set-payload value="Hello from security area!" doc:name="Set Payload"/>
</flow>
Please help me with header authentication in Mule 3.7.
You can use the "http:basic-security-filter" element, here you have an example:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:mule-xml="http://www.mulesoft.org/schema/mule/xml"
xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
xmlns:smtps="http://www.mulesoft.org/schema/mule/smtps"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:ss="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/smtps http://www.mulesoft.org/schema/mule/smtps/current/mule-smtps.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
">
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="user" password="password" authorities="ROLE_ADMIN" />
<ss:user name="anon" password="anon" authorities="ROLE_ANON" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="9091" doc:name="HTTP Listener Configuration"/>
<flow name="testingFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/*" doc:name="HTTP"/>
<logger message="Before Authentication" level="INFO" doc:name="Log Failure"/>
<http:basic-security-filter realm="mule-realm"/>
<logger message="After Authentication" level="INFO" doc:name="Log Failure"/>
</flow>
</mule>
You can find more information in the next link:
https://docs.mulesoft.com/mule-user-guide/v/3.7/http-listener-connector#authentication

Mule Log4j2 not working

I have a log4j2 XML file in my src/main/resources as below. But Still I do not see the log file created. Any idea what could I be missing.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="file" fileName="C:\\Users\\Guest\\Desktop\\Mule.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>
</PatternLayout>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="file" level="DEBUG"/>
<AppenderRef ref="STDOUT" level="INFO"/>
</Root>
</Loggers>
</Configuration>
Log4j2 configuration works only in Mule-3.6 version+, check your Mule version and give file name to C:/Users/Guest/Desktop/Mule.log format.
Sample file:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Properties>
<Property name="log-path">${env:MULE_HOME}/logs/test</Property>
<Property name="log-name">test</Property>
</Properties>
<Appenders>
<Console name="console-log" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<RollingFile name="info-log" fileName="${log-path}/${log-name}-info.log"
filePattern="${log-path}/${log-name}-info-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="debug-log" fileName="${log-path}/${log-name}-debug.log"
filePattern="${log-path}/${log-name}-debug-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="trace-log" fileName="${log-path}/${log-name}-trace.log"
filePattern="${log-path}/${log-name}-trace-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="error-log" fileName="${log-path}/${log-name}-error.log"
filePattern="${log-path}/${log-name}-error-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<!-- CXF is used heavily by Mule for web services -->
<AsyncLogger name="org.apache.cxf" level="WARN"/>
<!-- Apache Commons tend to make a lot of noise which can clutter the log-->
<AsyncLogger name="org.apache" level="WARN"/>
<!-- Reduce startup noise -->
<AsyncLogger name="org.springframework.beans.factory" level="WARN"/>
<!-- Mule classes -->
<AsyncLogger name="org.mule" level="INFO"/>
<AsyncLogger name="com.mulesoft" level="INFO"/>
<!-- Reduce DM verbosity -->
<AsyncLogger name="org.jetel" level="WARN"/>
<AsyncLogger name="Tracking" level="WARN"/>
<AsyncRoot level="DEBUG">
<appender-ref ref="info-log" level="info" />
<appender-ref ref="trace-log" level="trace" />
<appender-ref ref="debug-log" level="debug" />
<appender-ref ref="error-log" level="error" />
<appender-ref ref="console-log" level="debug" />
</AsyncRoot>
</Loggers>
</Configuration>
For studio, specify location of MULE_HOME in Run Configuration->Environment->new->Name->MULE_HOME and Value->c:/test
Try changing fileName to fileName="C:/Users/Guest/Desktop/Mule.log"

tomcat is logging all the tomcat related Debug logs

I have changed my tomcat logging to use logback.xml instead of util.Logger. I have changed using mentioned steps on https://github.com/grgrzybek/tomcat-slf4j-logback.
But now on starting tomcat it is logging every Debug log of tomcat.
My logback.xml looks like this:
<configuration>
<appender name="CONSOLE" class="org.apache.juli.logging.ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} %-5level {%thread} [%logger{20}] : %msg%n
</pattern>
</encoder>
</appender>
<appender name="FILE-CATALINA" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/catalina.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>
%d{HH:mm:ss.SSS} %-5level {%thread} [%logger{40}] : %msg%n
</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${catalina.base}/logs/catalina-%d{yyyyMMdd}-%i.log.zip
</fileNamePattern>
<maxHistory>
60
<!-- days -->
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-LOCALHOST" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/localhost.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>
%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n
</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${catalina.base}/logs/localhost-%d{yyyyMMdd}-%i.log.zip
</fileNamePattern>
<maxHistory>
60
<!-- days -->
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-MANAGER" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/manager.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>
%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n
</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${catalina.base}/logs/manager-%d{yyyyMMdd}-%i.log.zip
</fileNamePattern>
<maxHistory>
60
<!-- days -->
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<appender name="FILE-HOST-MANAGER" class="org.apache.juli.logging.ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/host-manager.log</file>
<append>true</append>
<encoder>
<charset>utf-8</charset>
<pattern>
%d{HH:mm:ss.SSS} %logger{0} {%thread} %level : %msg%n
</pattern>
</encoder>
<rollingPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>
${catalina.base}/logs/host-manager-%d{yyyyMMdd}-%i.log.zip
</fileNamePattern>
<maxHistory>
60
<!-- days -->
</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="org.apache.juli.logging.ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<logger name="org.apache.catalina" level="INFO" additivity="false">
<appender-ref ref="FILE-CATALINA"/>
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]" level="INFO" additivity="false">
<appender-ref ref="FILE-LOCALHOST"/>
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]" level="INFO" additivity="false">
<appender-ref ref="FILE-MANAGER"/>
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]" level="INFO" additivity="false">
<appender-ref ref="FILE-HOST-MANAGER"/>
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
Logs are like this
07:16:09.218 [main] DEBUG o.a.tomcat.util.digester.Digester - Fire end() for SetNextRule[methodName=addLifecycleListener, paramType=org.apache.catalina.LifecycleListener]
07:16:09.218 [main] DEBUG o.a.tomcat.util.digester.Digester - [SetNextRule]{Server/Listener} Call org.apache.catalina.core.StandardServer.addLifecycleListener(org.apache.catalina.core.AprLifecycleListener#277b8705)
This is line coming when I am starting tomcat :
Using CATALINA_BASE: /mnt/production/apache-tomcat
Using CATALINA_HOME: /mnt/production/apache-tomcat
Using CATALINA_TMPDIR: /mnt/production/apache-tomcat/temp
Using JRE_HOME: /opt/bitnami/java
Using CLASSPATH: /mnt/production/apache-tomcat/bin/bootstrap.jar:/mnt/production/apache-tomcat/bin/tomcat-juli.jar
So classpath looks correct to me.

Resources