Can you send hierarchical logs to Graylog? - java

I want to send hierarchical logs to Graylog. Something like :
transactionId: 2a4c43ea-546a-4c31-afe6-4352446ef7ae Log: "start Instance"
transactionId: 50c45778-6c36-4d9f-93e6-5a7cf239ab61 Log: "query database"
"start Instance" would be the parent of "query database" and so on.
So far I did just a simple example, following this tutorial: [http://www.andrew-programming.com/2018/09/13/setup-graylog-on-local-machine-and-sent-logs-to-it-from-java-application/] sending some logs to Graylog like this:
Logger logger = LogManager.getLogger(DemoApplication.class);
logger.info("Application Start Running...");
logger.debug("Application Start Running...");
logger.error("Application Start Running...");
logger.warn("Application Start Running...");
logger.info("This a test");
But I need more then this. So basically I want to be able to send hierarchical logs , and also to be able to see them in Graylog UI as a hierarchy (this is very important to me and I am not sure this is possible). Can someone give some hints if this is possible and how?

Related

Get Browser logs and make TestNG test fail if there are any SEVERE logs from browser console

I'm Designing an automation framework using Selenium+TestNG+Java.
I want to check browser logs, if there are any SEVERE logs while executing any tests, it should mark the test as FAIL.
I'm able to identify the way to fetch the browser logs and able to add it in my internal logger.
public void analyzeBrowserLogs() {
String type = "browser";
List<LogEntry> entries = driver.manage().logs().get(type).getAll();
System.out.println(entries.size() + " " + type + " log entries found");
for (LogEntry entry : entries) {
//if(entry.getMessage().contains("SEVERE"))
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}
}
I got stuck how could I check logs continually while executing the TestCases and If any SEVERE error occurs in logs, I need to mark the corresponding test status as FAIL.
It would be great addition to my framework if I'm able to design this logger feature.
Continuously polling the logs while the browser is basically running your test would not only be an overkill, but it may also cause flaky results.
So its not advisable to have your poll logs from browser, while test is running, happen in parallel.
What you should be doing is:
Leverage EventFiringWebDriver (see javadocs here) as your WebDriver implementation instead of RemoteWebDriver when your framework instantiates webdriver.
Plug in a custom implementation of WebDriverEventListener (see javadocs here) wherein you would identify events that cause javascript to get executed (usually its when a new page loads ) and for those events, within its afterXXX method, you make a call to your analyzeBrowserLogs() and if there's a SEVERE error, you throw an exception, which causes TestNG to automatically fail your test

Calling Windows COM interface and get Response

I have a system that has Windows COM interface so that external applications can connect to it and it has following details
Interface: InterfaceName
Flags: (1234) Dual OleAutomation Dispatchable
GUID: {ABCDEFG-ABCD-1234-ABCD-ABCDE1234}
I'd like to connect to this interface through Java Spring Application, it will sends a request to this interface and process the response.
I've tried to use the following code
ActiveXComponent mf = new ActiveXComponent("ApplicationName.InterfaceName");
try {
Dispatch f2 = mf.QueryInterface(" {ABCDEFG-ABCD-1234-ABCD-ABCDE1234} ");
Dispatch.put(f2, 201, new Variant("Request String"));
} catch (Exception e) {
e.printStackTrace();
}
The executable file opens but it doesn't do what I want. I want to do the following.
How do I make sure, my interface has bee registered, I can see it
under
Computer\HKEY_CLASSES_ROOT\ApplicationName.InterfaceName
Using ActiveXComponent opens the instance of application, which is not required. Application is already running.
call the interface with dispid.
Retreive the response from the call/put/invoke ( which suits best
for my requiremet ? ) and process the response.
I'm working first time with JAVA-COM_Interface and don't have much experience with it also I could find very few examples on the internet for it and I tried to convert the example I found for my project, also I am not sure the approach I am taking to call the interface is correct or not I would be glad if you can give a hand!
I have resolved this using JACOB lib.
1) Download JACOB folder from here.
2) Check your application is working & has details under
Computer\HKEY_CLASSES_ROOT\ApplicationName.InterfaceName
3) Make sure ApplicationName.dll file is registered. If not use this link for more info
regsvr32
4) Use this Java Code to send data to COM Interface with below simple code.
Dispatch dispatch = new Dispatch("Application.InterfaceName");
Variant response = Dispatch.call(dispatch, <DISPID>, message);
syso(response.getString()); // to print the response
Hope this helps.

Closing an application programmatically with custom error message?

I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}

Custom Internal Server Error Message Play Framework

In play framework, every time you get an Internal Server Error (500) in production mode, the browser shows a web page with
Oops, an error occured, This exception has been logged with id XXXX
I would like to customize the error message (or at least translate it to spanish), keeping the error id that makes it easier to look for in the application log.
I've tried to configure an error page in the Global settings in JAVA like this:
public Promise<Result> onError(RequestHeader request, Throwable t) {
return Promise.<Result>pure(internalServerError(
views.html.error.render(t)
));
}
Where I've a view named error.scala.html.
It is not working right now, it does not show any errors, just ignores it. Also with this alternative, I don't know how to display the error id.
I appreciate any suggestions, thanks a lot.
Is your Global class in the root package? That's a quite common mistake and also the reason why it is ignored.

EJB - System out printl - how to make it work

In university i'm doing EJB project on Java.
I have some Beans (Remote interface and it implementation, which do the main business logic). And i want to print some debugging text\information. For example:
#Stateless(mappedName = "BusinessLogicBean") // имя, по которому можно обращаться к этому бину извне)
public class BusinessLogicSessionBean implements BusinessLogicSessionBeanRemote, BusinessLogicSessionBeanLocal {
#PersistenceContext(unitName = "FoodDiary-ejbPU")
private EntityManager em;
#Override
public void addNewProduct(String name, Boolean isProducr, String kkal, String prot, String fat, String carb) {
System.out.printl("Now we are running method ADD NEW PRODUCT");
....
}
But when I use all methods - they are doing all business logic, but doesn't PRINT anywhere my phrase (which i'm writing with SOUT). I'm looked in Glassfish log, in log if executing my program - and there is nothing.
Could anyone tell - how can I print my information from Session Beans ?
Try to use debugger to make shure your System.out.println reached by app. Generally it looks ok.
According to glassfish documentation:
https://docs.oracle.com/cd/E19798-01/821-1752/beafc/index.html
Enabling Verbose Mode
To have the server logs and messages printed to System.out on your command prompt screen, you can start the server in verbose mode. This makes it easy to do simple debugging using print statements, without having to view the server.log file every time.
To start the server in verbose mode, use the ----verbose option as follows:
asadmin start-domain --verbose [domain-name]
When the server is in verbose mode, messages are logged to the console or terminal window in addition to the log file. In addition, pressing Ctrl-C stops the server and pressing Ctrl-\ (on UNIX platforms) or Ctrl-Break (on Windows platforms) prints a thread dump. On UNIX platforms, you can also print a thread dump using the jstack command (see http://java.sun.com/javase/6/docs/technotes/tools/share/jstack.html) or the command kill -QUIT process_id.

Categories

Resources