1:#include <log4sendpp/log4sendpp.h> // always first
2:
3:#include <iostream>
4:
5:#include <log4sendpp/tcpip_appender.h>
6:#include <log4sendpp/file_appender.h>
7:#include <log4sendpp/xmlformatter.h>
8:#include <log4sendpp/simpleformatter.h>
9:#include <log4sendpp/logger.h>
10:#include <log4sendpp/exception.h>
11:#include <log4sendpp/arguments.h>
12:
13:
14:using namespace log4snd;
15:
16:
17:int main()
18:{
19: int result = 255;
20: std::cout << "starting example\n";
21: try
22: {
23: std::cout << "initializing library\n";
24:
25: Logger::initLogging("trivial", TcpIpAppender::gethostname());
26: Logger &logger = Logger::logger();
27:
28: ////////////////////////////////////////////////////
29:
30: std::cout << "preparing diagnostic info\n";
31:
32: ThreadDictionary::get()->add(ThreadDictionary::getCurrentHandle(), "main");
33: ThreadDictionary::get()->add((ThreadDictionary::Handle)12, "another");
34:
35: logger.ndc().push("trivial context\nline 2 of context");
36:
37: logger.property().add("property-1", "value-1");
38: logger.property().add("property-2", "value-2");
39:
40: logger.mdc().add("mdc-1", "value-1");
41: logger.mdc().add("mdc-2", "value-2");
42:
43: ////////////////////////////////////////////////////
44:
45: std::cout << "sending some simple messages to chainsaw\n";
46:
47: logger.setLevel(Logger::All);
48: logger.trace("trace message");
49: logger.debug("debug message");
50: logger.info("info message");
51: logger.warn("warn message");
52: logger.error("error message");
53: logger.fatal("fatal message");
54:
55: ////////////////////////////////////////////////////
56:
57: std::cout << "sending some extended messages to chainsaw\n";
58:
59: logger.ndc().push("more ndc data");
60:
61: LOG4SENDPP_TRACE("trace-macro\nline2");
62: LOG4SENDPP_DEBUG("debug-macro\nline2\nline3");
63: LOG4SENDPP_INFO("info-macro");
64: LOG4SENDPP_WARNING("warning-macro");
65: LOG4SENDPP_ERROR("error-macro");
66: LOG4SENDPP_FATAL("fatal-macro");
67:
68: logger.ndc().pop();
69:
70: LOG4SENDPP_MACRO_TI("message throwinfo", "throwable-ti", Logger::Info);
71: LOG4SENDPP_MACRO_LI("message locinfo", "my-category", Logger::Error);
72: LOG4SENDPP_MACRO_LTI("message loc+throw info", "my-category", "throwable-ti", Logger::Error);
73:
74: result = 0;
75: }
76:
77: catch(Exception &ex)
78: {
79: std::string fmt("Exception caught (%1, %2):\n %3\n");
80: fmt << ex.getSrcFile()
81: << ex.getSrcLine()
82: << ex.getMessage();
83: std::cout << fmt;
84: result = 1;
85: }
86:
87: std::cout << "terminating example with result " << result << std::endl;
88: return result;
89:}
90: