IAP GITLAB

Skip to content
Snippets Groups Projects
logger_example.cc 1.59 KiB
Newer Older

/**
 * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * See file AUTHORS for a list of contributors.
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#include <corsika/logging/Logger.h>
#include <boost/format.hpp>
#include <fstream>
ralfulrich's avatar
ralfulrich committed
#include <iostream>
#include <string>
ralfulrich's avatar
ralfulrich committed

using namespace std;
using namespace corsika::logging;
ralfulrich's avatar
ralfulrich committed

ralfulrich's avatar
ralfulrich committed
int main() {
ralfulrich's avatar
ralfulrich committed
  {
ralfulrich's avatar
ralfulrich committed
    cout << "writing to \"another.log\"" << endl;
ralfulrich's avatar
ralfulrich committed
    ofstream logfile("another.log");
    sink::SinkStream unbuffered_sink(logfile);
    sink::BufferedSinkStream sink(logfile, sink::StdBuffer(10000));
    Logger<MessageOn, sink::BufferedSinkStream> info("\033[32m", "info", sink);
    Logger<MessageOn, sink::BufferedSinkStream> err("\033[31m", "error", sink);
ralfulrich's avatar
ralfulrich committed
    // logger<ostream,messageconst,StdBuffer> info(std::cout, StdBuffer(10000));

ralfulrich's avatar
ralfulrich committed
    /*
      Logging& logs = Logging::GetInstance();
      logs.AddLogger<>("info", info);
ralfulrich's avatar
ralfulrich committed
      auto& log_1 = logs.GetLogger("info"); // no so useful, since type of log_1 is
      std::any
ralfulrich's avatar
ralfulrich committed
    */
ralfulrich's avatar
ralfulrich committed
    for (int i = 0; i < 10000; ++i) {
ralfulrich's avatar
ralfulrich committed
      LOG(info, "irgendwas", " ", string("and more"), " ",
          boost::format("error: %i message: %s. done."), i, "stupido");
      LOG(err, "Fehler");
ralfulrich's avatar
ralfulrich committed
    }
  }
ralfulrich's avatar
ralfulrich committed
  {
    sink::NoSink off;
    Logger<MessageOff> info("", "", off);
ralfulrich's avatar
ralfulrich committed
    for (int i = 0; i < 10000; ++i) {
ralfulrich's avatar
ralfulrich committed
      LOG(info, "irgendwas", string("and more"),
          boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99,
          "ENDE");
ralfulrich's avatar
ralfulrich committed
    }
  }
ralfulrich's avatar
ralfulrich committed
  return 0;
}