How to fill with space for pretty logger messages? - kotlin

Is there a way to fill with spaces after the variable $nameIdDocument so that the 2nd variable (${resultPreventRequest.documentType}) always shows up at the spot ?
I like to have logger messages aligned vertically. I would like to have PASSEPORT and RESIDENCE_PERMIT start at the same position.
Here the code I execute, and the image attached is what is printed by the logger.
LOGGERCTRLONE.info("Correctly Read document | doctype found : $nameIdDocument | ${resultPreventRequest.documentType}")
logger output
I tried the java syntax with %s-20 but it does nothing, regardless where it is positioned.
I have looked up online and there is no subject about this alignment problem in Kotlin.

The Java syntax to use with formatting would be like %-20s. The conversion type, s in this case, always goes last.
fun main() {
println("%-25s | %-22s | %s".format("Correctly Read document", "some document.xyz", "some document type"))
println("%-25s | %-22s | %s".format("Incorrectly Read document", "another document2.xyz", "another document type"))
}
Prints
Correctly Read document | some document.xyz | some document type
Incorrectly Read document | another document2.xyz | another document type
Kotlin doesn't provide any built-in logging feature. The logging library you're using might have a cleaner way to do this.

Related

How do I transform array in search or elsewhere in dashboard

I have a search that is working fine
index=event_db environment=prod release = 2020150015
| timechart count as Events
However, I'd like to modify this to search for any release in an array of releases. I'm aware of the "in" operator.
The catch is that the array of releases I've been provided ("Releases") is formatted slightly differently like so:
[ver2020.15.0015, ver2020.15.0016, ver2020.22.0019] // in general, many more than 3!
Is there a way to use the in operator and some mapping to get
release in
[2020150015, 2020150016, 2020220019] ?
Can this be put in the search?
This is part of a panel so if it's simpler I could have code elsewhere to convert [ver2020.15.0015, ver2020.15.0016, ver2020.22.0019] into [2020150015, 2020150016, 2020220019]
However, as mentioned I'm a newbie so my knowledge of where to put code to transform an array is limited :)
I have a fieldset section and a panel with a query in it.
The "Releases" array is populated in the fieldset section as so:
<input type="text" token="Releases">
<label>Release or Releases</label>
<default>*</default>
</input>
The user enters ver2020.15.0015 or perhaps ver2020.15.*.
I can't just have the user enter 2020150015 as the ver2020.15.0015 format is used elsewhere.
Perhaps there's a way to create new field Releases_Alt right after getting this?
Let me know of any other info I can provide. As I said, I'm new to Splunk so I'm still struggling with terminology.
Try this query. It uses a subsearch to build the IN argument. Subsearches in Splunk run before the main search and the output of the subsearch replaces the subsearch itself.
index=event_db environment=prod release IN (
[ | makeresults
| eval Releases=replace ($Releases|s$, "[ver\.]+","")
| return $Releases ] )
| timechart count as Events
The makeresults command is there because even subsearches have to start with a generating command. makeresults creates a "dummy" event that allows other commands to work.
The eval command does the work of converting release versions into the desired format. Note the use of |s with the Releases token. This construct ensures the contents of the token are enclosed in quotation marks, which is expected by the replace function.
Finally, the return command with $ returns the results of the eval, but without the field name itself. Without it, the subsearch would return releases="2020150015, 2020150016, 2020220019", which wouldn't work.

How can I test that an image has been sent to a user on a chat application

I've got a chat application I'm doing Gherkin for and one of the features I'll be adding is the ability to send images of various types, I just don't know how to write this up. Could it be?
Given the following users exist:
| Username |
| Alice |
| Bob |
When "Alice" sends "Bob" "Image A"
Then "Bob" can see "Image A"
Is "Image A" the url to the image? And, if it is, where does the image reside for the test itself?
This is a common programming problem where you need to store image location in a variable and pass that variable as argument. You can pass that variable name from gherkin feature file. See Here for storing file location, hope this helps:
How to pass a text file as a argument?

Selenium "StoreText" to use in other field

Please help,
I want to use the value that i stored using storeText.
My problem is, how do i use this on the other fields of the page?
Thanks in advance!
For example:
I want to get the name of this customer, and verify it on another site if its existing by entering the name on the search field on another site?
See the "Variable substitution" paragraph of the documentation, it even has a nice example of usage for storing a name from multiple fields:
Variable substitution
Variable substitution provides a simple way to include a previously
stored variable in a command parameter. This is a simple mechanism, by
which the variable to substitute is indicated by ${variableName}.
Multiple variables can be substituted, and intermixed with static
text.
Example:
store | Mr | title
storeValue | nameField | surname
store | ${title} ${surname} | fullname
type | textElement | Full name is: ${fullname}
Why don't you get the text from the webelement store it in a global static variable and call the variable in the other test case?

How to output a plaintext for each loop with Jade view engine

I'm trying to render out a plaintext string for emailing using the Jade view engine. I'm having trouble getting the right syntax for a plaintext output using a for each loop. Works fine with regular HTML, just not the plain text version:
| Bill to:
| #{customer.active_card.name}
|
- each lineitem in invoice.lines
= lineitem.description
Outputs
Bill to:
Freddy Mac
<p>Line item 1 description</p><p>Line item 2 description</p>
I can't figure out how to format the lineitem.description line so that I get a simple plaintext output so that it would look like this:
Bill to:
Freddy Mac
Line item 1 description
Line item 2 description
Any suggestions on how to tackle this ridiculously obscure edge case for Jade?
Many thanks!
Are you sure the <p> tag isn't really in the lineitem.description variable value itself? I tried your example and didn't get an unexpected <p> tag.
Second note that if you want plain text, you probably don't want jade's default HTML escaping, so use != instead of =.
For what it's worth, jade is really heavily focused on HTML specifically and using it for plain text is probably going to be annoying. Have you considered an alternate templating language like underscore templates?

Scrapy: Item discrepancy

Scenario: a page with multiple items, each consisting of title, description, image. What happens when one of the items are missing the title? How does scrapy handle it? It seems that scrapy blindly selects all titles //div[id='content']/ul/li/div[id='title']/text(),
Expected output is that that row will have a missing title. But I fear that since it blindly selects all titles on the page without considering the item context. If the 5th item is missing title, wouldn't it mistakenly use the 6th item's title instead?
title1 | description | image
.
.
title4 | description | image
title6 | description | image <--- it's supposed to be missing the title.
| description | image
Does scrapy have a way to deal with this problem?
A workaround I was thinking would be to look at the parent item element, and then, look inside that item. If something is missing don't show it.
there are variety of ways you can handle this situation
1) you can implement a pipeline that can skip items that are not required
2) you can add check in your extraction part to only yield/return an item that is required
you needs to understand Scrapy is a high level crawling Framework , that is also providing builten support for data extraction , you can use any library for extraction you would like to.