summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciao/Logger/File_Logger_Backend.cpp
blob: b4a25d0d1b19000c4006ad6658278264bd49e729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// $Id$
#include "File_Logger_Backend.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Log_Record.h"
#include "ace/Log_Msg.h"
#include "ciao/CIAO_common.h"

namespace CIAO
{

  int
  File_Logger_Backend::open (const ACE_TCHAR *)
  {
    CIAO_DEBUG ( (LM_DEBUG, CLINFO "Setting logger's output to file \"%s\"", this->filename_.c_str()));
    this->fh_ = ACE_OS::fopen (this->filename_.c_str(), "w");
    if (0 == this->fh_)
      {
        ACE_CString s = "Failed to open log file \"";
        s += ACE_TEXT_ALWAYS_CHAR (this->filename_.c_str ());
        s += "\"";
        throw LoggerError (s.c_str());
      }
    return 0;
  }

  int
  File_Logger_Backend::close (void)
  {
    if (0 != this->fh_)
      {
        ACE_OS::fclose (this->fh_);
        this->fh_ = 0;
      }
    return 0;
  }

  ssize_t
  File_Logger_Backend::log (ACE_Log_Record &log_record)
  {
    int res = log_record.print (0, ACE_Log_Msg::VERBOSE, this->fh_);
    ACE_OS::fflush (this->fh_);
    return res;
  }

}