show message in log file with php - java

I need to know how to show a message in the log in apache with php, I know that java has this instruction
System.out.println
and in tcl
ns_log notice
but there are some equivalent in php?
Thanks!!!

Use the syslog function:
http://php.net/manual/en/function.syslog.php

You can use error_log to output directly to the error log.

Use error_log() function to set custom error messages
error_log("Oracle database not available!", 0);
Or you can save the errors to custom log file as
error_log("Oops, something went wrong!", 3, "/var/tmp/my-errors.log");

You have to set the level of logging on your PHP.ini, to debug or warming. Then use error_log or syslog to print to php_error.log or what ever u configure ur logging file is.

Related

Sending custom telemetry to azure insights

I have a Java azure function (runtime 3.2.0) where I try to send some custom telemetry. I use the following code
TelemetryConfiguration config = TelemetryConfiguration.getActive()
TelemetryClient telemetry = new TelemetryClient(config);
telemetry.trackEvent("Test Event");
telemetry.trackTrace("Test Trace", SeverityLevel.Warning);
telemetry.flush(); // Not sure it is needed
When I check config.getInstrumentationKey() is is the correct key for the Application Insights I want to show the custom telemetry. However, I never receive the custom event and trace in my Insights. Also config.isTrackingDisabled() i false and config.getChannel() seems to make sense.
All code examples I have found and in the official documentation as well it seems to be all the code I need. When I use the logger from the ExecutionContext logs appears in Application inside, so my function has access to it. So I suspect I have overlooked some small important fact or there is some configuration of my function that is not set correctly.
Can anybody help me get custom telemetry to work on my java function?

how to store logs in stringBuilder

I want to show the frontend user all the logs. How can I transport all the log statements to a frontend? For example:
void process(){
..
// currently this is shown in a file and in a console
log.info("process called..");
}
How can I transport this log message to the frontend in an efficient manner? Should I append the logs into a StringBuilder? How can I do this with Log4j2?
Currently, I have a no jdbc store. But I can store all my logs to a no sql database. I cannot use JDBCAppender (or CassandraAppender). Should I avoid a Logger and do it myself:
Instead of
log.info("process called..");
I could use
user.addLog("process called..");
Would it be better to get the string value of log.info(). If so, how?
The best idea would would be to store your logs in a database with a JDBCAppender. When the user requests the logs, you can decide how many of the logs to load and return in your response.
If you would hold all your logs in memory e.g. in a StringBuffer, you could run out of memory and kill your application. Also on a server restart, all your logs would be lost. Both is prevented by storing the logs into a database and access it on demand.
If you really need a StringAppender for custom integration, you have to write it yourself extending on AbstractOutputStreamAppender.
Here is a blog post with code about it.

Location of logs for java.util.logger

I am on windows, and using squirrel client to access a database on informix.
On my jsp pages there are code that open the databse informix for query.
Other than out printing the error message on the webpage where the code is eg: the code is in file DB123.jsp, then the error message can be printed out at //100.100.100.100/DB123.jsp on browser.
My question is if I have a java.sql.SQLException, where else can I look at more detailed error message, or what configuration should I make to have it enabled? Because sometimes sql error unable to be printed on the webpage.
The code at DB123.jsp with the log:
public Logger myLog = Logger.getLogger("DB123.jsp");
{...}
catch(SQLException sqle){
strMsg = "failed";
strMsgDesc = ERR_SERVICE_NOT_AVAILABLE+sqle;  //this one out print on webpage
myLog.error(sqle.getMessage());  //This line i dont know where it logs to
}...
array.put("msgdesc", strMsgDesc);
out.print(array);
/***end****/
If there is a syntax error on sql statement, the flow of the program should stopped at sql.executeQuery(); right? So the logging of error should be on the dev environment server, there wont be any thing to be debug at informix server right? So IBM interactive debugger would not help here.
Whenever I google 'location of logs of java.util.logging' or a similar phrase, I could not get any good explanation. Many searches returns codes of how to setup the logger, but not where the logs are.
Any help is much appreciated.

Redirect stacktraces to logfile instead of console output?

whenever I get an unhandled exception or stacktrace output in the serverconsole, I would rather be saving this to a global logfile. And not to print it in the server console.
How can I prevent or redirect these errors?
You can change the PrintStream instance that is set for System.err via the method System.setErr. However, this will redirect all output sent to System.err to the log file.
Although this is not kosher on java-ee, in general, have a look at UncaughtExceptionHandler.
In earlier days, you had to manage a threadgroup to intercept uncaught exceptions, but now you can set the default handler.

How to handle client side exceptions in GWT/GXT?

I am using GWT. if any server side exception is generated, we are sending an email with error details(have used log4j SMTPAppender). Based on the line number, we can fix the issue..
My scenario is, if any exception is generated in the client package code, as of now, we are giving generic message saying "Some Exception has Occured". But is it possible to display error stack trace along with the exception cause and line number? my code is as below:
GWT.setUncaughtExceptionHandler(new
GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable e) {
Window.alert("Some Exception has Occured");
}
});
I dont think it is possible as client package is converted into Javascript in web mode. Please suggest me if there is any approach to display exception cause and line number where it has occured.
You can read this page
Basically, you have to use JUL to do your logging, and it's client logging : firebug, JS console, etc... You may do some smarter things with the RemoteLogging but i can't help you on that.
The main problem is that log4j is not supported. Maybe with a bridge between JUL and log4j you will be able to achieve everything you want
I would recommend using gwt-log:
Project Page
gwt-log has support for an 'UncaughtExceptionHandler' and a RemoteLogger to send messages/exception to the server.
in gwt-log, you can also turn on the "emulated stack", which is exactly what you want to do:
Wiki Page - Emulated Stack
please note however that this adds a LOT of code to the compiled JS-script

Categories