Line data Source code
1 : //# SLog.cc:
2 : //# Copyright (C) 2007
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be addressed as follows:
20 : //# Internet email: aips2-request@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //#
27 : //#
28 : //# -------------------------------------------------------------------------
29 :
30 :
31 : #include <flagging/Flagging/SLog.h>
32 :
33 : #define LOGLEVEL 3
34 : //debuglevel{DEBUGGING, DEBUG2, DEBUG1, NORMAL5, ..., WARN, SEVERE}
35 : // loglevel{LOG0, LOG1, LOG2, LOG3, ..., LOG9, LOG10}
36 : //set LOGLEVEL to 3 to filter out all debug message
37 :
38 : using namespace casacore;
39 : namespace casa {
40 :
41 : SLog* SLog::instance = 0;
42 : //uInt SLog::refCount = 0;
43 :
44 668 : SLog* SLog::slog() {
45 668 : if (!instance) {
46 1 : instance = new SLog();
47 : }
48 : //refCount++;
49 : //cout << "slog::refCount=" << refCount << endl;
50 668 : return instance;
51 : }
52 :
53 0 : SLog::~SLog() {
54 0 : out("destroy logger");
55 :
56 : //generally speaking, there is no need to destruct
57 : //SLog because it has at most 1 real object, others
58 : //are just pointers. The real log object will be
59 : //removed when the whole process is done.
60 : //cout << "----------------- destroy slog---------" << endl;
61 : //delete instance;
62 : //instance = 0;
63 : //this destruct never get called anyway
64 :
65 0 : }
66 :
67 1 : SLog::SLog() {
68 1 : out("create logger");
69 1 : }
70 :
71 0 : void SLog::FnEnter(String fnname, String clname) {
72 0 : out("---->> Enter", fnname, clname, LogMessage::DEBUG1);
73 0 : }
74 :
75 0 : void SLog::FnExit(String fnname, String clname) {
76 0 : out("<<---- Exit", fnname, clname, LogMessage::DEBUG1);
77 0 : }
78 :
79 0 : void SLog::FnPass(String fnname, String clname) {
80 0 : out("-- Pass --", fnname, clname, LogMessage::DEBUG1);
81 0 : }
82 :
83 347 : void SLog::out(const String &msg, const String& /*fnname*/,
84 : const String& /*clname*/,
85 : LogMessage::Priority msglevel,
86 : Bool onconsole) {
87 347 : if (msglevel >= LOGLEVEL) {
88 346 : priority(msglevel);
89 346 : output() << (const char *)msg.c_str();
90 346 : post();
91 346 : if (onconsole) {
92 0 : cout << LogMessage::toString(msglevel)
93 : // << " from " << clname << "::" << fnname
94 : // << " ==>> "
95 0 : << " " << msg << endl;
96 : }
97 : }
98 347 : }
99 :
100 : };
101 :
|