Log4j2 Property Replacement - log4j2

In Log4j2 appenders it's useful to use the contextPath as the filename, as in:
filename="/logs/${web:contextPath}.log. This means one log configuration can be reused across multiple webapps.
However If a contextPath is /foo/bar this creates the file /logs/foo/bar.log. Is there anyway to replace the / in the contextPath with _ so the filename is /logs/foo_bar.log?
For me this is more useful than replicating the context path structure directly into the logs. I 've read up on the StringSubstitution docs and can't see anyway to do it, but if anyone has a solution it would be really helpful!

I don't think there is a way to do this out of the box. But you can easily create a custom lookup that does this.
Start by subclassing WebLookup, and replace '/' characters with underscores in the returned string.
Example of creating a custom Log4j2 lookup:
see the manual page, or this question.

Related

Suffix appended to properties logged through Serilog for dotnet

We're logging to Elastic through the Serilog dotnet package and have noticed that properties that we add to the Poerperties part of the log events seem to be suffixed with _ (underscore) and then some type identifier. For example:
This causes some issues for us in the indexing process. I've been looking through the Serilog library code to try to find the source of this but without any luck. Can someone point me in the right direction as to where the suffix is added to the property names?
It looks like you're overriding the ElasticsearchSinkOptions.CustomFormatter with code to do this when constructing the sink. Using the default formatter (leaving this un-set) should not result in this style of property name.
If this doesn't cover it, please post as much as you can to show how the sink is being configured in your app.
See also:
https://github.com/serilog-contrib/serilog-sinks-elasticsearch#a-note-about-fields-inside-elasticsearch
https://github.com/serilog-contrib/serilog-sinks-elasticsearch/issues/184

Configure Eleventy not to use directories for output?

Is it possible somehow to do a general configuration for Eleventy so that 'my_file.html' in the input folder ends up just as 'my_file.html' in the _site folder, not '/my_file/index.html'?
I know I can do it on a file by file basis with permalinks. But I'd like it configured for the site as a whole, if possible.
Unfortunately, since this behavior isn't encouraged, there isn't a simple configuration option to disable the directory output.
However, since permalink is part of the data cascade, you can set a global default, and in combination with the filePathStem computed data, you can set the output to be .html files.
To set a permalink using a global data file, add a permalink.js file to your global _data directory.
// _data/permalink.js
module.exports = '/{{ page.filePathStem }}.html'
There is also a config global data option coming soon to v1.0.0. I am not sure if it will handle the {{ page.filePathStep }} preprocessing, but if it does, that could be an option too, especially since it will keep config-related things inside the config file.
Yes, you can control where Eleventy writes things out by specifying a permalink value in the front matter. This is covered here: https://www.11ty.dev/docs/permalinks/#remapping-output-(permalink)
An example would be:
---
permalink: "/my_file.html"
---

log4j2 xml Configuration tag dest attribute example

Has anyone a working example using the dest attribute to output log4j2 debug information to a file? I am trying to troubleshoot configuration problems and see the documentation shows this property can be set to err, or a url, or a file path along with setting the status to the level of output to produce, but I am not able to find a working example anywhere for this particular property.
Presently my xml for the Configuration element is as follows:
<Configuration status="DEBUG" dest="${sys:catalina.home}/logs/log4jdebug.log">
But, alas, no log4jdebug.log file is appearing along with the files my RollingFile appender create in the same path.
Thanks!
I have not found a specific example, but you can obtain equivalent functionality by putting
dest="err"
where output will appear in std.out. With a Tomcat web app, for example, output from log4j will write to catalina.out.
I was able to troubleshoot my configuration by setting status="debug" along with dest="err".

How to create and load a configuration file in dxl

I have a script which saves some files at a given location. It works fine but when I send this code to someone else, he has to change the paths in the code. It's not comfortable for someone who does not know what is in that code and for me to explain every time where and how the code should be changed.
I want to get this path in a variable which will be taken from the configuration file. So it will be easier for everyone to change just this config file and nothing in my code. But I have never done this before and could not find any information on how I can do this in the internet.
PS: I do not have any code and I ask about an ultimate solution but it is really difficult to find something good in the internet about dxl, especially since I'm new with that. Maybe someone of you already does that or has an idea how it could be done?
DXL has a perm to read the complete context of a file into a variable: string readFile (string) (or Buffer readFile (string))
you can split the output by \n and then use regular expressions to find all lines that match the pattern
^\s*([^;#].*)\s*=\s*(.*)\s*$
(i.e. key = value - where comment lines start with ; or #)
But in DOORS I prefer using DOORS modules as configuration modules. Object Heading can be the key, Object Text can be the value.
Hardcode the full name of the configuration module into your DXL file and the user can modify the behaviour of the application.
The advantage over a file is that you need not make assumptions on where the config file is to be stored on the file system.
It really depends on your situation. You are going to need to be a little more specific about what you mean by "they need to change the paths in the code". What are these paths to? Are they DOORS module paths, are they paths to local/network files, or are the something else entirely?
Like user3329561 said, you COULD use a DOORS module as a configuration file. I wouldn't recommend it though, simply because that is not what DOORS modules were designed for. DOORS is fully capable of reading system files in one line at a time as well as all at once, but I can't recommend that option either until I know what types of paths you want to load and why.
I suspect that there is a better solution for your problem that will present itself once more information is provided.
I had the same problem, I needed to specify the path of my configuration file used in my dxl script.
I solved this issue passing the directory path as a parameter to DOORS.exe as follow:
"...\DOORS\9.3\bin\doors.exe" -dxl "string myVar = \"Hello Word\"
then in my dxl script, the variable myVar is a global variable.

Determining Path of MultipartFile in Groovy

My Grails app is successfully uploading then parsing a MultipartFile with the following code:
def file = request.getFile('rawReport')
def report = new XmlSlurper().parse(file.inputStream)
My Problem: I need the path of the original file ('rawReport'), can see path information in the Debugger's "Expression" View, but can't find a method that will return the file's path as I need it.
I've found loads of "methods of the sort I'd like to have" here but they're all for simple Files, not MultipartFiles. I felt a surge of hope when I found "getStorageDescription" for MultipartFiles here but that hope was dashed when it returned "in memory" (literally... what good is that?!)
It's frustrating because I can see pieces of what I could use in the debugger... STS Expression View: Name:file -> repository -> path "\\home$\Happiness\Awaits\You\Here..."
Any help would be most appreciated.
In general it's not available as described in the Javadoc for the getOriginalFilename() method: http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/multipart/commons/CommonsMultipartFile.html#getOriginalFilename%28%29
I'm guessing that this is a security issue. I found that it behaved for me as described for Firefox and Chrome, and even Opera didn't include the full path. So even if you can get the information locally you wouldn't be able to trust that the full path would be available in general.
You might look for a Flash-based uploader which wouldn't be constrained by browser restrictions.

Resources