mastercoin-MSC / mastercore

mastercore info
mastercoin.org
MIT License
24 stars 11 forks source link

Move: logger into new file #265

Closed dexX7 closed 9 years ago

dexX7 commented 9 years ago

This is actually a move only commit with the intention of isolating the logger, because it's a component basically used by every other, but currently bound to the huge mastercore main files.

Build confirmation: https://travis-ci.org/dexX7/mastercore/builds/45404613

dexX7 commented 9 years ago

I wanted to keep this as "move only", so consider this for further discussion.

What's most notable imho: it should not really be the decision of a specific module, whether something gets logged or not.

PSR-3 from the PHP world provides suggestions for an unified logger interface, which should not be used as blueprint, but might serve as idea:

public function log($level, $message, array $context = array());
...
public function warning($message, array $context = array());
public function info($message, array $context = array());
public function debug($message, array $context = array());

Here is an example for our case:

if (msc_debug_metadex1) {
    file_log("%s(%s: prop=%u, desprop=%u, desprice= %s);newo: %s\n", ...);
}

What I mean: x_Trade should neither worry, if msc_debug_metadex1 is enabled, nor if it's logged to a file, console or whatsoever. It might as well look like this:

Log("metadex1", "%s(%s: prop=%u, desprop=%u, desprice= %s);newo: %s\n", ...);

Using an enum or so instead of a string for the category or log level is to prefer, but this functionallity is basically already provided by Bitcoin Core with:

LogPrint(const char* category, const char* format, TINYFORMAT_VARARGS(n))

And it then gets decided, if given category is accepted or where the content to log is added to.

whitj00 commented 9 years ago

Ack, refactoring is good

dexX7 commented 9 years ago

Addressed by https://github.com/OmniLayer/omnicore/pull/17.