ealogger
ealogger is a c++ library that provides a blazing fast and easy to use logging mechanism
sink_file.h
Go to the documentation of this file.
1 // ealogger is a simple, asynchronous and powerful logger library for c++
2 // Copyright 2013 - 2016 Christian Rapp
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SINK_FILE_H
17 #define SINK_FILE_H
18 
21 #include <fstream>
22 
23 #include <ealogger/sink.h>
24 
25 namespace ealogger
26 {
41 class SinkFile : public Sink
42 {
43 public:
64  SinkFile(std::string msg_template, std::string datetime_pattern,
66  std::string log_file, bool flush_buffer);
67  virtual ~SinkFile();
68 
79  void set_log_file(std::string log_file);
80 
81 private:
82  std::mutex mtx_file_stream;
83  std::mutex mtx_log_file;
84 
85  std::ofstream file_stream;
86  std::string log_file;
87  bool flush_buffer;
88 
89  void write_message(const std::string &msg);
95  void config_changed();
99  void open_file();
103  void close_file();
104 };
106 }
107 
108 #endif /* SINK_FILE_H */
std::string datetime_pattern
Definition: sink.h:141
Main namespace for ealogger.
Definition: conversion_pattern.h:28
A sink is an object that writes the log message to a specific target.
Definition: sink.h:52
bool enabled
Definition: sink.h:142
std::string msg_template
Definition: sink.h:140
void set_log_file(std::string log_file)
Set log file.
Definition: sink_file.cpp:34
Sink to write to a log file.
Definition: sink_file.h:41
SinkFile(std::string msg_template, std::string datetime_pattern, bool enabled, ealogger::constants::LOG_LEVEL min_lvl, std::string log_file, bool flush_buffer)
SinkFile constructor with additional parameters.
Definition: sink_file.cpp:21
LOG_LEVEL
An enumaration representing the supported loglevels.
Definition: global.h:58