log/tofile.cpp

/* This example shows how to create a simple log that outputs to a file */

#include <toast/log.hpp>

using namespace toast::log;

typedef logger<always_output, to_file<> > Log;

void tofile_log_example()
{
  Log log;
  log.open("example.log");

  log.message("When you're done here, go check out example.log!");
  log.message("Do a second run to see what happens.");
}

void tofile_rotation_log_example()
{
  Log log;
  log.open("example.log");

  log.max_size(size::KB * 5);
  log.max_rotated(5);

  for (unsigned int messages = 3000; messages > 0; --messages) {
    log.message("When you're done here, go check out example.log!");
    log.message("And, example.log.N");
    log.message("And, example.log.N-1");
    log.message("And .. oh, you get the idea ..");
  }
}

typedef logger<always_output, to_file<default_header_policy, newline, 
  rotation_policy<message_limit, roll_rotation> > > MessageLog;

void tofile_rotation_log_example2()
{
  MessageLog log;
  log.open("message.log");

  log.max_messages(1000);
  log.max_rotated(5);

  for (unsigned int messages = 3002; messages > 0; --messages) {
    log.message("Only 1000 of these will appear in each log, and then rotation!");
  }
}

SourceForge.net Logo