I am working on some logging in log4j2, as one of the arguments I pass in pojo. I would like to intercept this and create a custom string from the pojo. The pojo is a collection of keyValue pairs. I have implemented this in logback using ClassicConverter. I have debugged but it doesn't look like I have access to the argArray
LOGGER.info("custom data in log {}", eventFields);
Is this doable in log4j2 converter or maybe I need to use a diff type of plugin.
Any thoughts?
You have a few options:
Wrap your collection in a MapMessage and log the message. If using the PatternLayout you can then use %K to select what you want.
Same as item one but implement a custom PatternConverter to format the Map.
Extend MapMessage and override one of the formatting methods.
Implement a custom pattern converter that can handle the Message types your application is using (see http://logging.apache.org/log4j/2.x/manual/messages.html).
From your description it sounds like you are trying to write a custom PatternConverter. I suspect the problem you are having is that the object you are looking for is attached to the Message object in the log event, not in the log event itself. You should be able to get access to it via the Message.getParameters() method.
Related
As per documentation, I am creating a new custom field type in atlassian-plugin.xml using the SDK CLI. Now I want to use that new custom field type and create a custom field in another module when the plugin is enabled. However, that module is throwing null pointer exceptions, because the new type is not yet available. The class implementing the type is not annotated as a component - it only gets scanned by spring. It appears the class is instantiated by Jira some time after the plugin has been enabled. How do I know when it is safe to use the new type?
You can go with "/rest/api/2/field" POST option for creating custom fields.
Please refer the URL :
https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/field-createCustomField
I'm using Serilog currently and I would like to be able to pass a class to the logger and have it log in a custom format before it outputs to a textfile. Somewhat similar to IFormatProvider. I have also found ITextFormatter but I am not sure if that would be the right thing to implement. Would I want a custom sink?
For primitive types, Serilog supports IFormatProvider directly.
Most user-defined reference types however won't be passed directly to the sink by Serilog. This is because sinks often operate asynchronously, and Serilog can't assume that arbitrary user-defined types are thread-safe.
You can circumvent this, in order to use an IFormatProvider, by capturing values of the type as "scalars":
.Destructure.AsScalar<SomeClass>()
Or, alternatively, you can "destructure" the class into whatever secondary representation you want at the time of logging:
.Destructure.ByTransforming<SomeClass>(sc => Display(sc))
For this (ByTransforming()) to work, you need to opt-in with # when the object is logged:
Log.Information("Hello {#Something}", new SomeClass());
Simplest of all, you could also just override ToString() in the class itself.
I'm trying to bind a XML response from a WS to a set of POJO's classes using ksoap2-android.
A lot of examples on the internet treat very simple responses like this one.
In my case however, I have a lot of custom classes and they keep a reference of each other, sometimes even inside an arraylist.
Here's what i'm trying to do, i would like to bind this kind of response :
<Car number="35">
<Engine>
[...]
</Engine>
<Passenger id="1">
[...]
</Passenger>
<Passenger id="2">
[...]
</Passenger>
</Car>
To this kind of class :
public class Car {
private int number;
private Engine engine;
private ArrayList<Passenger> passengers;
}
With, if possible, only modifying POJOs files (the Simple XML annotations system is very elegant, too bad there's no equivalent to this in ksoap).
I looked into the KVMSerializable interface, but when I try to override the getPropertyInfo() method, I have no idea of what I should return in the PropertyInfo.type and how will ksoap handle ArrayLists.
I got a huge headache right now, please help me
Please go to the below URL and read it.
http://www.c-sharpcorner.com/UploadFile/88b6e5/how-to-call-web-service-in-android-using-soap/
Thanks
Ashok Parmar
Traction Software Co.
You should read the document from ksoap 2, they have many useful examples in there.
For getting an array of complex type, you can check here
And I have used this approach to parse a complex object.
If all of them not work, you have to map field by field from soap object to your pojo.
Updated:
Thanks a lot for the 3rd link, it's very useful and I'm now able to
map custom objects. However, in the wiki page you provided, the author
is parsing an array of custom classes, wrapped in a parent element. Is
there a way to do this with inline lists like in my example ?
I have never tried it before, but I think you can combine my answer and the wiki.
First, you can try an example from wiki to implement your passengers list (extends Vector). Then you can use my approach to create a complex object with arraylist inside. The important thing is you must register your object with the response from web service. Something like this:
public class PassengerVector extends Vector<Passenger> implements KvmSerializable {
}
envelope.addMapping(NAMESPACE, "Car", Car.class);
envelope.addMapping(NAMESPACE, "Passenger", PassengerVector.class);
But I'm not sure this way can work. For a very complex object like your example, I recommend you should get data field by field by its name, as like the wiki
I'm writing a Groovy script (as part of a Grails plugin) and I want to get a list of properties for a GrailsDomainClass that a user of my plugin might define. I can do this using domainClass.properties (where domainClass is a GrailsDomainClass).
However, suppose a user has the grails domain class:
class Example {
String name
static constraints = {
}
def getSomeNonExistingProperty(){
return "Not-a-real-property"
}
}
In this case, domainClass.properties returns a list with both name and someNoneExistingProperty
I understand that this is because of Grails is generating a read-only property on-the-fly for use where someone has a getBlah() method. That's great, but in my script I want to perform some actions with the "real" properties only (or at least non read-only properties).
That is, I would like some way of distinguishing or identifying someNonExistingProperty as a read-only property, or, alternatively, as a property generated by Grails and not entered explicitly as a field in the domainClass by the user of my plugin.
I've looked at the GrailsDomainClassProperty Class and it has a range of methods providing information about the property. However, none of them appear to tell me whether a property is read-only or not, or to allow me to distinguish between a field defined in the domainClass and a field created on-the-fly by Grails as a result of a "getSomeNonExistingProperty()" method.
Am I missing something obvious here? Is there a way of getting a list of just the explicitly user-defined fields (eg name, in the above example)?
I believe transient properties are what you are trying to exclude
I've run into this problem a few times, and instead of trying to work around it I typically just end up renaming my getX() method. It's probably the easiest option.
Edit:
Alternatively, I wonder if you could use reflection to see which methods are defined on the class, and while iterating over your properties see if the property has an explicit getter defined, and omit it. I'm not very familiar with reflection when it comes to Groovy and Grails, especially with the dynamic methods, but it's a possible route of investigation.
I've created a new custom JSON codec for OpenRasta which works fine.
I need to pass arguments to the codec's write method when the handler is executed but cannot find any documentation on how to do it.
I notice in the implemented WriteTo method, there is a string[] codecParameters parameter, however no idea how to pass them in.
Anyone come accross this problem before? Thanks
the codec parameters are per-request. They're intended to be used together with (for example) the PathSegmentAsParameterUriDecorator.
For example, if you enable that decorator, the path /resource;segment will be treated as /resource by openrasta, and a parameter will be created with the "segment" value, and passed to the codec.
If you wish to pass information to the codec from the handler, there's nothing there, as architecturally it goes against the design of OpenRasta, which specifically prevents handlers and codecs from talking to each others.
If you wish to pass configuration data to your codec, you use the Configuration property from the ICodec interface, which will be filled with whatever object you have provided at configuration time.
You provide the configuration object either through the paramter in the .TranscodedBy(object configuration) method, or if you do custom registration using the configuration metamodel, bu adding the configuration to your Configuration property on CodecModel (which incidently is used in the ResourceModel object created by the fluent API).
Do you have a specific scenario I can help with?