8e031e7fa57b378e4ab04f71a12b91d87268f80d
[oweals/dinit.git] / src / dinit-log.cc
1 #include <iostream>
2 #include "dinit-log.h"
3
4 LogLevel log_level = LogLevel::WARN;
5 bool log_to_console = true;    // whether we should output log messages to console
6 bool log_current_line;
7
8 // Log a message
9 void log(LogLevel lvl, const char *msg) noexcept
10 {
11     if (lvl >= log_level) {
12         if (log_to_console) {
13             std::cout << "dinit: " << msg << std::endl;
14         }
15     }
16 }
17
18 // Log a multi-part message beginning
19 void logMsgBegin(LogLevel lvl, const char *msg) noexcept
20 {
21     log_current_line = lvl >= log_level;
22     if (log_current_line) {
23         if (log_to_console) {
24             std::cout << "dinit: " << msg;
25         }
26     }
27 }
28
29 // Continue a multi-part log message
30 void logMsgPart(const char *msg) noexcept
31 {
32     if (log_current_line) {
33         if (log_to_console) {
34             std::cout << msg;
35         }
36     }
37 }
38
39 // Complete a multi-part log message
40 void logMsgEnd(const char *msg) noexcept
41 {
42     if (log_current_line) {
43         if (log_to_console) {
44             std::cout << msg << std::endl;
45         }
46     }
47 }
48
49 void logServiceStarted(const char *service_name) noexcept
50 {
51     if (log_to_console) {
52         std::cout << "[  OK  ] " << service_name << std::endl;
53     }
54 }
55
56 void logServiceFailed(const char *service_name) noexcept
57 {
58     if (log_to_console) {
59         std::cout << "[FAILED] " << service_name << std::endl;
60     }
61 }
62
63 void logServiceStopped(const char *service_name) noexcept
64 {
65     if (log_to_console) {
66         std::cout << "[STOPPED] " << service_name << std::endl;
67     }
68 }