|
| 1 | +// MIT License |
| 2 | +// |
| 3 | +// Copyright (c) 2019 Jussi Lind <jussi.lind@iki.fi> |
| 4 | +// |
| 5 | +// https://github.com/juzzlin/SimpleLogger |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files (the "Software"), to deal |
| 9 | +// in the Software without restriction, including without limitation the rights |
| 10 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +// copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions: |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in all |
| 15 | +// copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +// SOFTWARE. |
| 24 | + |
| 25 | +#include "simple_logger.hpp" |
| 26 | + |
| 27 | +// Don't compile asserts away |
| 28 | +#ifdef NDEBUG |
| 29 | + #undef NDEBUG |
| 30 | +#endif |
| 31 | + |
| 32 | +#include <cassert> |
| 33 | +#include <cstdlib> |
| 34 | +#include <fstream> |
| 35 | + |
| 36 | +int main(int, char **) |
| 37 | +{ |
| 38 | + using juzzlin::L; |
| 39 | + |
| 40 | + const auto logFile = "hello_world.log"; |
| 41 | + |
| 42 | + L::init(logFile); |
| 43 | + L::enableEchoMode(true); |
| 44 | + L::enableDateTime(true); |
| 45 | + L::setLoggingLevel(L::Level::Trace); |
| 46 | + |
| 47 | + std::string message = "Hello, world!"; |
| 48 | + |
| 49 | + L().trace() << message; |
| 50 | + L().debug() << message; |
| 51 | + L().info() << message; |
| 52 | + L().warning() << message; |
| 53 | + L().error() << message; |
| 54 | + L().fatal() << message; |
| 55 | + |
| 56 | + std::ifstream fin{logFile}; |
| 57 | + assert(fin.is_open()); |
| 58 | + |
| 59 | + int lines = 0; |
| 60 | + std::string line; |
| 61 | + while (std::getline(fin, line)) |
| 62 | + { |
| 63 | + assert(line.find(message) != std::string::npos); |
| 64 | + lines++; |
| 65 | + } |
| 66 | + |
| 67 | + assert(lines == 6); |
| 68 | + |
| 69 | + return EXIT_SUCCESS; |
| 70 | +} |
0 commit comments