append line of code and datetime in microlog - android

currently I use like below in microlog.properties file.
microlog.formatter.PatternFormatter.pattern=[%d]:[%P] %c - %m %T
and getting the result is Microlog 38623:[INFO]-this is my class.
I want to get 1) the datetime as 29-10-2012 : 21:55:40 and 2) append the line of the class to the log file.
How can I set to the properties file to set both ?

The default time specifier for %d is absolute time. Try to specify how you like to format the time, e.g. %d{ISO8601}
Microlog4Android is inspired from Log4j, as such is has support for many of its features. The formatter in Microlog4Android includes many of the patterns found in PatternLayout.

Related

Converting Numbers to Local (UTF8) Bengali numbers

I am trying to convert the English numbers (1, 2, 3) to Bengali numbers (১, ২, ৩).
For example, if I get 10000, then I want to show like ১০,০০০.
I can replace the number one by one with the Bengali counterpart using replaceAll method
But I want to know if there is an alternative solution to do that instead of the above.
Use this:
val convertedString = String.format(Locale.forLanguageTag("bn"), "%d", 1234567890)
I have used NumberFormat from popular library Intl and converted it easily like below
NumberFormat("##,##,##,###", "bn").format(10000)
And the output is:
১০,০০০

How to open jetpack DataStore file (.preferences_pb)

I am trying out new jetpack DataStore library . I saved data using the library . This created a file settings.preferences_pb in app data directory (/data/data/my.package.name/files/datastore/settings.preferences_pb) . setting is the file name given by me . The data doesn't show properly with a text viewer . I can make out Key name but the value is garbage . How do I open this file and view it ?
Here is the drive link for file settings.preferences_pb
Reference: https://medium.com/swlh/get-your-hand-dirty-with-jetpack-datastore-b1f1dfb0a5c1
The protobuf files will be located in /data/data/{application.package}/files/datastore/ . These are the protobuf formatted files, so we can not read them with an ordinary editor. To decode the files, we can use protoc command line.
To be able to use protoc command, we have to pull these files to our
workstation’s space using adb command
For preference datastore
protoc --decode_raw < app_name.preferences_pb
The result will be similar to this:
1 {
1: "app_name"
2 {
5: "Datastore sample"
}
}
1 {
1: "is_demo_mode"
2 {
1: 1
}
}
Note: value 1 of is_demo_mode represents a true
Here is the current format for the preferences_pb file: link
You can parse the file using this schema and print it out if you need to.
Alternatively, you can just use the toString() method on the Preferences object and you should get a nice readable output.
I used an Hex Editor ("Hex Fiend" for macOS) and it seems understandable.
You may refer to the preferences.proto here (thanks #rohit-sathyanarayana)
The binary file is a map of <string, value> pair.
Each pair starts with 0x0A and length (in bytes). For example 0x26 means next 38 bytes.
Name field starts with 0x0A and length (in bytes). For example 0x04 for "name" and 0x05 for "token".
Value field starts with 0x12 and length (in bytes). For example 0x1E = next 30 bytes.
First byte might indicates field type. For example 0x2A = String field.
Second byte is length of value. For example 0x1C = 28 bytes.
Since 0x0A is same as line feed, you can open the preferences_db as text if most of your fields are in String format.
I find a workaround from the datastore source code. Just change the pbFile to File(filesDir, "datastore/settings.preferences_pb")

How to set string resource length limit in Android?

It is known that Androd string resources support xliff namespace to annotate non-translatable string formatting placeholders, like this
<string name="max_file_size_exceeded_template">File
<xliff:g example="some_image.jpg" id="file_name">%1$s</xliff:g>
is too big and could not be uploaded.</string>
It helps translators to undestand what parts of string should not be modified. But sometimes I need to annotate some strings max length it they are used in UI control with limited size. What I want is add text length limit to warn translators about this. Something like max-length="24" max-lines="2" length-unit="char" Maybe, xliff supports such thing or it can be achieved in other way.
I use Weblate for translations if it matters.
You can set this in Weblate, the Andoid format does not support this directly.
Click on edit (pencil) icon next to flags on the string.
Enter max-length:LENGTH as check flag.
See also https://docs.weblate.org/en/latest/admin/translating.html#additional-information-on-source-strings

Regular Expression failed when I try to get all files that name only contains number

I try to list all the files under "/proc" on my android device,and get all those files' names only contain numbers,such as '123','435'.I try to filter those by regular expression.I tried three expressions below but all of these failed sometimes:
^[0-9]+$
[0-9]+
\d+
I wonder how can the three expressions can match such as "14971" but can't match "15003"?
I think boober Bunz is right, that the file extension is the difference.
All three of your expressions match both
"14971"
and
"15003"
the best way is to pull the extensions off the fileNames, and then use the most restrictive expression you need to: ^[0-9]+$
or if you want to just leave the extension on, this would most likely work for you:
"^[0-9]+[.][^.]*$"
start of string, one or more digits, must have a . and then any number of non . end of string. this would not match:
"123.123.txt"

How to parse an XML date with Zulu time in Android?

How can I parse a standard XML date in Android that is formatted according to the ISO standard? Example:
2012-12-13T12:34:56.678Z
Note how the time zone is given as "Z" (Zulu time).
SimpleDateFormat does not recognize the Z, and when I try to use the XML packages, I get an exception that they are not included.
DatatypeConfigurationException: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not found
Am I missing something? I'm assuming it should be pretty simple and straightforward to parse and format an ISO date.
In JavaScript, we would write:
var isoDateString = new Date().toISOString(); //2012-12-13T12:34:56.678Z
var isoDate = new Date(isoDateString);
See Android reference:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
One could also always use java regular expression parsing to grab the components of the DTG, but that is not recommended if the Android API provides this functionality.

Categories

Resources