Torque3D Documentation / _generateds / consoleLogger.cpp

consoleLogger.cpp

Engine/source/console/consoleLogger.cpp

More...

Public Variables

Public Functions

ConsoleDocClass(ConsoleLogger , "A class designed <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> console consumer and log the data it receives <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dumpConsoleFunctions\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dumpConsoleClasses\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Logging\n</a>" )
DefineEngineMethod(ConsoleLogger , attach , bool , () , "() Attaches the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console and begins writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "// Will automatically start writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> testLogging.txt with normal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">priority\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classconsolelogger/">ConsoleLogger</a>(logger, \"testLogging.txt\", false);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Send something <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console, with the logger consumes and writes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Stop logging, but do not delete the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "logger.detach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is not logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Attach the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again\n</a>" "logger.attach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Logging has <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resumed\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"Logging has resumed\");" "@endtsexample\n\n" )
DefineEngineMethod(ConsoleLogger , detach , bool , () , "() Detaches the logger from the console and stops writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "// Will automatically start writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> testLogging.txt with normal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">priority\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classconsolelogger/">ConsoleLogger</a>(logger, \"testLogging.txt\", false);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Send something <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console, with the logger consumes and writes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Stop logging, but do not delete the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "logger.detach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is not logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Attach the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again\n</a>" "logger.attach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Logging has <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resumed\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"Logging has resumed\");" "@endtsexample\n\n" )
ImplementEnumType(LogLevel , "@brief Priority levels <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> logging <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">entries\n\n</a>" "@ingroup Logging" )

Detailed Description

Public Variables

 EndImplementEnumType 

Public Functions

ConsoleDocClass(ConsoleLogger , "A class designed <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> be used as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> console consumer and log the data it receives <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dumpConsoleFunctions\n</a>" "@see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">dumpConsoleClasses\n</a>" "@ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Logging\n</a>" )

DefineEngineMethod(ConsoleLogger , attach , bool , () , "() Attaches the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console and begins writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "// Will automatically start writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> testLogging.txt with normal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">priority\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classconsolelogger/">ConsoleLogger</a>(logger, \"testLogging.txt\", false);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Send something <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console, with the logger consumes and writes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Stop logging, but do not delete the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "logger.detach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is not logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Attach the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again\n</a>" "logger.attach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Logging has <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resumed\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"Logging has resumed\");" "@endtsexample\n\n" )

DefineEngineMethod(ConsoleLogger , detach , bool , () , "() Detaches the logger from the console and stops writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a702945180aa732857b380a007a7e2a21">file</a>" "@<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">tsexample\n</a>" "// Create the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "// Will automatically start writing <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> testLogging.txt with normal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">priority\n</a>" "<a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> <a href="/coding/class/classconsolelogger/">ConsoleLogger</a>(logger, \"testLogging.txt\", false);\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Send something <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console, with the logger consumes and writes <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Stop logging, but do not delete the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">logger\n</a>" "logger.detach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"This is not logged <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the file\");\n\n" "// Attach the logger <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> the console <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">again\n</a>" "logger.attach();\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "// Logging has <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">resumed\n</a>" "<a href="/coding/file/ggendoflinefix_8txt/#ggendoflinefix_8txt_1a7f8fee038817022b75b8865e5da4eba3">echo</a>(\"Logging has resumed\");" "@endtsexample\n\n" )

IMPLEMENT_CONOBJECT(ConsoleLogger )

ImplementEnumType(LogLevel , "@brief Priority levels <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> logging <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">entries\n\n</a>" "@ingroup Logging" )

  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#include "console/consoleLogger.h"
 24#include "console/consoleTypes.h"
 25#include "console/engineAPI.h"
 26
 27Vector<ConsoleLogger*> ConsoleLogger::mActiveLoggers;
 28bool ConsoleLogger::smInitialized = false;
 29
 30IMPLEMENT_CONOBJECT( ConsoleLogger );
 31ConsoleDocClass( ConsoleLogger,
 32   "A class designed to be used as a console consumer and log the data it receives to a file.\n\n"
 33   
 34   "@see dumpConsoleFunctions\n"
 35   "@see dumpConsoleClasses\n"
 36   "@ingroup Logging\n"
 37);
 38//-----------------------------------------------------------------------------
 39
 40ConsoleLogger::ConsoleLogger()
 41{
 42   mFilename = NULL;
 43   mLogging = false;
 44   mAppend = false;
 45
 46   mLevel = ConsoleLogEntry::Normal;
 47}
 48
 49//-----------------------------------------------------------------------------
 50
 51ConsoleLogger::ConsoleLogger( const char *fileName, bool append )
 52{
 53   mLogging = false;
 54
 55   mLevel = ConsoleLogEntry::Normal;
 56   mFilename = StringTable->insert( fileName );
 57   mAppend = append;
 58
 59   init();
 60}
 61
 62//-----------------------------------------------------------------------------
 63
 64ImplementEnumType( LogLevel,
 65   "@brief Priority levels for logging entries\n\n" 
 66   "@ingroup Logging")
 67   { ConsoleLogEntry::Normal,     "normal", "Lowest priority level, no highlighting."  },
 68   { ConsoleLogEntry::Warning,    "warning", "Mid level priority, tags and highlights possible issues in blue." },
 69   { ConsoleLogEntry::Error,      "error",  "Highest priority level, extreme emphasis on this entry. Highlighted in red." },
 70EndImplementEnumType;
 71
 72void ConsoleLogger::initPersistFields()
 73{
 74   addGroup( "Logging" );
 75   addField( "level",   TYPEID< ConsoleLogEntry::Level >(),     Offset( mLevel,    ConsoleLogger ), "Determines the priority level and attention the logged entry gets when recorded\n\n" );
 76   endGroup( "Logging" );
 77
 78   Parent::initPersistFields();
 79}
 80
 81//-----------------------------------------------------------------------------
 82
 83bool ConsoleLogger::processArguments( S32 argc, ConsoleValueRef *argv )
 84{
 85   if( argc == 0 )
 86      return false;
 87
 88   bool append = false;
 89
 90   if( argc == 2 )
 91      append = dAtob( argv[1] );
 92
 93   mAppend = append;
 94   mFilename = StringTable->insert( argv[0] );
 95
 96   if( init() )
 97   {
 98      attach();
 99      return true;
100   }
101
102   return false;
103}
104
105//-----------------------------------------------------------------------------
106
107ConsoleLogger::~ConsoleLogger()
108{
109   detach();
110}
111
112//-----------------------------------------------------------------------------
113
114bool ConsoleLogger::init()
115{
116   if( smInitialized )
117      return true;
118
119   Con::addConsumer( ConsoleLogger::logCallback );
120   smInitialized = true;
121
122   return true;
123}
124
125//-----------------------------------------------------------------------------
126
127bool ConsoleLogger::attach()
128{
129   if( mFilename == NULL )
130   {
131      Con::errorf( "ConsoleLogger failed to attach: no filename supplied." );
132      return false;
133   }
134
135   // Check to see if this is initialized before using it
136   if( !smInitialized )
137   {
138      if( !init() )
139      {
140         Con::errorf( "ConsoleLogger failed to initalize." );
141         return false;
142      }
143   }
144
145   if( mLogging )
146      return false;
147
148   // Open the filestream
149   mStream.open( mFilename, ( mAppend ? Torque::FS::File::WriteAppend : Torque::FS::File::Write ) );
150
151   // Add this to list of active loggers
152   mActiveLoggers.push_back( this );
153   mLogging = true;
154
155   return true;
156}
157
158//-----------------------------------------------------------------------------
159
160bool ConsoleLogger::detach()
161{
162
163   // Make sure this is valid before messing with it
164   if( !smInitialized ) 
165   {
166      if( !init() ) 
167      {
168         return false;
169      }
170   }
171
172   if( !mLogging )
173      return false;
174
175   // Close filestream
176   mStream.close();
177
178   // Remove this object from the list of active loggers
179   for( S32 i = 0; i < mActiveLoggers.size(); i++ ) 
180   {
181      if( mActiveLoggers[i] == this ) 
182      {
183         mActiveLoggers.erase( i );
184         mLogging = false;
185         return true;
186      }
187   }
188
189   return false; // If this happens, it's bad...
190}
191
192//-----------------------------------------------------------------------------
193
194void ConsoleLogger::logCallback( U32 level, const char *consoleLine )
195{
196
197   ConsoleLogger *curr;
198
199   // Loop through active consumers and send them the message
200   for( int i = 0; i < mActiveLoggers.size(); i++ ) 
201   {
202      curr = mActiveLoggers[i];
203
204      // If the log level is within the log threshhold, log it
205      if( curr->mLevel <= level )
206         curr->log( consoleLine );
207   }
208}
209
210//-----------------------------------------------------------------------------
211
212void ConsoleLogger::log( const char *consoleLine )
213{
214   // Check to see if this is intalized before using it
215   if( !smInitialized ) 
216   {
217      if( !init() ) 
218      {
219         Con::errorf( "I don't know how this happened, but log called on this without it being initialized" );
220         return;
221      }
222   }
223
224   mStream.writeLine( (U8 *)consoleLine );
225}
226
227//-----------------------------------------------------------------------------
228
229DefineEngineMethod( ConsoleLogger, attach, bool, (), , "() Attaches the logger to the console and begins writing to file"
230           "@tsexample\n"
231           "// Create the logger\n"
232           "// Will automatically start writing to testLogging.txt with normal priority\n"
233           "new ConsoleLogger(logger, \"testLogging.txt\", false);\n\n"
234           "// Send something to the console, with the logger consumes and writes to file\n"
235           "echo(\"This is logged to the file\");\n\n"
236           "// Stop logging, but do not delete the logger\n"
237           "logger.detach();\n\n"
238           "echo(\"This is not logged to the file\");\n\n"
239           "// Attach the logger to the console again\n"
240           "logger.attach();\n\n"
241           "// Logging has resumed\n"
242           "echo(\"Logging has resumed\");"
243           "@endtsexample\n\n")
244{
245   ConsoleLogger *logger = static_cast<ConsoleLogger *>( object );
246   return logger->attach();
247}
248
249//-----------------------------------------------------------------------------
250
251DefineEngineMethod( ConsoleLogger, detach, bool, (), , "() Detaches the logger from the console and stops writing to file"
252           "@tsexample\n"
253           "// Create the logger\n"
254           "// Will automatically start writing to testLogging.txt with normal priority\n"
255           "new ConsoleLogger(logger, \"testLogging.txt\", false);\n\n"
256           "// Send something to the console, with the logger consumes and writes to file\n"
257           "echo(\"This is logged to the file\");\n\n"
258           "// Stop logging, but do not delete the logger\n"
259           "logger.detach();\n\n"
260           "echo(\"This is not logged to the file\");\n\n"
261           "// Attach the logger to the console again\n"
262           "logger.attach();\n\n"
263           "// Logging has resumed\n"
264           "echo(\"Logging has resumed\");"
265           "@endtsexample\n\n")
266{
267   ConsoleLogger *logger = static_cast<ConsoleLogger *>( object );
268   return logger->detach();
269}
270