Disable printing of log output on console using pytest - python-3.x

I am writing tests using pytest and if my validation fails it generates a lot of logs which is needed. I am using the python's standard logging module to log these errors to a file using FileHandler class.
I am using pytest-html to generate the html report.
Everything is working as expected except that pytest is logging the log messages into the terminal also which is taking more time than actual test execution. (Imagine logging around 200k log messages on the terminal).
Is there any option in pytest that would disable logging any logs into the terminal but still capture and make those logs available in the html report. It would still be desirable to log the exceptions or the assertion errors if possible.

You might be able to configure the output using the --show-capture option.
From pytest --help:
--show-capture={no,stdout,stderr,log,all}
Controls how captured stdout/stderr/log is shown on failed tests. Default is 'all'.
If you want a finer-grained control of what you filter out, you might need to look into the logging configuration itself (change the captured log level, etc.)

Related

Azure function logging doesn't appear to be working

I'm able to successfully call my functions and make them do what I want them to do. The problem is that it doesn't look like the logs are being saved anywhere and I don't see how I can view them. Which I'll want to do in the event of an error. As a test I have my working function just doing a log.Info as soon as it's called. When testing locally it prints the message to the console. I believe I've enabled everything correctly but let me explain what I've done in case I didn't.
In my app service, under Monitoring -> Diagnostic Logs, I have enabled everything. Application Logging (filesystem) verbose, Application Logging (Blob) verbose (with the storage location set), detailed error messages and failed request tracing turned on.
In my function, I'm using the TraceWriter object that's passed to my run method (I started from a template).
Please note that functions are set to require authentication. If I click on the "Monitor" tab nothing appears. It just says "Loading..." forever and there's no information. Perhaps this is because of the authentication?
I used the Azure Storage Explorer to browse to my blob. The "log" blob exists, and I do see a set of nested directories that lead up to now. However it just contains a 354 byte file that contains a few lines of some random info. This file never seems to update or get larger.
I used FTP to try and browse to where the logs might be, but there's no directory on there that contains any log files.
I also went to KUDU for my function app ({myfunctionapp}.scm.azurewebsites.net/azurejobs/#/functions). While I do see that my function was called successfully, I don't see anything from the call to log.Info anywhere.
I tried using a different logger, and as a test did: System.Diagnostics.Trace.TraceError("test error");
I also don't see this message appearing anywhere.
Am I missing something as far as set up goes? Is the problem the fact that I require authentication? If it's the latter, is there still a way to view logs? I definitely have to have auth enabled. Thanks. And if it helps, below are links to what my settings and the monitor tab look like.
Settings: https://postimg.org/image/u57m2xbl5/
Monitor: https://postimg.org/image/uou10arch/
Authentication should not cause any problems with logging and Log.Info should work out of the box, no setup required.
I highly recommend that you enable AlwaysOn for your dedicated function app. The long loading of the Monitor tab could be because your site is in a 'cold' state, where it takes longer to start up.
If you go to {myfunctionapp}.scm.azurewebsites.net/DebugConsole and navigate to LogFiles/Application/Functions do you see any expected logs there? Also, when you run a function from the portal do you see logs in the log window?
Same thing happened to me if I had Fiddler open....close Fiddler and all is good.

Application Insights logs "no data for server exceptions"

I had an issue on my test server that was throwing an exception, I noticed that it logged nothing to application insights so first tried to debug on my local machine. I managed to replicate the issue, and low and behold in my DEV application insights I have server exceptions logged.
So I go back to my Test Application insights and again replicate the issue but still no errors logged (Even after an hour or so).
However I can see it logs them as "Failed Requests", just not Server Exceptions. Without the server exceptions I can't see the stacktrace/error message.
I am using the Log4Net app insights extension to log these exceptions. It's obviously not a code issue because the same code is being run in both cases. So I looked at configuration issues.
My log4net.config and applicationinsights.config have no transforms from Dev to Test (Or to prod). They stay the same.
My Web.config only has a transform to remove the debug=true as is standard.
I do set some environment properties in Azure (Using Azure Websites), but the only one that is actually application changing is the AppInsightsInstrumentation key to switch it to a different AppInsights. However I know that this key is correct because I'm logging some things, just not others.
Here's the answer (Kinda)
I was logging the exception in a Basecontroller, this worked fine on my local machine and I could debug through.
What happens though is when I push it remotely, .net's out of the box error handling kicks in. Notably the global "HandleErrorAttribute" (Check your FilterConfig.cs). This seems to capture and swallow the exception. There is lots of other talks about this if you wish to override this behaviour, mostly when talking about other logging tools like Elmah.
The reason I only see this in my test environment is because CustomErrors defaults to remoteOnly. So I only see it not logging when it's not on my machine.
Because I'm handling errors myself, I can remove this line from my FilterConfig.cs
filters.Add(new HandleErrorAttribute());
And server exceptions should be logged now (I also handle showing the user a nice error page in my BaseController for now)

See full msg debug with Node-RED

I'm running an application on Bluemix using Node-RED. I added a debug node to output the complete msg object, but it is being truncated in the debug console. How can I see the complete object?
You can have the output sent to the console as well as the debug tab by checking a box in the debug node's config. The whole object will be sent to the console
The current debug tab will always truncate, but there are some plans to possibly add a separate debug window that could show the whole message. Also have a look in settings.js as I believe the character limit for when to truncate is set there, so if it's just too short you can increase it a bit.
EDIT:
I'd missed the bluemix tag earlier. To view the console log you need to use the cf command to tail the output. e.g. for a app called node-red you would run the following:
cf logs node-red
Not sure if you can access your settings.js file but if you do, look for the debugMaxLength property and set it to a larger number. It will display more of your debug info.
This also applies for the Node-RED add-on for Home Assistant. After changing the debugMaxLength value in config/node-red/settings.js, one needs to restart the add-on.

how to trace or log from a CFC file

Is there a way through the brasiers like firebug or another browser plugin to do traces or log console from a cfc file.
I'm completely new to CF so sorry if this seems like a stupid question.
If you want logs to be visible in the browser ColdFire is your best choice. With it, you can see all of ColdFusion's extended debugging information even on a production site. Unless you have the proper authentication via ColdFire the server won't spit out the extended info.
As #gillesc recommended, you can use LogBox which is extracted from the ColdBox framework. The ColdBox Framework has a debugging mode that allows you to trace messages to the bottom of the page, or, to a separate window. This is useful even on production sites since you can observe the tracer methods from other users.
Finally, you can simply print to the console using writeDump(var="my log message",output="console") for quick debugging--or--use the <cflog> tag to save log messages to a named log file which you can monitor using tail. For a dead simple solution, you can save the log file to the root of your site and simply press F5 to see the new log entries; however, I do not recommend this practice (unless you are saving credit card information and share that file with me :).
Hope this reply helps.
Aaron
There is a cftrace tag that will allow you to log output to the console, among other spots in your application and development environment.
<cftrace category="init data" type="Information" var="myvartooutput" />
Calling this tag will output the relevant content in a few places:
The console in ColdFusion Builder, if you are using that IDE
In Dreamweaver, the Adobe docs mention a server debug tab/view (I don't use DW, so am not sure)
At the end of the request in the debug output
In cftrace.log, which is in your log directory (/COLDFUSION/INSTALL/DIR/logs/cftrace.log)
You can also use the tag cflog to write data to one of the standard log files or you may choose to have it write the desired data to a custom log file.
<cflog file="customlog" application="no" text="Output #somevar#!" />
If "customlog" does not exist, CF will create it for you (in the same location noted above).
Hope that helps!
EDIT: I offered this more of an alternative way to using to Firebug ... if you want the logs/traces but were not necessarily wed to a browser/plug-in.
If you've got CF Builder you can actually set up a debugger, but it's terribly slow. Here's the documentation on that: http://help.adobe.com/en_US/ColdFusionBuilder/Using/WS0ef8c004658c1089-31c11ef1121cdfd6aa0-7fff.html
There's also ColdFire, which is a Firebug add-on. Never used it before but I hear good things: https://github.com/nmische/ColdFire/
Try ColdFire for firebug extension
http://coldfire.riaforge.org/

selecting a log file

We have multiple log files like database log, weblog, quartzlog in our application.
Any log from files under package /app/database will go to database log.
Any log from files under package /app/offline will go to quartzlog log.
What we need now is - want to direct the log staments from one of the java file under /app/database to be outputted to quartzlog instead of database log.
How can we select a particular log file in java file?
You need to define the appropriate appender that logs in the desired file. Read this short introduction to see how you can do it.
Then in the configuration file, you can instruct all messages from a specific package to go in the selected appender:
log4j.logger.my.package = DEBUG, myFileAppender
EDIT:
I believe that in log4j only package resolution is possible - you can't use an appender per file or method. You could try to work around this by adding an extra layer on top of log4j or implementing your own appender.
For example, instead of log.debug use:
my.loggerproxy.log.debug(message);
If you only need to do it from a single method, then the above will be enough. Just instruct the logger proxy package to be logged in a different file.

Resources