Skip to main content
26 votes

C++ logging library

Lots of good code comments already given. I'll focus on non-code aspects. Take this from a DevOps engineer that regularly troubleshoots complex, unfamiliar systems from logs under time pressure. You ...
Emily L.'s user avatar
  • 16.6k
23 votes
Accepted

Custom error-logging

Reusable methods Notice that you have several methods that essentially do the same thing. Log and both writeCustomErrorLog ...
Flater's user avatar
  • 5,542
20 votes

C++ logging library

I see a number of things that may help you improve your code. Separate interface from implementation The interface goes into a header file and the implementation (that is, everything that actually ...
Edward's user avatar
  • 66.6k
17 votes

Sensor logger for Raspberry Pi in a stratospheric probe

Do not call main recursively. You are setting yourself up for stack overflow. Consider instead ...
vnp's user avatar
  • 57.3k
16 votes
Accepted

A simple error messaging and logging system via macro(s) in C++

You’ve already noted that this could be done better without macros, so I won’t belabour the point. I will note, though, that your goal—“to refresh [your] skills at writing good solid macros”—makes ...
indi's user avatar
  • 13.7k
16 votes
Accepted

Python script to analyse Apache log files

If code is repetitive, you probably need some functions and better data organization. The current code is very repetitive: multiple versions of nearly-but-not-quite identical code to handle the ...
FMc's user avatar
  • 12.8k
14 votes
Accepted

Implementing a logging system in C++17

Is my code thread safe? If not, how do I make it thread safe? No, of course it's not thread-safe. You don't do anything to make it thread-safe. A more nuanced answer would be: It's thread-safe as ...
Quuxplusone's user avatar
  • 19.4k
14 votes

C++ logging library

Making functions in header files static means that each translation unit gets its own separate definition. This usually isn't what we want. Standard practice is to declare the function in the header, ...
user673679's user avatar
  • 11.9k
11 votes
Accepted

Sensor logger for Raspberry Pi in a stratospheric probe

Have you already executed the code to see how it performs and if the battery will last? There is that famous Donald Knuth quote saying premature optimization is the root of all evil (or at least most ...
Kim's user avatar
  • 226
11 votes
Accepted

Logger module in C

Redundant code As the 4 functions are nearly identical, consider coding helper functions. At a minimum, I recommend a ...
chux's user avatar
  • 33.6k
11 votes

Implicitly logging the filepath of the callsite of the log-statement

Unless I am missing something, adapting the formatter slightly would produce the same result: ...
Kate's user avatar
  • 7,568
10 votes
Accepted

Simple log writer class

The code is pretty good, and quite readable. Here are some of the things I noticed: Header guards Your Logger.h needs header guards: ...
Justin's user avatar
  • 3,295
10 votes
Accepted

SQL trigger to log when employee records are updated

First some comments. Usage of Deprecated Features Currently your trigger does a SELECT that returns a resultset from a trigger. That was at one time supported but ...
this's user avatar
  • 2,029
10 votes

C++ logging library

You have some good answers already. My criticism comes from one word. "printf". The problem for fault-finding is not just knowing what each part has reported, but also knowing in what order they ...
Graham's user avatar
  • 359
10 votes

C++ logging library

A few more suggestions in addition to the great existing answers: Support logging stack traces - it's easy! Standard C++ offers no facilities for obtaining stack traces, so traditionally - logging ...
einpoklum's user avatar
  • 2,035
10 votes
Accepted

Simple log rotation script

Return early, there's no need to touch files if the current file is <5mb. DRY your code, move the "{}{}.{}".format into it's own function. Don't use ...
Peilonrayz's user avatar
  • 43.5k
10 votes

C++ code for a simple single header logging library

General Observations: It isn't clear why you are designing this log as a singleton. This allows only a single instance of the log in the program, what if I need multiple logs? Should it be okay to run ...
pacmaninbw's user avatar
  • 24.8k
9 votes
Accepted

C++ code for a simple single header logging library

Use enum class By default, C-like enum put their enumerators in the enclosing namespace. And that's not great at all. From C++11 on, you can use enum class instead, ...
Matthieu M.'s user avatar
  • 5,590
8 votes
Accepted

Error-Handling Class and Logging for VBA

Amount of boilerplate code As it is, there are lot of boilerplate that we must provide to set up everything. At a minimum, we need the following code: ...
this's user avatar
  • 2,029
8 votes

Sensor logger for Raspberry Pi in a stratospheric probe

Opening and closing files takes resources: with open('babar.txt', 'a') as f: f.write('a'*10000) takes 300 micro-seconds while: ...
Benoît P's user avatar
  • 799
8 votes
Accepted

Operation logger

One drawback I can think of this way of logging is that (correct me if I'm wrong) it is lazy. That's to say, until the root Op object is ...
JAD's user avatar
  • 2,919
8 votes
Accepted

Minimal Python logging

Setting up logging You might be interested in logging.basicConfig, which can setup everything you setup there as well. It's not sufficient if you want for example ...
Gloweye's user avatar
  • 1,746
8 votes

Custom Logger class

Docstrings should be on the inside of a function or class, not on the outside - before the def or class. Your logger doesn't ...
Peilonrayz's user avatar
  • 43.5k
8 votes

C++ code for a simple single header logging library

That's a single header implementation in name only, but it isn't a header-only implementation. You need one (and exactly one) implementation file that uses some undocumented magic, namely ...
Zeta's user avatar
  • 19.3k
7 votes

Advanced Python logging system

PEP-8 Conventions Top-level functions should be separated (preceded and followed) by two blank lines: ...
Daniel's user avatar
  • 4,500
7 votes

SQL trigger to log when employee records are updated

You are basically reformatting one group of fields into another. I'm not sure if that's a good idea - you might want to just make a straight-up copy of the fields, since that improves your "audit" ...
aghast's user avatar
  • 12.4k
7 votes

Custom error-logging

Coding style Variable names Avoid variable names like sw or st. In your code they still make sense because they're the ...
Abbas's user avatar
  • 5,563
7 votes
Accepted

Logger that writes to text file with std::vformat

The class seems pointless, since it can't even be instantiated. Why not a free function (in a suitable namespace, perhaps)? The function itself opens and closes ...
Toby Speight's user avatar
  • 81.7k
6 votes

Custom error-logging

A few other things: 1) Your implementation is not thread safe. It is not clear how you are going to use it in multi-threaded environment. 2) Reopening file stream for every log message is ...
Nikita B's user avatar
  • 13k
6 votes
Accepted

Reading SQL query from a resource, with error logging

The most unforgivable aspect of this code is that it rethrows a degraded exception. The original type of the exception (likely an IOException) and the stack trace ...
200_success's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible