I am building a Java Google App using Google App Engine and I followed these instructions on how to use Logging.
Basically, what I'm trying to do is very simple. I am issuing a POST request to a servlet in the App Engine, and I just want to print out via the Logs to see if I'm getting the data correctly. There are no statements in the Logs at all, aside from the automatically generated one saying that a POST was received, but my debug statement is not there.
Am I missing something simple outside of these directions? I'm baffled why this isn't working.
Most probably you use debug level during logging, but your logging.properties file has INFO level. Change it to DEBUG:
# Set the default logging level for all loggers to WARNING
.level = DEBUG
Make sure you have the minimum log level set in the logging.properties file.
AppEngine Logging
Related
I am running a java application in GKE and monitoring logs in Log explorer. Java application is writing logs to stdout and as far as I understand GKE agent parse it and send it to log explorer. What I found is that the log explorer shows WARN and ERROR messages with severity INFO.
I figured out that I can't change the default parser of logs and configured logback to represent java logs in JSON format suitable for GCP (I used implementation from this answer), here is an example:
{"message":"2022-02-17 12:42:05.000 [QuartzScheduler_Worker-8] DEBUG some debug message","timestamp":{"seconds":1645101725,"nanos":0},"thread":"QuartzScheduler_Worker-8","severity":"DEBUG"}
{"message":"2022-02-17 12:42:05.008 [QuartzScheduler_Worker-8] INFO some info message","timestamp":{"seconds":1645101725,"nanos":8000000},"thread":"QuartzScheduler_Worker-8","severity":"INFO"}
{"message":"2022-02-17 12:42:05.009 [QuartzScheduler_Worker-8] ERROR some error message","timestamp":{"seconds":1645101725,"nanos":9000000},"thread":"QuartzScheduler_Worker-8","severity":"ERROR"}
But it didn't help at all.
Please point me out where I am wrong with JSON format or maybe I need to configure something additionally on the GCP side. I've checked the official doc regarding log JSON format and I don't understand what I am missing.
According to the documentation link 1 & link 2
Severities: By default, logs written to the standard output are on the INFO level and logs written to the standard error are on the ERROR level. Structured logs can include a severity field, which defines the log's severity.
If you're using Google Kubernetes Engine or the App Engine flexible environment, you can write structured logs as JSON objects serialized on a single line to stdout or stderr. The Logging agent then sends the structured logs to Cloud Logging as the jsonPayload of the LogEntry structure.
If the manual implementation is not working, you may try to:
Directly send logs to Cloud Logging API
Use this official Java logback lib (note: it's currently a WiP)
Not able to run mongodb instance in ERROR log level. As defined by mongodb documentation, by default verbosity is 0 which includes information messages. But increasing verbosity to 1-5 will include debug level messages. I need only error messages to be logged in my log file. I am currently using mongodb-3.6.3 version with java driver at client side.
Is there any way to do it? If yes, how to achieve this? I've already tried reducing logs by adding quiet = true in the config file. But still, a lot of unnecessary logs are generated.
Add this line to your application.properties file and check the console output after running any MongoRepository query.
logging.level.org.springframework.data.mongodb.core.MongoTemplate=ERROR
I have logging working to Sentry from android just using the EventBuilder from raven-java, but I need to attach extra info which apparently EventBuilder or java.util.logging can't do.
I tried to use log4j but it doesn't pick up log4j.properties, how can I configure it with the Sentry DSN and other information? I have no preference about what logging library to use, so logback or log4j2 will do but they seem to suffer from the same problems.
I tried to configure logging programmatically but can't add the appender SentryAppender.
I also tried using android-logging-log4j library but this has the same problem.
I realize that https://github.com/joshdholtz/Sentry-Android exists which might work but it doesn't do retries in case of network issues which is quite important.
The https://github.com/joshdholtz/Sentry-Android library now supports saving of offline captures and failed captures as of version v1.1.0 - https://github.com/joshdholtz/Sentry-Android/releases/tag/v1.1.0
I just read the gwt-log Getting Started guide and found it very helpful, however I have a few questions surrounding the Loggers:
The SystemLogger sends output to System.err and System.out - in the context of a client-side web app running inside a browser, where will this output eventually go? Browser logs?
Does RemoteLogger depend on JUL or log4j? I have a homegrown slf4j binding that I like to use for all my Java backends, and would like to use it, but not sure if RemoteLogger will be incompatible with it?
Is it possible to have RemoteLogger hit my own LoggingServiceServlet, which could then translate the log messages coming in on the HttpServletRequest into logging statements that are compatible with my custom slf4j binding? If so, what might this config look like?
Thanks in advance!
In this link, you have a most updated documentation about the GWT logging framework
Answers to your questions:
#1 Yes it works in client side, but only when running the app in DevMode (not in production nor superdev mode). Look for the log lines in the DevMode window, or in your terminal output if you run dev-mode from the command-line.
#2 It depends on java.util.logging, you can change it though (see #3)
#3 Yes you can change the logging framework extending the RemoteLoggingServiceImpl and overriding the logOnServer(LogRecord lr) method.
I'm using Log4j in my application and application logging is working fine while framework in my application is internally using commons-logging and logs are going to System.out but I want to redirect them to a separate file and also want to enable DEBUG level.
Tested this on tomcat and working fine. Generating all logs in their respective files. But when I deploy code on WAS7.0, only INFO level of framework logs are being generated SystemOut.log. (my log4j.xml is fine as it is working fine on tomcat)
Any help would be appreciated. Thanks!
I was having the same problem. I found the answer in Websphere Docs.
Note: Trace information, which includes events at the Fine, Finer and
Finest levels, can be written only to the trace log. Therefore, if you
do not enable diagnostic trace, setting the log detail level to Fine,
Finer, or Finest does not effect the logged data.
Reference: http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Frtrb_loglevels.html
In Java Utility Logging terms FINE = DEBUG, so DEBUG level and below will not appear in System.out, only int the WAS trace log.