1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // contains the logger
21 #include "nel/misc/log.h"
22 #include "nel/misc/string_common.h"
24 // contains standard displayers
25 #include "nel/misc/displayer.h"
27 using namespace NLMISC
;
29 // create a displayer that displays on stdout and, on Windows, if the
30 // application is in debug mode and launched with the debugger (F5), it displays
31 // on the output windows of Visual C++.
34 // create a displayer that displays in a file. The first parameter is the filename
35 // and the second one says that we want to clear the file before logging.
36 // If you put false (default value), then, new logs are append to the file.
37 CFileDisplayer
fd("main.log",true);
39 // create a displayer that displays in a message box. It actually works only on
40 // Windows, it does nothing on other systems.
43 int main (int /* argc */, char ** /* argv */)
45 // create a logger; it's an information logger.
46 CLog
logger (CLog::LOG_INFO
);
48 // the process name is used when we have more than one process logging stuffs
49 // in the same displayer (for example for centralized displayer)
50 logger
.setProcessName ("my_process_name");
52 // add displayers for the logger
53 logger
.addDisplayer (&sd
);
54 logger
.addDisplayer (&fd
);
55 logger
.addDisplayer (&mbd
);
57 // so, now, if we send something on the logger, it will be displayed on the 3 displayers
58 // (stdout, file and message box)
60 // display the string with decoration.
61 // The decoration is the text that displayers add before the string.
62 // They could add the date, the process name and so on.
63 // Before each display/displayNL, you have to set the position of where the display
64 // occurs. If you don't do that, the position will not be displayed on the displayers.
65 logger
.setPosition (__LINE__
, __FILE__
);
66 logger
.display ("display using display() %d\n", 1);
68 // display the string with decoration and a new line at the end of the string.
69 logger
.setPosition (__LINE__
, __FILE__
);
70 logger
.displayNL ("display using displayNL() %d", 2);
72 // display the string without decoration.
73 logger
.displayRaw ("display using displayRaw() %d\n", 3);
75 // display the string without decoration and with a new line at the end of the string.
76 logger
.displayRawNL ("display using displayRawNL() %d", 4);
78 printf("\nPress <return> to exit\n");