ealogger
ealogger is a c++ library that provides a blazing fast and easy to use logging mechanism
logqueue.h
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 LOGQUEUE_H
17 #define LOGQUEUE_H
18 
19 #include <memory>
20 #include <mutex>
21 /*
22  * We use a std::queue as basis for this threadsafe queue
23  */
24 #include <queue>
25 /*
26  * We need a conditional variable to notify a waiting thread
27  */
28 #include <condition_variable>
29 
30 #include <ealogger/logmessage.h>
31 
32 namespace ealogger
33 {
49 class LogQueue
50 {
51 public:
55  LogQueue();
56 
61  void push(std::shared_ptr<LogMessage> m);
66  std::shared_ptr<LogMessage> pop();
71  bool empty();
72 
73 private:
75  std::mutex mtx;
76  std::queue<std::shared_ptr<LogMessage>> msg_queue;
81  std::condition_variable cond_var_queue;
82 };
83 }
84 
85 #endif // LOGQUEUE_H
bool empty()
Check if the Queue is empty.
Definition: logqueue.cpp:46
LogQueue()
LogQueue constructor.
Definition: logqueue.cpp:20
Main namespace for ealogger.
Definition: conversion_pattern.h:28
void push(std::shared_ptr< LogMessage > m)
Push LogMessage in the Queue.
Definition: logqueue.cpp:21
The LogQueue class represents a threadsafe queue ealogger uses to store log messages.
Definition: logqueue.h:49
std::shared_ptr< LogMessage > pop()
Get the next LogMessage object in the Queue and remove it.
Definition: logqueue.cpp:30