Question

I'm making a console application, and over time I have been developing my own tools and practices for outputting text; a process that keeps evolving.

For example, these days I have 4 main types of messages formatted roughly like the following:

bold(   red("  Error: ")) + msg << endl << bold(blue("  Value: ")) + invert(val);
bold( green("Success: ")) + msg << endl << bold(blue("  Value: ")) + invert(val);
bold(orange("Warning: ")) + msg << endl << bold(blue("  Value: ")) + invert(val);
bold(yellow("Process: ")) + msg << endl << bold(blue("  Value: ")) + invert(val);

It makes sense to me, however I am concerned that I might be reinventing the wheel, and would rather follow a standard if one exists, especially if it came from a project like:

  • Linux Kernel Development
  • Qt Project
  • Highly recommended C/C++ manuals or textbooks
  • Bjourne's recommendation
  • Anything to do with C really.

Do coding standards or best practices for any major projects like this? Are there any others that fall outside this scope but are worth mentioning ?

Thanks.

Was it helpful?

Solution

You are reinventing the wheel, in several ways.

First, you seem to be conflating program output and logging. Traditionally, program output is unadorned text that goes to StdOut, while logging and error messages go to StdErr (Google for "the UNIX philosophy" or go to Wikipedia for a summary.

More complex logging needs are typically handled in Linux using the syslog facility (and again, Wikipedia for a summary).

The benefit to using an actual logging facility is that the log messages can be directed to multiple sources, and categorized according to multiple factors.

There are also third-party alternatives. In the Java world, Log4J remains popular, and there's a port of it to C. One of the benefits to third-party frameworks is cross-platform availability, and also consistency (if you're familiar with Log4C, you should be able to transition to Log4J or Log4Net or Log4JS with little effort).

Licensed under: CC-BY-SA with attribution
scroll top