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/>.
19 #include "nel/net/net_displayer.h"
20 #include "nel/net/message.h"
21 #include "nel/net/naming_client.h"
25 using namespace NLMISC
;
30 /* This index must correspond to the index for "LOG" in CallbackArray in the Logging Service
31 * (see CNetDisplayer::display())
33 const sint16 LOG_CBINDEX
= 0;
39 CNetDisplayer::CNetDisplayer(bool autoConnect
) :
40 _Server(NULL
), _ServerAllocated (false) // disable logging otherwise an infinite recursion may occur
42 if (autoConnect
) findAndConnect();
47 * Find the server (using the NS) and connect
49 void CNetDisplayer::findAndConnect()
53 _Server
= new CCallbackClient();
54 _ServerAllocated
= true;
57 if ( CNamingClient::lookupAndConnect( "LOGS", *_Server
) )
59 nldebug( "Connected to logging service" );
64 * Sets logging server address
66 void CNetDisplayer::setLogServer (const CInetAddress
& logServerAddr
)
68 if (_Server
!= NULL
&& _Server
->connected()) return;
70 _ServerAddr
= logServerAddr
;
74 _Server
= new CCallbackClient();
75 _ServerAllocated
= true;
80 _Server
->connect (_ServerAddr
);
88 void CNetDisplayer::setLogServer (CCallbackClient
*server
)
90 if (_Server
!= NULL
&& _Server
->connected()) return;
99 CNetDisplayer::~CNetDisplayer ()
101 if (_ServerAllocated
)
103 _Server
->disconnect ();
110 * Sends the string to the logging server
112 * Log format: "2000/01/15 12:05:30 <LogType> <ProcessName>: <Msg>"
114 void CNetDisplayer::doDisplay ( const CLog::TDisplayInfo
& args
, const char *message
)
118 if (_Server
== NULL
|| !_Server
->connected())
123 bool needSpace
= false;
129 str
+= dateToHumanString(args
.Date
);
133 if (args
.LogType
!= CLog::LOG_NO
)
135 if (needSpace
) { str
+= " "; needSpace
= false; }
136 str
+= logTypeToString(args
.LogType
);
140 if (!args
.ProcessName
.empty())
142 if (needSpace
) { str
+= " "; needSpace
= false; }
143 str
+= args
.ProcessName
;
147 if (needSpace
) { str
+= ": "; needSpace
= false; }
151 CMessage
msg("LOG" );
154 _Server
->send (msg
, 0, false);
156 catch(const NLMISC::Exception
& )