Need to Log Only errors in Cloudwatch - amazon-web-services

I am using Lambda function for populating Dynamo DB. I need to log the event details in cloudwatch to know the exception if some occurs. I am able to configure cloudwatch logs for the lambda function but it is showing other debug statements that is leading to unwanted logging. Is there any way to configure that.Any help will be appreciated.

OK, I think I misunderstood your question. Apparently (from your comment) you're using log4j. The way to set log4j logging level is:
logger = Logger.getRootLogger(); // or Logger.getLogger("com.foo");
logger.setLevel(Level.ERROR);
This is standard log4j use, regardless of Lambda. A more Lambda-specific question might be how to control logging without changing your source code. Currently the best answer to that is using Lambda aliases, which would be clumsy, but soon Lambda will support environment variables as part of the function configuration and you could use that.

Each invocation will get three log lines from Lambda: START, END, and REPORT. All other log lines are from customer code (or modules used by customer code), or else a stack trace from an unhandled exception in user code, so it's up to you to control that.

You have to use the exception handling mechanism in your code. if any of error occur in your code then catch block should run and there you can use stacktrace methods for tracing the error. The stack trace method can be different in different languages.
For Cloudwatch log you can use simple console output methods according to languages.

Related

Retry on AmazonSQSClient

I'm using AmazonSQSClient to interact with the SQS service and using the default client configuration which means it already is using the DEFAULT_RETRY_POLICY.
Let's say I make a call in my Java code to the "sendMessage" method.
As per the doc, the method can throw 2 types of Exceptions: InvalidMessageContentsException & UnsupportedOperationException.
Now let's say that the SQS service was unavailable due to whatever reason, and even after retries the SQSClient could not perform the sendMessage operation. I'm trying to understand how would I get to know that in my Java code. I can catch the aforementioned exceptions but I don't think these exceptions would have the info I need. They seem more related to an invalid message or an unsupported operation.
Am I missing something? Thoughts?
This looks like the relevant Java SDK code. This section leads me to believe you'll receive a SdkClientException with the causal exception inside of it.

Is it OK to log from a Flask Extension?

I was looking at source from the Flask Extension Registry. I probably looked at about 6 or 7 projects and couldn't find any of them logging output.
My question is: is it OK to do so? If so, should I use app.logger or my own logger?
Yes, you should log - no, you should not use the application logger since the user will not the be able to configure your extension's logging verbosity separately from their own.
Instead, create your own logger using Python's built-in logging module. Add a NullHandler (Python 3 has one, create your own NullHandler for Python2) so that by default your library will not log anything. Add a documentation section explaining how the user can access your logger to setup handlers (and explicitly configure levels, should they so desire).
As is often the case, there is some very good advice on this subject in Python's documentation:
Configuring Logging for a Library
When developing a library which uses logging, you should take care to document how the library uses logging - for example, the names of loggers used. Some consideration also needs to be given to its logging configuration. If the using application does not use logging, and library code makes logging calls, then (as described in the previous section) events of severity WARNING and greater will be printed to sys.stderr. This is regarded as the best default behaviour.
If for some reason you don’t want these messages printed in the absence of any logging configuration, you can attach a do-nothing handler to the top-level logger for your library. This avoids the message being printed, since a handler will be always be found for the library’s events: it just doesn’t produce any output. If the library user configures logging for application use, presumably that configuration will add some handlers, and if levels are suitably configured then logging calls made in library code will send output to those handlers, as normal.

Making logs on a web application

I am developing an application using Django that works similar to a project manager. For this reason, the system should be capable of storing information about everything. When I say everything I refer to the actions the users do, the errors that occurred while doing an action, etc.
I have a class Log and one of its attributes is called action_type, this attribute specifies what kind of action just happened. I am supposed to have 5 kinds of types:
INFO: this log stores the information related to user's actions such as creating a project, create other users, etc.
DEBUG: should store comments made by the developers that will allow them to detect errors.
ERROR: shows errors that occurred in the system but they don't affect the system's functionality.
WARNING: it's for potentially damaging actions.
FATAL: unexpected errors, exceptions and security breaches.
I can only come up with logical logs for INFO.
Could you tell me some reasonable logs that I should include in this and the other categories?
The answer will depend greatly on exactly what your application does, but my basic approach is this:
Each time you get ready to log an event, just think about the event and it will be clear where it belongs. Did it kill your application? It's fatal. Did it prevent something from working correctly? It's an error. Could it prevent something from working, and did we just get lucky this time? It's a warning. Does anyone care? Info. Otherwise, if you still need to log it, it must be for debugging purposes.
In your particular context, it sounds like you might only be trying to log user actions. If that is the case, the only actions that could be fatal would be ones for which you don't provide an undo option (or, I suppose, if the user is able to order a piano bench and a length of strong rope through your application). I also couldn't really imagine any debug-level logs coming from user actions. Because of this, I assume you will be logging code level events in addition to user actions.
FATAL: This should only appear in the logs when your application actually crashes, and possibly alongside 500 responses. You might generate these within your wsgi application in a catch-all, only when the process would otherwise have died.
ERROR: Likely tied to http error responses. This is typically for errors caused by something outside your application. Things that happen in your code are probably expected and <= warning level, or unexpected and fatal. Errors might be a 404 from the user making a typo in a url, validation errors on form submission, or authentication errors. From the other direction, errors might be returned from remote web services that you contact or IO errors from the os.
WARNING: For things that don't break anything, but that might bite you if you keep it up. Examples are using deprecated apis and anywhere something only worked because of the default (time zone, character encoding, etc). Maybe certain input values result in warnings, too, like setting a due date in the past.
INFO: General, healthy operation. Someone created a database row (a new project or a task?), created an account, logged in or out, a socket was successfully opened, etc.
DEBUG: Just what it says. Output that you will usually turn off once the code is working correctly. Method entry/exit, object instantiation, field values at various points in the code, counters. Whatever you need to figure out why your program is crashing right now, as you work on it.

Writing to the Windows Security Log with C++

I have been tasked with writing entries to the Windows security log. The entire project is Win32 C++ code. I have already written (with help from various online resources) a logging class that handles registration, deregistration, and code for executing the ReportEvent() call. Also, I've done the mc.exe and rc.exe steps for my event logging, if that helps establish where I'm at in the project.
My question is a multi-parter:
I've noticed at Filling Windows XP Security Event Log that there are some who believe this is not allowed by Windows. Others ( How to write log to SECURITY event Log in C#? ) imply otherwise. Possible or not?
If it is possible, how to get it to write to the security log. Is it as simple as specifying "Security" as my source name when calling RegisterEventSource()?
As far as deregistration, when should that occur? When the app is uninstalled? When the app closes? When the log entry is written?
How do I look up my log entries? I look in the Windows Event Viewer, but I don't see the entries I add with my test app, despite all the appropriate return values from the system calls. Where would I look up the events that I specified with a source name of "yarp" when I made my call to RegisterEventSource()?
For the moment, I'll just deal with the first question, because the answer to that probably renders the rest irrelevant.
Only Local Security Authority (lsass.exe) can write to the security log. This isn't a matter that something else attempting to get the privilege will fail -- it's a matter of there not being a way for anything else to even request the privilege at all (and this is by design).
From there, about the only answer to your other questions is "Sorry!"

How to trace Coldfusion template execution in details?

I have some 'spaghetti'-style code that is generously saused with Custom tags and Stored procedures calls. Templates include each other, custom tags nested and stored procedures are callind other stored procedures in their place.
Problem is that one template call is hanging somewhere in between. I cannot get any error out and cannot see debug output. What is best way to debug such 'hanging' request with as much detail as possible ?
Thanks!
If you are using CF 8+, you can use the Step Debugging tools in Eclipse to step through the code: http://www.adobe.com/devnet/coldfusion/articles/debugger.html
If you are using an earlier version, you can use a 3rd party product like Fusion Debug ( http://www.fusion-debug.com/fd/ ) to do the same thing.
If you are using CF8, you can also use the CF Admin Server Monitor to see where a thread is hanging as well: http://www.adobe.com/devnet/coldfusion/articles/monitoring_pt1.html
If the built-in debugger is of no use cause the request just hang the other quick way is to just start with a cfabort at the top and keep moving it down until you hit the file causing the request to hang.
CFTrace is a great tool for this. It is native and reports time information as well.
Have you looked at the standard coldfusion server log files to see what might be in there?
Have you run the server in a console window so you can see what is appearing in the console as the templates are running (or not as the case might be)?
You could Take jvm thread dumps. You can do from command line or via server monitoring if you have Enterprise 8+