logging

Python mocking logging while retaining log output

社会主义新天地 提交于 2020-02-01 07:59:04
问题 I have a series of unit/integration tests which using the python logging module . I would like to test that the right things are logged when appropriate which I can achieve using the mock module as follows: @mock.patch('logging.Logger.info') However, when I do this the actual logging is stopped (for obvious reasons!) and this is useful for me to debug why my tests are working etc. My question is as follows: Is there a way in why I can mock out logging calls so I can assert they have been

Testing logging output with pytest

余生颓废 提交于 2020-02-01 03:14:05
问题 I am trying to write a test, using pytest, that would check that a specific function is writing out a warning to the log when needed. For example: In module.py: import logging LOGGER = logging.getLogger(__name__) def run_function(): if something_bad_happens: LOGGER.warning('Something bad happened!') In test_module.py: import logging from module import run_function LOGGER = logging.getLogger(__name__) def test_func(): LOGGER.info('Testing now.') run_function() ~ somehow get the stdout/log of

I want to display the file Name in the log statement

南楼画角 提交于 2020-01-30 19:54:48
问题 For every logger statement with any level, I need to display the file name from where the log statement executed, below is the illustration I given below: Example : Below is the line executed from JobWork.js logger.info("getInCompleteJobs in job works"); Actual : 2012-11-05T06:07:19.158Z - info: getInCompleteJobs in job works Required : 2012-11-05T06:07:19.158Z - info JobWork.js : getInCompleteJobs in job works Without passing the fileName as a parameter from the log statement it should give

c# Read real time from windows event log

大城市里の小女人 提交于 2020-01-30 09:09:15
问题 i can succesfully read events from event log. But polling all events has very bad performance. I wonder if there is an event or something that i can subscribe to catch log entries "as they happen"? Is this possible? EventLog log = new EventLog("Security"); var entries = log.Entries.Cast<EventLogEntry>().Where(x => x.InstanceId == 4624).Select(x => new { x.MachineName, x.Site, x.Source, x.UserName, x.Message }).ToList(); Console.WriteLine(entries[0].UserName); 回答1: You can use EventLogWatcher

c# Read real time from windows event log

不想你离开。 提交于 2020-01-30 09:08:28
问题 i can succesfully read events from event log. But polling all events has very bad performance. I wonder if there is an event or something that i can subscribe to catch log entries "as they happen"? Is this possible? EventLog log = new EventLog("Security"); var entries = log.Entries.Cast<EventLogEntry>().Where(x => x.InstanceId == 4624).Select(x => new { x.MachineName, x.Site, x.Source, x.UserName, x.Message }).ToList(); Console.WriteLine(entries[0].UserName); 回答1: You can use EventLogWatcher

c# Read real time from windows event log

旧时模样 提交于 2020-01-30 09:08:05
问题 i can succesfully read events from event log. But polling all events has very bad performance. I wonder if there is an event or something that i can subscribe to catch log entries "as they happen"? Is this possible? EventLog log = new EventLog("Security"); var entries = log.Entries.Cast<EventLogEntry>().Where(x => x.InstanceId == 4624).Select(x => new { x.MachineName, x.Site, x.Source, x.UserName, x.Message }).ToList(); Console.WriteLine(entries[0].UserName); 回答1: You can use EventLogWatcher

Microsoft Logging application block and multi-threading

白昼怎懂夜的黑 提交于 2020-01-30 06:46:48
问题 I am new to the Logging application block (4.1). Has anyone written an application that uses the Logging application block from multiple threads? I am asking because the Logger is a static class and because of potential writing to the same log file from multiple threads for example. 回答1: The Logging Application Block is thread safe, meaning you can call its public methods from multiple threads without doing any synchronization of your own. The library does its own synchronization. 回答2: I am

C++ How to set a severity filter on a Boost Global Logger

99封情书 提交于 2020-01-30 05:11:55
问题 I've been trying for days now to create a Boost Global Logger for use throughout the application but I can't seem to get the severity level set in the Global Logger . IMPORTANT: Look below for Andrey's answer...it's labeled as step (a) and (b) but I'm still not getting it right! Right out of the Boost Documentation here ...it would be more convenient to have one or several global loggers in order to easily access them in every place when needed. In this regard std::cout is a good example of

Django logging requests

懵懂的女人 提交于 2020-01-30 05:07:09
问题 I'm using django 1.11 in aws elastic beanstalk and I've been trying to get my app to log with no luck . . . I have these in my settings.py LOGGING_CONFIG = None LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': '/opt/python/current/app/staging.log', }, }, 'loggers': { '': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate'

Log4j2 Custom appender: ERROR Attempted to append to non-started appender

一笑奈何 提交于 2020-01-30 05:00:35
问题 I have created a custom appender in log4j2. While using the custom appender, I am getting the following error: "ERROR Attempted to append to non-started appender". Any help is appreciated. 回答1: Log4j 2 checks for each log event that the appender is in a useable state. The error you are seeing is that Log4j detects that the appender is not ready to be used. Some appenders need to do preparation before they can be used. The start() lifecycle method is the place where appenders can do