Add pattern to stack driver and console to display (line number/class name/function name) in app engine second gen - spring

I'm currently building a spring boot application using gcp app engine version 2 and I would like to add a pattern to stack driver and console to display function name / line number / class name (like logs displayed in app engine first gen)
I want to change this:
(https://i.stack.imgur.com/6TfSD.png)
to something like this:
(https://i.stack.imgur.com/sxP2g.png)
logback-spring.xml:
(https://i.stack.imgur.com/E5TMn.png)
Also it is not a must you use logback, so if there is any other way to output the desired logs (and works with spring boot and app engine second gen) I can switch to it

Related

SpringBoot IntelliJ: distinguish my own logs versus framework based logs

Small question regarding SpringBoot, IntelliJ and Grep Console please.
I am going to use a very small example code:
#GetMapping("/api/employees/{id}")
Mono<Employee> one(#PathVariable String id) {
logger.info("<===== {IMPORTANT} please highlight this line!!!");
return Mono.just(DB.stream().filter(employee -> employee.id().equals(id)).findFirst().orElseThrow(() -> new RuntimeException("Couldn't find " + id)));
}
Please note the logger line is at info level. I do not want to introduce custom levels please.
When launching the application and performing queries, even at INFO level, we see many logs related to SpringBoot framework:
Like for instance:
2023-01-31T05:57:19.644+08:00 INFO [Tutorial,,] 24404 --- [ main] s.b.s.SpringBootLoggingApplication : Started SpringBootLoggingApplication in 4.104 seconds (process running for 4.812)
I paste one here, but usually, it is a lot.
And in the middle of those, there would be some real application log, some custom log developers from the project would write.
I do not want to "silence" the SpringBoot logs, they are very useful, but rather, just "highlight" the application logs, without creating a different log level just for my logs in development.
For instance, in IntelliJ, ERROR messages are highlight in orange, WARN messages are highlighted in yellow, etc..
Is it possible to highlight my custom messages with my own color?
What I have tried:
I am using Grep Console plugin in IntelliJ. Here is the configuration (please see screenshot)
However, the log line is not being highlighted.
What am I missing please?
Thank you
You can grep, filter, and highlight the log contents with specific words by enabling the Grep Console plugin.

Where is CoreData located?

I am writing an app which uses CoreData using NSPersistentContainer to save data.
While I am developing the app, I would like to:
examine the data directly
back up the data
see what happens when I change the bundle id
I assume the data is physically stored somewhere, but I’m not sure where to look.
By default NSPersistentContainer stores the database inside app container under directory Libray/Application Support
To locate the full path, in simulator, you can print the applicationSupportDirectory using urls(for:in:) function of the default FileManager:
print(FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first?.path ?? "nil")
If you are running your app on an actual device you can download the application container following this answer.
For sandboxed apps the location goes like this:
~/Library/Containers/…/Data/Library/Application Support/…

How do I combine multiple sys_class_name while query?

In the path below where I am doing filter on sys_class_name = Generic Application
/api/now/table/cmdb_ci?&sysparm_display_value=true&sysparm_exclude_reference_link=true&sys_class_name=Generic Application
I have multiple sys_class_name like Application, Generic Application, ServiceNow Application, Share point, IBM Websphere, Business application, business service, discovered service, web application, web service, web site.
My question is how do I combine all these Sys_Class_Names?
You actually want to use the sysparm_query URL parameter with an IN condition:
sysparm_query=sys_class_nameINcmdb_ci_appl,cmdb_ci_appl_generic,...
The whole URL looks something like this:
/api/now/table/cmdb_ci?sysparm_query=sys_class_nameINcmdb_ci_appl%2Ccmdb_ci_appl_generic
Note: this is using the actual class name (e.g. cmdb_ci_appl_generic) in place of the class _label_. If you need to look up the name based on the label, go to /sys_db_object_list.do.
One easy way to use sysparm_query is to just build the list you want in the UI using the normal filter, and then just right-click the breadcrumbs (the blue text above the filter after Running) for the filter, and click Copy Query. That can just be pasted in as the sysparm_query in the table API.
When you filter on a table you can right click on the filter text and select "copy URL".
https://docs.servicenow.com/bundle/london-platform-administration/page/administer/exporting-data/task/t_UseAURLQueryToFilterAListResult.html
Your URL will look something like this:
/api/now/table/cmdb_ci?&sysparm_display_value=true&sysparm_exclude_reference_link=true&sys_class_name=Generic Application&sys_class_name=ServiceNow Application

Marklogic Spring Boot - Installing a Rest Endpoint

I am currently using the Marklogic spring boot demo. So far I have been able to add indexes, facets, front-end logic etc just fine.
Right now, I am trying to layer in some semantic logic into a rest endpoint.
I wrote a simple query into the query console, and attempted to add it to the src/main/ext folder so that it would get deployed by the ml-gradle bootrun.
Right now. This file will get deployed to the test-modules database, and is visible once saved (I can see it in explorer under URI /ext/my-endpoint. I also tried adding a folder named rest-api but that just adds it to /ext/rest-api/my-endpoint
At the top of the endpoint I have it declared as
`module namespace ext = "http://marklogic.com/rest-api/resource/my-endpoint";
However when I navigate to the URL it should be living at http://localhost:8090/LATEST/resources/my-endpoint?
It tells me it does not exist.
So I can see it in the modules database, but I can't use it on HTTP. the Query works in the query console (and is rather trivial, and-query of json-property-word-queries)
My question is:
How can I properly update the marklogic-spring-boot framework to properly deploy rest endpoints.
So I figured it out it seems.
Manually creating the file isn't registering the distribution workflow properly.
Instead I create the resource using ml-gradle
gradle mlCreateResource -PresourceName=my_endpoint
This will create a new folder called services, and create the endpoint for me, which can then have code over written.
Still not sure what gradle is doing special, so I can know what the proper way to do this manually would be, but at least it works.

Effective way to debug a Google Apps Script Web App

I have had some experience writing container-bound scripts, but am totally new to web apps.
How do I debug (e.g. look at variable values, step through code etc) a web app? In a container bound script it was easy, because I could set breakpoints, use the apps script debugger - how do I go about this in a web page e.g. when I execute a doPost?
In his excellent book "Google Script", James Ferreira advocates setting up your own development environment with three browser windows; one for the code, one for the live view (in Publish, Deploy as web app, you are provided with a "latest code" link that will update the live view to the latest save when it is refreshed), and one for a spreadsheet that logs errors (using try/catch wrapped around bits of code you want to keep an eye on).
In Web Apps, even the most basic debugging of variables through Logger.log() does not work!
A great solution to have at least simple variable logging available is Peter Herrmann's BetterLog for Apps Script. It allows you to log into a spreadsheet (the same as your working spreadsheet or a separate one).
Installation is very simple - just add an external resource (see the Github readme) and a single line of code to override the standard Logger object:
Logger = BetterLog.useSpreadsheet('your-spreadsheet-key-goes-here');
Remember, that the spreedsheet that you give here as a parameter will be used for the logging output and thus must be writable by anybody!
BetterLog will create a new sheet called "Log" in the given spreadsheet and will write each log call into a separate row of that sheet.
So, for me, I debug the front-end using inspector, I haven't found a way to step through code yet, but you can use 'debugger' in your javascript (along with console.log) to stop the code and check variables.
to debug the backend, what I've been doing is to write my functions like
function test_doSomething(){
payload = "{item1: 100, item2: 200}" //<- copy paste from log file
backend_doSomething(payload)
}
function backend_doSomething(payload){
Logger.log(payload)
params = JSON.parse(payload)
...
}
Then after refreshing your project on the backend, you can look at executions, grab the payload from the log file, and paste it into your test_doSomething() function.
From there, you are re-creating the call that you want to debug and you can run that, stepping through the backend code as usual.

Resources