SOL9 Sample: LogWriter

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * LogWriter.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#include <sol\LogWriter.h>

class UserLogWriter {

public:
  static LogWriter& getInstance() {

    static LogWriter logWriter;
  
    try {
      TCHAR user[_MAX_PATH];
      const TCHAR* filename = _T("test.log");
      GetEnvironmentVariable(_T("UserProfile"), user, SizeOf(user)); //2012/06/26

      _tprintf(_T("LogProperties dir=[%s] filename=%s level=%d\n"), 
        user, filename, LogWriter::LOG_TRACE);

      logWriter.setProperties(user, _T("test.log"), LogWriter::LOG_TRACE);


    } catch (...) {
      
    }
    return logWriter;

  }
};

class DefaultLogWriter {

public:
  static LogWriter& getInstance() {

    static LogWriter* logWriter=NULL;
    if (logWriter==NULL) {
      logWriter = new LogWriter();
    }
    _tprintf(_T("DefaultLogWriter fullpath=[%s], level=[%d]\n"),
      logWriter->getFullPath(), logWriter->getLevel());

    return *logWriter;

  }
};

void _tmain(int argc, TCHAR* argv[])
{
  LogWriter& log = UserLogWriter::getInstance();

  log.trace("This is a trace level log. %s", "Enter log.error");

  log.error("This is a error level log");

  log.trace("This is a trace level log. %s", "Leave log.error");

  log.debug("This is a debug log integer=%d", 12345);

  LogWriter& logger = DefaultLogWriter::getInstance();
  
  logger.trace("Using a default log writer. This is a trace level log. %s", "Enter log.error");

  logger.error("Using a default log writer. This is a error level log");

  logger.trace("Using a default log writer. This is a trace level log. %s", "Leave log.error");

  logger.debug("Using a default log writer. This is a debug log integer=%d", 12345);

  //logger.~LogWriter();
  LogWriter* l = &logger;
  delete l;

  //2008/07/16
  LogWriter& sollog1 = LogWriter::getInstance();
  sollog1.error("LogWriter,1,Somehting error1 happened.");

  LogWriter& sollog2 = LogWriter::getInstance();
  sollog2.error("LogWriter,2,Somehting error2 happened.");
      
}

Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.