Torque3D Documentation / _generateds / consoleLogger.h

consoleLogger.h

Engine/source/console/consoleLogger.h

More...

Classes:

class

A class designed to be used as a console consumer and log the data it receives to a file.

Public User Defined

Detailed Description

Public User Defined

DefineEnumType(LogLevel )

typedef ConsoleLogEntry::Level LogLevel 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _CONSOLE_LOGGER_H_
 25#define _CONSOLE_LOGGER_H_
 26
 27#ifndef _SIMOBJECT_H_
 28   #include "console/simObject.h"
 29#endif
 30#ifndef _CONSOLE_H_
 31   #include "console/console.h"
 32#endif
 33#ifndef _FILESTREAM_H_
 34   #include "core/stream/fileStream.h"
 35#endif
 36
 37
 38/// @ingroup console_system Console System
 39/// @{
 40
 41typedef ConsoleLogEntry::Level LogLevel;
 42DefineEnumType( LogLevel );
 43
 44/// A class designed to be used as a console consumer and log
 45/// the data it receives to a file.
 46class ConsoleLogger : public SimObject
 47{
 48   typedef SimObject Parent;
 49
 50   private:
 51   
 52      bool mLogging;                   ///< True if it is currently consuming and logging
 53      FileStream mStream;              ///< File stream this object writes to
 54      static bool smInitialized;                ///< This is for use with the default constructor
 55      bool mAppend;                    ///< If false, it will clear the file before logging to it.
 56      StringTableEntry mFilename;      ///< The file name to log to.
 57
 58      /// List of active ConsoleLoggers to send log messages to
 59      static Vector<ConsoleLogger*> mActiveLoggers;
 60
 61      /// The log function called by the consumer callback
 62      /// @param   consoleLine   Line of text to log
 63      void log( const char *consoleLine );
 64
 65      /// Utility function, sets up the object (for script interface) returns true if successful
 66      bool init();
 67
 68   public:
 69
 70      // @name Public console variables
 71      /// @{
 72      ConsoleLogEntry::Level mLevel;   ///< The level of log messages to log
 73      /// @}
 74
 75      DECLARE_CONOBJECT( ConsoleLogger );
 76
 77      static void initPersistFields();
 78
 79      /// Console constructor
 80      ///
 81      /// @code
 82      /// // Example script constructor usage.
 83      /// %obj = new ConsoleLogger( objName, logFileName, [append = false] );
 84      /// @endcode
 85      bool processArguments( S32 argc, ConsoleValueRef *argv );
 86
 87      /// Default constructor, make sure to initalize
 88      ConsoleLogger();
 89
 90      /// Constructor
 91      /// @param   fileName   File name to log to
 92      /// @param   append     If false, it will clear the file, then start logging, else it will append
 93      ConsoleLogger( const char *fileName, bool append = false );
 94
 95      /// Destructor
 96      ~ConsoleLogger();
 97
 98      /// Attach to the console and begin logging
 99      ///
100      /// Returns true if the action is successful
101      bool attach();
102
103      /// Detach from the console and stop logging
104      ///
105      /// Returns true if the action is successful
106      bool detach();
107
108      /// Sets the level of console messages to log.
109      ///
110      /// @param   level   Log level. Only items of the specified level or
111      ///                  lower are logged.
112      /// @see ConsoleLogEntry::Level
113      void setLogLevel( ConsoleLogEntry::Level level );
114
115      /// Returns the level of console messages to log
116      ConsoleLogEntry::Level getLogLevel() const;
117
118      /// The callback for the console consumer
119      ///
120      /// @note This is a global callback, not executed per-instance.
121      /// @see Con::addConsumer
122      static void logCallback( U32 level, const char *consoleLine );
123};
124
125/// @}
126
127#endif // _CONSOLE_LOGGER_H_
128