1 ////////////////////////////////////////////////////////////////////////////////
3 // Copyright 2015 - 2017, Paul Beckingham, Federico Hernandez.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // http://www.opensource.org/licenses/mit-license.php
25 ////////////////////////////////////////////////////////////////////////////////
32 ////////////////////////////////////////////////////////////////////////////////
33 std::string Log::file () const
38 ////////////////////////////////////////////////////////////////////////////////
39 void Log::file (const std::string& name)
45 ////////////////////////////////////////////////////////////////////////////////
46 void Log::ignore (const std::string& category)
48 _ignore.insert (category);
51 ////////////////////////////////////////////////////////////////////////////////
52 void Log::write (const std::string& line)
57 ////////////////////////////////////////////////////////////////////////////////
58 void Log::write (const std::string& category, const std::string& line)
60 // Determine if this category is in the ignore list.
61 if (_ignore.find (category) != _ignore.end ())
66 // If line contains newlines, split it into separate lines and log each one.
67 if (line.find ('\n') != std::string::npos)
69 for (const auto& single : split (line, '\n'))
70 write (category, single);
84 // Catch up by writing out the backlog.
85 if (_name != "" && _backlog.size ())
87 for (const auto& line : _backlog)
95 std::string message = Datetime ().toISO ()
96 + ' ' + PACKAGE_VERSION
98 + ' ' + format ("(Repeated {1} times)", _repetition)
102 _file.append (message);
104 _backlog.push_back (message);
109 std::string message = Datetime ().toISO ()
110 + ' ' + PACKAGE_VERSION
116 _file.append (message);
118 _backlog.push_back (message);
123 ////////////////////////////////////////////////////////////////////////////////