logging

UTF-8 In Python logging, how?

爷,独闯天下 提交于 2019-12-28 09:05:33
问题 I'm trying to log a UTF-8 encoded string to a file using Python's logging package. As a toy example: import logging def logging_test(): handler = logging.FileHandler("/home/ted/logfile.txt", "w", encoding = "UTF-8") formatter = logging.Formatter("%(message)s") handler.setFormatter(formatter) root_logger = logging.getLogger() root_logger.addHandler(handler) root_logger.setLevel(logging.INFO) # This is an o with a hat on it. byte_string = '\xc3\xb4' unicode_string = unicode("\xc3\xb4", "utf-8")

How to change filehandle with Python logging on the fly with different classes and imports

…衆ロ難τιáo~ 提交于 2019-12-28 08:07:11
问题 I cannot perform an on-the-fly logging fileHandle change. For example, I have 3 classes one.py import logging class One(): def __init__(self,txt="?"): logging.debug("Hey, I'm the class One and I say: %s" % txt) two.py import logging class Two(): def __init__(self,txt="?"): logging.debug("Hey, I'm the class Two and I say: %s" % txt) config.py import logging class Config(): def __init__(self,logfile=None): logging.debug("Reading config") self.logfile(logfile) myapp from one import One from two

How to use Morgan logger?

喜夏-厌秋 提交于 2019-12-28 07:58:13
问题 I cannot log with Morgan. It doesn't log info to console. The documentation doesn't tell how to use it. I want to see what a variable is. This is a code from response.js file of expressjs framework: var logger = require("morgan"); res.render = function(view, options, fn){ options = options || {}; var self = this; var req = this.req; var app = req.app; // support callback function as second arg if ('function' == typeof options) { fn = options, options = {}; } // merge res.locals options.

Use tee (or equivalent) but limit max file size or rotate to new file

情到浓时终转凉″ 提交于 2019-12-28 05:21:25
问题 I would like to capture output from a UNIX process but limit max file size and/or rotate to a new file. I have seen logrotate, but it does not work real-time. As I understand, it is a "clean-up" job that runs in parallel. What is the right solution? I guess I will write a tiny script to do it, but I was hoping there was a simple way with existing text tools. Imagine: my_program | tee --max-bytes 100000 log/my_program_log Would give... Always writing latest log file as: log/my_program_log Then

log4j not printing the stacktrace for exceptions

时间秒杀一切 提交于 2019-12-28 04:56:21
问题 I am using log4j with tomcat. When I log exceptions in my JSPs, servlets: private Logger _log = Logger.getLogger(this.getClass()); ... try{...} catch (Exception e) { _log.error("Error refreshing all prices", e); } I only get the first line of the exception, without a stacktrace. 17-Feb 17:37:45 ERROR AutoContrib:175 - Exception while publishing csv file: java.lang.ArrayIndexOutOfBoundsException Not very helpful at all! My log4j.properties file (/tomcat/common/classes/log4j.properties) looks

How to write different logs in different files with log4j2 (MDC in xml)?

泪湿孤枕 提交于 2019-12-28 04:21:28
问题 Now I'm using structure like this: Appender: <RollingFile name="user.log" append="true" fileName="users/%MDC{USERNAME}.txt" filePattern="users/archive/%MDC{USERNAME}-%d{MM-dd-yyyy}-%i.txt.gz"> <PatternLayout pattern="%-5p %d{MMMM-dd HH:mm:ss} %X: %c - %m%n"/> <Policies> <TimeBasedTriggeringPolicy/> <SizeBasedTriggeringPolicy size="50 MB"/> </Policies> </RollingFile> Logger: <appender-ref ref="user.log"> <ThreadContextMapFilter onMatch="ACCEPT" onMismatch="DENY" operator="or"> <KeyValuePair

Lazy logger message string evaluation

▼魔方 西西 提交于 2019-12-28 03:29:08
问题 I'm using standard python logging module in my python application: import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger("log") while True: logger.debug('Stupid log message " + ' '.join([str(i) for i in range(20)]) ) # Do something The issue is that although debug level is not enable, that stupid log message is evaluated on each loop iteration, which harms performance badly. Is there any solution for this? In C++ we have log4cxx package that provides macros like

how to log Spring 5 WebClient call

大城市里の小女人 提交于 2019-12-28 02:51:09
问题 I'm trying to log a request using Spring 5 WebClient. Do you have any idea how could I achieve that? (I'm using Spring 5 and Spring boot 2) The code looks like this at the moment: try { return webClient.get().uri(url, urlParams).exchange().flatMap(response -> response.bodyToMono(Test.class)) .map(test -> xxx.set(test)); } catch (RestClientException e) { log.error("Cannot get counter from opus", e); throw e; } 回答1: You can easily do it using ExchangeFilterFunction Just add the custom

Capture Output of Spawned Process to string

你离开我真会死。 提交于 2019-12-28 02:11:26
问题 Background: I'm working on a program that needs to be able to capture the stdout , stderr and return values of a program. Ideally, I would like to capture these in a string that I store inside of my object that holds details of the process. I currently have some code that works by saving the output into a file using some (in my opinion) archaic C file handle magic. Any time I want to output the results, I open up that file and I print the contents. Sometimes (when a process I spawn is left

Log4Net Logging of two different levels to two different appenders for the same logger

烈酒焚心 提交于 2019-12-28 01:52:06
问题 We have two different asp.net applications with Log4net logging enabled. They both have the same version of Log4Net, 1.2.10.0. We have added the log4net.Appender.AdoNetAppender logger to both of them and want to log Info level to it for the root logger, but also want to log to the Error level for a root logger to a file appender. Our configuration is as follows; <?xml version="1.0" encoding="utf-8"?> <log4net> <appender name="filelogAppender" type="log4net.Appender.RollingFileAppender" >