libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FileLogger.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // $Id: FileLogger.h,v 1.4 2005/10/08 02:42:00 vlg Exp $
4 //------------------------------------------------------------------------------
5 // FileLogger.h
6 //------------------------------------------------------------------------------
7 // Copyright (C) 1997-2002 Vladislav Grinchenko
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Library General Public
11 // License as published by the Free Software Foundation; either
12 // version 2 of the License, or (at your option) any later version.
13 //------------------------------------------------------------------------------
14 #ifndef FILE_LOGGER_H
15 #define FILE_LOGGER_H
16 
17 #include <fstream>
18 #include <string>
19 #include <iostream>
20 
21 #include "assa/Logger_Impl.h"
22 
23 namespace ASSA {
24 
30 class FileLogger : public Logger_Impl
31 {
32 public:
33  FileLogger ();
34 
35  virtual int log_open (const char* logfname_,
36  u_long groups_,
37  u_long maxsize_ = 10485760); // 10 Mb = 1024x1024x10
38 
39  virtual int log_close (void);
40  virtual void log_resync (void);
41 
42  virtual int log_msg (Group g_,
43  size_t indent_level_,
44  const string& func_name_,
45  size_t expected_sz_,
46  const char* fmt_, va_list);
47  virtual int log_func (Group g_,
48  size_t indent_level_,
49  const string& func_name_,
50  marker_t type_);
51 
56  int log_raw_msg (const string& msg_);
57  void dump (void);
58 
59 private:
60  enum state_t { opened, closed };
61 
62  FileLogger (const FileLogger&); // copy constructor
63  FileLogger& operator= (const FileLogger&); // copy assignment
64 
65  int handle_rollover ();
66 
67 private:
68  std::ofstream m_sink;
72 };
73 
74 inline FileLogger::
76  : m_maxsize (1048576),
77  m_state (closed),
78  m_bytecount (0)
79 {
80  /*--- empty ---*/
81 }
82 
83 inline void
85 log_resync (void)
86 {
87  m_sink << std::flush;
88 }
89 
90 } // end namespace ASSA
91 
92 #endif /* FILE_LOGGER_H */