PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llcommon/llerrorcontrol.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 176 lines | 67 code | 37 blank | 72 comment | 0 complexity | 2e55a2d9e11c56c2d90b08e8fc4bb2f9 MD5 | raw file
  1/** 
  2 * @file llerrorcontrol.h
  3 * @date   December 2006
  4 * @brief error message system control
  5 *
  6 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLERRORCONTROL_H
 29#define LL_LLERRORCONTROL_H
 30
 31#include "llerror.h"
 32#include "boost/function.hpp"
 33#include <string>
 34
 35class LLSD;
 36
 37/*
 38	This is the part of the LLError namespace that manages the messages
 39	produced by the logging.  The logging support is defined in llerror.h.
 40	Most files do not need to include this.
 41	
 42	These implementations are in llerror.cpp.
 43*/
 44
 45// Line buffer interface
 46class LLLineBuffer
 47{
 48public:
 49	LLLineBuffer() {};
 50	virtual ~LLLineBuffer() {};
 51
 52	virtual void clear() = 0; // Clear the buffer, and reset it.
 53
 54	virtual void addLine(const std::string& utf8line) = 0;
 55};
 56
 57
 58namespace LLError
 59{
 60	LL_COMMON_API void initForServer(const std::string& identity);
 61		// resets all logging settings to defaults needed by server processes
 62		// logs to stderr, syslog, and windows debug log
 63		// the identity string is used for in the syslog
 64
 65	LL_COMMON_API void initForApplication(const std::string& dir);
 66		// resets all logging settings to defaults needed by applicaitons
 67		// logs to stderr and windows debug log
 68		// sets up log configuration from the file logcontrol.xml in dir
 69
 70
 71	/*
 72		Settings that control what is logged.
 73		Setting a level means log messages at that level or above.
 74	*/
 75	
 76	LL_COMMON_API void setPrintLocation(bool);
 77	LL_COMMON_API void setDefaultLevel(LLError::ELevel);
 78	LL_COMMON_API ELevel getDefaultLevel();
 79	LL_COMMON_API void setFunctionLevel(const std::string& function_name, LLError::ELevel);
 80	LL_COMMON_API void setClassLevel(const std::string& class_name, LLError::ELevel);
 81	LL_COMMON_API void setFileLevel(const std::string& file_name, LLError::ELevel);
 82	LL_COMMON_API void setTagLevel(const std::string& file_name, LLError::ELevel);
 83	
 84	LL_COMMON_API void configure(const LLSD&);
 85		// the LLSD can configure all of the settings
 86		// usually read automatically from the live errorlog.xml file
 87
 88
 89	/*
 90		Control functions.
 91	*/
 92
 93	typedef boost::function<void(const std::string&)> FatalFunction;
 94	LL_COMMON_API void crashAndLoop(const std::string& message);
 95		// Default fatal function: access null pointer and loops forever
 96
 97	LL_COMMON_API void setFatalFunction(const FatalFunction&);
 98		// The fatal function will be called when an message of LEVEL_ERROR
 99		// is logged.  Note: supressing a LEVEL_ERROR message from being logged
100		// (by, for example, setting a class level to LEVEL_NONE), will keep
101		// the that message from causing the fatal funciton to be invoked.
102
103    LL_COMMON_API FatalFunction getFatalFunction();
104        // Retrieve the previously-set FatalFunction
105
106    /// temporarily override the FatalFunction for the duration of a
107    /// particular scope, e.g. for unit tests
108    class LL_COMMON_API OverrideFatalFunction
109    {
110    public:
111        OverrideFatalFunction(const FatalFunction& func):
112            mPrev(getFatalFunction())
113        {
114            setFatalFunction(func);
115        }
116        ~OverrideFatalFunction()
117        {
118            setFatalFunction(mPrev);
119        }
120
121    private:
122        FatalFunction mPrev;
123    };
124
125	typedef std::string (*TimeFunction)();
126	LL_COMMON_API std::string utcTime();
127	
128	LL_COMMON_API void setTimeFunction(TimeFunction);
129		// The function is use to return the current time, formatted for
130		// display by those error recorders that want the time included.
131
132
133
134	class LL_COMMON_API Recorder
135	{
136		// An object that handles the actual output or error messages.
137	public:
138		virtual ~Recorder();
139		
140		virtual void recordMessage(LLError::ELevel, const std::string& message) = 0;
141			// use the level for better display, not for filtering
142			
143		virtual bool wantsTime(); // default returns false
144			// override and return true if the recorder wants the time string
145			// included in the text of the message
146	};
147	
148	LL_COMMON_API void addRecorder(Recorder*);
149	LL_COMMON_API void removeRecorder(Recorder*);
150		// each error message is passed to each recorder via recordMessage()
151	
152	LL_COMMON_API void logToFile(const std::string& filename);
153	LL_COMMON_API void logToFixedBuffer(LLLineBuffer*);
154		// Utilities to add recorders for logging to a file or a fixed buffer
155		// A second call to the same function will remove the logger added
156		// with the first.
157		// Passing the empty string or NULL to just removes any prior.
158	LL_COMMON_API std::string logFileName();
159		// returns name of current logging file, empty string if none
160
161
162	/*
163		Utilities for use by the unit tests of LLError itself.
164	*/
165
166	class Settings;
167	LL_COMMON_API Settings* saveAndResetSettings();
168	LL_COMMON_API void restoreSettings(Settings *);
169		
170	LL_COMMON_API std::string abbreviateFile(const std::string& filePath);
171	LL_COMMON_API int shouldLogCallCount();
172	
173};
174
175#endif // LL_LLERRORCONTROL_H
176