From D Wiki
Revision as of 16:42, 28 January 2015 by Dicebot (talk | contribs) (Current state)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


std.logger is a module authored by Robert Schadek. It is relatively minimalistic module aiming to serve as a standard API base for any common logging functionality one may need in the application. It does not aim to provide many actual "batteries" right now.

Related links

Initial pre-review discussion

Current state

Merged into std.experimental for further polishing

Review 1

Proposed extensions (not needed for merging, can be implemented later on)

structured logging$prm$

I think we can provide structured logging support as a non-breaking API extension, so we should not make this part of this review. But here's how I'd imagine such an API to work:


  • log_ get new overloads which accept (T...) as the last parameter (or if T... is already the last parameter that's fine).
  • Add a new struct to logger.core: struct MsgID which is just a strong typedef for UUID
  • Add a templated type, KeyValue, which can be used like this:
  KeyValue("user", "nobody") //string key / string value
  KeyValue("age", 42); //string key / T value
  KeyValue("msg", "Hello %s! %s", "World", 42); //string key/fmt val
  • KeyValue stores it's parameters, no string processing yet
  • Multivalue parameters handled by many KeyValue with same key? Might complicate backend. Or don't support multivalue at all? Or KeyValue("key", MultiValue(a, ,b, c)) (MultiValue == Tuple?)
  • Structured loggers do not use msg, instead they use a KeyValue with "msg" key. This is cause you usually want different messages with structured loggers. We still keep everything in one function, so the user doesn't have to do "if(structuredlogger) logstruct() else log()" for every log message.
  • MsgID marks the end of normal format parameters. See example below. This is also the reason why we can't use UUID directly


string error;
logf("Something bad happened: %s", error,
     MsgID("abcd-valid-uuid"),       //MsgID--> end of fmt params
     KeyValue("msg", "Something bad happend"),
     KeyValue("error-code", error));

output: normal backend:

test.d:42 Something bad happened: out of memory

structured backend: (only example, exact format backend specific)

  "uuid": "abcd-valid-uuid",
  "msg": "Something bad happened",
  "error": "out of memory",
  "file": "test.d",
  "line": 42

The next part is an efficient Backend Layer:

class StructuredLogger : Logger
    writeLogMsg; //Not used

    void logKey(string key);
    void valuePart(const(char)[] part);
    void finishValue(bool last); //Last only if we support multivalue


auto slog = new StructuredLogger();
foreach(KeyValue kv; T...)
    //Need slog -> outputrange adapter: map put<>valuePart
    formattedWrite(wrap(slog), kv.formatstring, kv.args);


No formal result expected for early review. Opinions expressed, arguments made.


Review thread

Review 2


Voting for inclusion into std.experimental has been started


Review thread

Pre-voting review at some point turned into discussion about different API options and necessary features. Lot of changes have been done based on feedback. There is still no full agreement about target API (and will probably never be) but package has been confirmed to be used by several real-world users and should be ready for inclusion to std.experimental

Voting for std.experimental

Voting thread


Votes for inclusion into std.experimental. As original description did not match actual expectations of the process from Andrei I adjusted some of votes based on more detailed explanations. Thus "yes" votes that list clear critical API requirements that not yet met has been turned into "No".

  1. Jakob Ovrum* - No (
  2. Rikki Cattermole - Yes ($2cvn$
  3. Andrei Alexandrescu* - No ($2e9n$
  4. Martin Drašar - Yes (
  5. John Colvin - Yes (
  6. Casey - Yes (
  7. Francesco Cattoglio - No (
  8. Byron Heads - No ($24d$
  9. ponce - Yes (
  10. Sean Kelly* - No (
  11. MrSmith - Yes (
  12. Martin Nowak* - No ($p7i$
  13. David Nadlinger* - No (

6 Yes, 7 No

Members of are marked with *


While there were many objections against specific design choices overall attitude to the proposal is positive and utility of standard logging module is not questioned. Discussion has naturally moved to GitHub PR which is indeed most practical course of actions - once Phobos reviewers make sure all concerns listed are taken care of, it can go striaght for another approval voting without any additional formal review overheead.

Effective outcome is thus : postponed until blockers are taken care of.

Review 3

Review 3 has effectivelty never ended - comments kept coming to in a slow flow with various issues fixed over a long period of time.

At some point it was decided that it could take forever and more practical approach would be to continue development in std.experimental