1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2010 Licq Developers <licq-dev@googlegroups.com>
4  *
5  * Please refer to the COPYRIGHT file distributed with this source
6  * distribution for the names of the individual contributors.
7  *
8  * Licq is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Licq is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Licq; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22 
23 #ifndef LICQDAEMON_FILELOGSINK_H
24 #define LICQDAEMON_FILELOGSINK_H
25 
26 #include "streamlogsink.h"
27 
28 #include <fstream>
29 
30 namespace LicqDaemon
31 {
32 
33 class FileLogSink : public StreamLogSink
34 {
35 public:
36   inline FileLogSink(const std::string& filename);
37 
isOpen()38   bool isOpen() const
39   // const_cast needed on Solaris where ofstream::is_open isn't declared const
40   { return const_cast<std::ofstream&>(myFile).is_open(); }
41 
42 private:
43   std::ofstream myFile;
44 };
45 
FileLogSink(const std::string & filename)46 inline FileLogSink::FileLogSink(const std::string& filename)
47   : StreamLogSink(myFile)
48 {
49   setUseColors(false);
50   myFile.open(filename.c_str(), std::ios::out | std::ios::app);
51 }
52 
53 } // namespace LicqDaemon
54 
55 #endif
56