Tag Info

New answers tagged

11

Here's an example that uses Java. It's been a while since I've used log4j, but from what I remember, the whole log4j logging tool would initialize from an XML file. The XML file itself could contain multiple loggers with different configurations(where you write to, what levels are written, etc). So, in this case you would have logger objects rather than ...


1

Logger.new is a factory that will take where the result will be used (name of the class/file). In the configuration files you can then decide what level to log to not logging at all for parts of the program without having to recompile the project. Thus you can disable all but high-level logging (errors) for release builds and only activate the lowest ...


1

Your comment says that "verbose" refers to the need to repeat this line of code in every class. My first response is that, in the big picture, adding two lines of code (variable definition plus import statement) to every class isn't that big a deal. Especially since you only need to add them to the classes that have behavior and therefore need to do logging. ...


0

I assume you would be writing client-side applications in browser. Security Issue: Browsers are not very fond of you accessing client's file system - this probably your biggest issue with security. Logs on client's machine are quite useless for you, because you need to access that machine to fetch the logs unless it's a machine you have access to. ...


0

Here is one way to do it, which increments a collections.Counter every time a callable attribute is accessed: class LoggingMixIn: def __init__(self, *args, **kwargs): self._log = Counter() super().__init__(*args, **kwargs) def __getattribute__(self, name): attr = super().__getattribute__(name) if callable(attr): ...


2

Collecting exceptions When collecting exceptions, be careful with two things: What will happen if an exception occurs, and while reporting it, the reporting mechanism throws another exception? The worst case is to start reporting the new exception, which may trigger a new one, resulting in thousands of new exceptions thrown in a loop. You absolutely need ...


0

I have no detailed solution for this but my approach would be to make sub classes of the exceptions you catch and store + analyse and implement some information about the exception type. public enum ExceptionDanger { Low, Middle, SecurityCritical // And so on } Now we add this to the derived exception class: public class ...


1

Are you ever going to use the information logged? It could be possibly be useful for debugging but then you will probably use a debugger anyway. I have worked on projects where practicality everything was logged, but there was a real business requirement -- they needed forensic proof if bad/fraudulent behavior by "trusted" associates was detected.


6

I don't think that article is implying that every method should should be logged that way, it's just saying when you're logging make sure you capture the context in which the log occurred. For example, if you have a log which says only "User cannot be found", if you're actually trying to understand the scenario which lead to that log then you probably need ...



Top 50 recent answers are included