Customize what log4j2 JSonLayout loggs - jackson

It seems as though in log4j2 when I add to my appender that what gets logged is a static set of values. How can I customize what gets logged?

More research led to the answer to my question. Setting the properties flag to true in the JsonLayout config causes each log message to contain the contents of whatever is in the context map. So to answer my question, populate the context map with MDC puts and set the properties flag to true and you get your custom content in the log message.
Also, there is a propertiesAsList flag that when set to true also prints out the contents of the context map but does does in key=, value = format.

Related

How to read System.Net.Mail.Attachment.ContentStream properties?

I'm looking for a way to read the Name property of the .NET Attachment.Content Stream I can see the property when I setup a watch, but when I try accessing I don't see the "Name" property show up. I need to get the file location with the "C:\Test123.pdf", I've found a way to get the file name...but I need its location/path.

Eclipse Editor: automatically switch context when parts get active/inactive

I am developing my own eclipse editor and need to switch between different contexts for key binding. Currently I am doing the context activation/deactivation manually upon part activation.
This page
https://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_advext_contexts.htm says:
If you are activating a more specific Context within your part (either
View or Editor) you can use the part site service locator to active
your Context. The part's IContextService will take care of activating
and deactivating the Context as your part is activated or deactivated.
It will also dispose the Context when the part is disposed.
It seems like that is just what I want. But the page did not say how. Can anyone give me a hint what a 'part site service locator' mentioned in the text is and how to use it?
I would interpret the text so that you should use the service locator of the site that corresponds to your (editor) part. In the following example, part references your editor. By obtaining the context service from the part's site, you get a child context service for that particular part in wich you can activate a specialized editor context.
IContextService contextService = part.getSite().getService( IContextService.class );
contextService.activateContext( "your.editor.context.id" );
After digging through Eclipse code, here's my answer to my own question.
First thing first, it is JUST enough to invoke
IContextService contextService = part.getSite().getService( IContextService.class );
contextService.activateContext( "your.editor.context.id" );
anywhere after init(where you get PartSite), just as #RĂ¼diger Herrmann mentioned in his answer.
AND(here's my finding) NOTHING ELSE need to be done.
Eclipse will automatically activate/deactivate the context when part is activated /deactivated, just as described in the text I refer to. In addition, when the part site is disposed, all context will be disposed.
If you are interested in how, here's more digging.
Activate/Deactivate
When we invoke getSite().getService(IContextService.class), what we get is an instance of SlaveContextService.
When we call activateContext(String contextId) on it, our request will be automatically translate to a request with a default expression ActivePartExpression.
From it's name we can easily guess that this expression will check whether a part is active and do some changes. The changes it does can be seen at ContextService.UpdateExpression.changed. Here's the code(ContextService:124-128)
if (result != EvaluationResult.FALSE) {
runExternalCode(() -> contextService.activateContext(contextId));
} else if (cached != null) {
runExternalCode(() -> contextService.deactivateContext(contextId));
}
Whenever Eclipse context changes(activate/deactivate part will trigger context change), UpdateExpression.changed will be invoked and check whether the target part is still active, then activate/deactivate the context accordingly.
Dispose
In SlaveContextService.dispose, all context registered through it will be disposed upon the service's dispose.

File attributes slow

Using vb.net I download files using sftp then immediately set their attributes to normal.
File.SetAttributes(Downloadedfile, Attr)
where Attr is a FileAttribute. I later set the attributes to readonly
File.SetAttributes(Downloadedfile, FileAttributes.ReadOnly)
The problem I am having is that there appears to be a delay between the file being downloaded and the attributes being set by the OS(Win7). As a result the .normal attribute doesn't always get set but later the readonly attribute does. Is it possible to wait until the OS has finished whatever it is doing? I've looked around and seen various articles about changing the indexing and what the folder will be used to store but none of these suggestions has worked. Don't expect somebody to come up with "You need to this" but a pointer in the right direction would be a great help.

How can I use a custom layout and still have the console application work?

I am using a custom layout in Yii. Everything works great in the web part of the app. Then I tried to run the console part of the app to run a job and it says:
exception 'CException' with message 'Property "CConsoleApplication.layout" is not defined.' in /pathToFramework/base/CComponent.php:173
If I revert to the default layout in config/main.php it works again. I can't find any documentation on how to specify the layout only for the console application. I know I can fix it but don't want to get hacky. Does anyone have a clue about the correct wat to go about this? Thanks.
Generally you don't need to specify a layout in your config, but rather do that within your controllers if you're overriding things. That's probably why your CWebApplication can handle things (you're giving it a layout property in your config), but your CConsoleApplication doesn't allow for that property to be set.
Seems like your options are:
Specify your layout property in each controller (any reason you couldn't just use the default views/layouts/main.php?)
Specify your layout property in a config file that is only used for your CWebApplication system instead of your CConsoleApplication
Override your layout property in a config file specific to your CConsoleApplication
Any of the above should work.

Checkstyle custom check access property value?

Can someone tell me or point me to some documentation regarding Checkstyle custom checks and accessing property values?
My custom class needs to obtain a regex file the users supply. Can they supply this file as a property in the Checkstyle .xml config file? If so, how does my custom Check class read the value of the property?
thanks.
I found a way around this problem. Just set a java Property using -Dpropertyname=propertyvalue, then in the custom class get the property value.