SpringBoot IntelliJ: distinguish my own logs versus framework based logs - spring-boot

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.

Related

How to debug web development in Google Application Script?

I am testing/learning webhook. How to send, receive it. So I thought I would use GAS.
I have this simple script and I wonder why Logger does not work. In Projects/Executions I can see that the script doPost was executed but no logs. Email was sent and the script returned the value.
using old, Legacy Editor (no idea how to get the new one)
in Menu-Resources-Cloud Platform Project is said "This script has an Apps Script-managed Cloud Platform project."
when I open the project in editor I get this message "This project is running on our new Apps Script runtime powered by Chrome V8."
exception logging set to "exceptionLogging": "STACKDRIVER" is set to default
I tried console.log(e); but it did not work for me.
function doPost(e) {
Logger.log("I was called")
if(typeof e !== 'undefined'){
Logger.log(e.parameter);
Logger.log("I was called 2")
MailApp.sendEmail({
to: "radek#gmail.com",
subject: "Call Sucessful",
htmlBody: "I am your <br>" +
JSON.stringify(e)+ "<br><br>" +
JSON.stringify(e.parameters)
});
}
return ContentService.createTextOutput(JSON.stringify(e))
}
Question1: Can I make Logger work?
Question2: I would like to see accepted data in Debugger, is that possible?
Question3: Is there any way the GAS pushes the data it received to my web browser. Of course the browser is NOT sending the data.
Question4: No related to the topic but ... Would you know what I need to do in order to be able to use new Editor?
If you want your own custom log information to go to Stackdriver, then you need to create a Google Cloud Platform project, and associate that GCP project with your Apps Script project.
First create a new GCP Project:
Go to your GCP dashboard:
https://console.cloud.google.com/home/dashboard?authuser=0
In the blue bar at the top, there is a drop down menu for project names. Click that, and a dialog should appear with a button to create a new project.
Create a new Google Cloud Platform project.
Copy the Project Number.
Go back to the Apps Script editor.
From the legacy Apps Script editor, click the "Resources" menu.
Click Cloud Platform project.
Paste in the Project Number and click the button.
Now, any console.log() statements you have will send the logs to Stackdriver.
And Stackdriver can be viewed in your browser.
Note: Some people set up their own logging system to log information from server side Apps Script code to a Google Sheet. There are some open source repos that are available.
The new code editor does have a "built-in" way to log server side information to a log pane code editor window. But, of course this assumes that you are running code from the code editor. This new feature avoids the need for changing browser tabs to see your logging output. I don't know of any way to log server side info to your browser console. You could save log info into an object, and then send it back to the client after the server code completed, and then log everything in the console.
The way that it might be possible to get logging information depends on how the code was originally triggered.
From code editor
From a user using your app
From a Http Request to your Web App
Logging in Apps Script works differently depending upon:
run time version being used - V8 or DEPRECATED_ES5 - Set in appsscript.json file or through the "Run" menu in the Legacy editor, Set in "Settings" in new IDE - New Apps Script projects default to V8 so chances are your project is using V8.
Is your Apps Script project associated with a Google Cloud Platform
(GCP) default or standard project
Is exception logging set to "exceptionLogging": "STACKDRIVER" - Set in appsscript.json file - Default is always to include it - Probably already correct unless you deleted it.
Using either Logger.log or console.log
Using console.log in the server ".gs" file or client side ".html"
file. console.log can be used in both server and client side code
but the log print out goes to different places. You can't see logs
in the browser dev tools from a console.log statement in your
server code. If you use console.log in server side .gs files, and the Apps Script project is not associated with a standard GCP project, then the log only gets sent to your "Executions." I believe that the only way that you can get your logs sent to Stackdriver is by using a standard GCP project. The problem with that, is that you only have so many GCP projects that you can use without requesting an increase in your quota.
Plus there may be issues (bugs) depending upon how you have logging set up and other factors.
For example:
https://issuetracker.google.com/issues/134374008
As lots of people specified, you can use console.log for this.
However, I also work with webhooks from time to time. And I find it much more comfortable to debug directly into google spreadsheets, using code like this
function doPost(e) {
log('# doPost', JSON.stringify(e));
try {
// Some webhook-processing logic here
if(e.parameter.action == 'test-error') {
item.something = nothing;
}
if(e.parameter.action == 'test-log') {
log('# custom log', 'Some data');
}
} catch(error) {
log('# error', JSON.stringify([error, error.stack]));
}
}
function log(event, message){
SpreadsheetApp.getActive().getSheetByName('Log').appendRow([new Date(), event, message])
}
Example spreadsheet:
https://docs.google.com/spreadsheets/d/144i9pxDIB_C8ZRZ-6vd9DiPIw8Rt85hTtVoqk7dtHQg/edit?usp=sharing
You can trigger logging by something like this
curl -X POST https://script.google.com/macros/s/AKfycby3EoaQ8DOt8H_Mc4vjH6JZkhsaAwYHk_sa9HE5Be3qVo0Ym0b2/exec?action=test-error
or
curl -X POST https://script.google.com/macros/s/AKfycby3EoaQ8DOt8H_Mc4vjH6JZkhsaAwYHk_sa9HE5Be3qVo0Ym0b2/exec?action=test-log
You can use same log for your custom logging of some intermediate variable during webhook resolution.
The reason I prefer this over standard stackdriver logging is that google sheets are more explicit and easier to manage.
You can use console.log() to see things within "My Executions".

Form displays blank fields instead of DB data values

I have a from with a plugin that updates a record in the DB. I see the updated data in the record in the DB, but when i load the form the updated data does not show.
there are no business rules, the is no JS OnLoad event.
The record is inactive in the DB when the data is updated, but i don' think that should matter
Any ideas as to what I am overlooking?
You're correct that the changes should still save to an inactive record.
Under Advanced Settings > Administration > System Settings > Customization you can set "Enable logging to plug-in trace log" to "All".
Then in the plugin you can use the ITracingService to log messages, which are then visible in Advanced Settings > Plugin-In Trace Log.
You could log the fields' values before and after you set them to confirm that they're getting set.
Or, for a "quick and dirty" option store the fields' values before you set them, then after you set them, throw an InvalidPluginExecution exception containing the "before and after" values. The exception message will pop up right in the UI.
We'd be better able to analyze the issue if you post your code.
On a related note, when writing plugins I often separate the logic out into a Visual Studio Shared Project. I reference that project from a console app and the plugin assembly. The console app enables me to test and debug locally with full VS debugging capabilities before publishing the plugin. Of course there are certain things from the context that can be tricky to mock in the Console app, so your mileage may vary depending on the application.
There are also testing frameworks like FakeXrmEasy, but I have yet to try any of those.

OpenTest Reporting Library

I am currently seeking information around the available reporting capabilities for OpenTest. I would need information regarding the following:
Portability of reports/logging - can these results be published in various formats
Granularity of reports/logging - is there a way of getting very detailed in what is reported on and/or strategies to ensure that enough information is logged to allow for debugging of automated tests and System Under Test(SUT)
Screenshots - is there current functionality to allow for screenshots to be taken and published/posted to external systems?
Portability of reports/logging
You can obtain the test session results by using the API, either in JSON format (which contains a lot of detail) or the JUnit XML format:
http://localhost:3000/api/session/<SESSION_ID>?format=json
http://localhost:3000/api/session/<SESSION_ID>?format=junit
The detailed log of the test session can be retrieved in: JSON or human-readable format:
http://localhost:3000/api/session/<SESSION_ID>/log?format=json
http://localhost:3000/api/session/<SESSION_ID>/log?format=pretty
Granularity of reports/logging
The test results in JSON format will tell you everything you need to know about the pass/fail status for each test and each individual test action within a test, arguments that were used for test actions, the name of the screenshot captured for each test action, execution times and many other useful information.
When you want to troubleshoot a failed test, most of the time you'll need the detailed log information, which can be retrieved using the APIs I mentioned above. Aside from the log information generated by OpenTest itself, you can always log additional information that is specific to your application or test scenario using the $log JavaScript API.
Screenshots
Screenshots are automatically captured for Web and UI tests, whenever a test action fails. If you need to capture additional screenshots during your test, you can do so using the TakeScreenshot keyword for either Web testing or mobile testing. You can also capture a screenshot after any test action by using the $screenshot global test action argument:
- description: Click product 1 and capture a screenshot
action: org.getopentest.selenium.Click
args:
locator: { id: product1 }
$screenshot: true
You can download screenshots using this API:
https://localhost:3000/api/screenshot/SID1554380072_WEB_T05_SG01_ST01_after_03.png
SID1554380072_WEB_T05_SG01_ST01_after_03.png is the name of the screenshot file, which you can find in the test execution results in JSON format.
Integrating with custom reporting solutions
At some point you will need to integrate with a dedicated reporting product that can give you all the nice features that OpenTest is not be able to provide out-of-the-box. This is possible to do using the APIs I described. In order to notify interested parties of the current status of test sessions, OpenTest also provides a WebSocket API. You can use that to be notified when a test session has finished, then you can extract all the information you need via APIs. You can find a Java project that does all that here: https://github.com/adrianth/opentest-monitor. This project is intended as a starting point for your own custom integration.

Developer log in Joomla?

Does Joomla have a general purpose API for logging debug information to a file, or to the database, so that extension writers can capture debug info from a live site?
Enabling debug output and logging to screen is not an option. It's a live site.
Something like Drupal's watchdog would be nice.
I'm sorry for the short answer :)
This page might help: https://docs.joomla.org/Using_JLog
It shows how to configure the log output and how to use logging in your own code.
EDIT, in case the link dies:
Enable "Log Everything" under the properties of the System - Debug plugin.
To create log records:
JLog::add("Hello world", JLog::INFO);
If within a namespace, qualify JLog:
\JLog::add("Hello world", \JLog::INFO);
There's no built-in log reading UI, just look at administrator/logs/everything.php.

How can I get the open new issues, confirmed new issues, false positive new issues?

This is a screen where we configure our project, SonarQube shows new issues open, confirmed which is highlighted in yellow, I am using the SonarQube API in my application and want to dump the data to my DB. Accordingly I will create the report. But In Sonar Metrics document I do not find how could I get these value using API.
api/issues/search should get you all you need. Check out the documentation embedded in your SonarQube server (linked at the footer).
From the use-case you describe, parameters sinceLeakPeriod or createdAfter / createdInLast can help out with date filtering. Not to mention other filters like resolved and componentKeys. Exchaustive listing is in the WebAPI documentation.

Resources