abumq / easyloggingpp

C++ logging library. It is extremely powerful, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Auto EOL

jbakosi opened this issue · comments

Is there an automatic way of processing long strings (containing EOL '\n') to appear correctly-prefixed with the FORMAT prefix in the log?

That is, when logging

std::string longone( "Results: 14 results found.\nMatches 1-10: long string\nanother long string")
LOG(DEBUG) << longone;

instead of

2022-07-06 18:22:35: DEBUG: Results: 14 results found.
Matches 1-10: long string
another long string

I would like

2022-07-06 18:22:35: DEBUG: Results: 14 results found.
2022-07-06 18:22:35: DEBUG: Matches 1-10: long string
2022-07-06 18:22:35: DEBUG: another long string

Answering my own question, with

void longlog( std::string& s, int width = 70 ) {
  auto logline = []( char*& e, char* b ){
    while (*e == ' ') ++e;
    char tmp = *e;
    *e = 0;
    NLOG(INFO) << b;
    *e = tmp;
  };
  char* b = &s[0];
  char* e = b;
  while (*(++e) != 0) {
    if (*e == '\n' || (e-b > width && *e == ' ')) {
      logline( e, b );
      b = e;
    }
  }
  if (e > b) logline( e, b );
}

I can do

longlog( longone );

Now if I could call that consistent with other log comands, e.g.,

LOG(INFO) << longone;

that would be great.

@jbakosi May i work on this issue ? I'm new to open source and I'd like to contribute