summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/Logger/File_Logger_Backend.cpp
blob: 7e45b0fa26a247f87007fb233a2e9e50810e4e83 (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 "Log_Macros.h"

namespace DAnCE
  {

  int
  File_Logger_Backend::open (const ACE_TCHAR *)
  {
    DANCE_DEBUG ((LM_DEBUG, "[%M] Setting logger's output to file \"%s\"\n", this->filename_.c_str()));
    this->fh_ = ACE_OS::fopen (this->filename_.c_str(), "a+");
    if (0 == this->fh_)
      {
        ACE_TString s = ACE_TEXT("Failed to open log file \"");
        s += this->filename_;
        s += ACE_TEXT("\"\n");
        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;
  }

}