PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/lllog.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 111 lines | 67 code | 15 blank | 29 comment | 7 complexity | 10b9d7048d5ce255f9fe8dad6e01333d MD5 | raw file
  1/** 
  2 * @file lllog.cpp
  3 * @author Don
  4 * @date 2007-11-27
  5 * @brief  Class to log messages to syslog for streambase to process.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "lllog.h"
 31
 32#include "llapp.h"
 33#include "llsd.h"
 34#include "llsdserialize.h"
 35
 36
 37class LLLogImpl
 38{
 39public:
 40	LLLogImpl(LLApp* app) : mApp(app) {}
 41	~LLLogImpl() {}
 42
 43	void log(const std::string &message, LLSD& info);
 44	bool useLegacyLogMessage(const std::string &message);
 45
 46private:
 47	LLApp* mApp;
 48};
 49
 50
 51//@brief Function to log a message to syslog for streambase to collect.
 52void LLLogImpl::log(const std::string &message, LLSD& info)
 53{
 54	static S32 sequence = 0;
 55    LLSD log_config = mApp->getOption("log-messages");
 56	if (log_config.has(message))
 57	{
 58		LLSD message_config = log_config[message];
 59		if (message_config.has("use-syslog"))
 60		{
 61			if (! message_config["use-syslog"].asBoolean())
 62			{
 63				return;
 64			}
 65		}
 66	}
 67	llinfos << "LLLOGMESSAGE (" << (sequence++) << ") " << message 
 68		<< " " << LLSDNotationStreamer(info) << llendl;
 69}
 70
 71//@brief Function to check if specified legacy log message should be sent.
 72bool LLLogImpl::useLegacyLogMessage(const std::string &message)
 73{
 74    LLSD log_config = mApp->getOption("log-messages");
 75	if (log_config.has(message))
 76	{
 77		LLSD message_config = log_config[message];
 78		if (message_config.has("use-legacy"))
 79		{
 80			return message_config["use-legacy"].asBoolean();
 81		}
 82	}
 83	return true;
 84}
 85
 86
 87LLLog::LLLog(LLApp* app)
 88{
 89	mImpl = new LLLogImpl(app);
 90}
 91
 92LLLog::~LLLog()
 93{
 94	delete mImpl;
 95	mImpl = NULL;
 96}
 97
 98void LLLog::log(const std::string &message, LLSD& info)
 99{
100	if (mImpl) mImpl->log(message, info);
101}
102
103bool LLLog::useLegacyLogMessage(const std::string &message)
104{
105	if (mImpl)
106	{
107		return mImpl->useLegacyLogMessage(message);
108	}
109	return true;
110}
111