MongoDB  2.0.3
ramlog.h
00001 // ramlog.h
00002 
00003 /*    Copyright 2009 10gen Inc.
00004  *
00005  *    Licensed under the Apache License, Version 2.0 (the "License");
00006  *    you may not use this file except in compliance with the License.
00007  *    You may obtain a copy of the License at
00008  *
00009  *    http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  *    Unless required by applicable law or agreed to in writing, software
00012  *    distributed under the License is distributed on an "AS IS" BASIS,
00013  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *    See the License for the specific language governing permissions and
00015  *    limitations under the License.
00016  */
00017 
00018 #pragma once
00019 
00020 #include "log.h"
00021 
00022 namespace mongo {
00023 
00024     class RamLog : public Tee {
00025     public:
00026         RamLog( string name );
00027 
00028         virtual void write(LogLevel ll, const string& str);
00029 
00030         void get( vector<const char*>& v) const;
00031 
00032         void toHTML(stringstream& s);
00033 
00034         static RamLog* get( string name );
00035         static void getNames( vector<string>& names );
00036 
00037         time_t lastWrite() { return _lastWrite; } // 0 if no writes
00038 
00039     protected:
00040         static int repeats(const vector<const char *>& v, int i);
00041         static string clean(const vector<const char *>& v, int i, string line="");
00042         static string color(string line);
00043 
00044         /* turn http:... into an anchor */
00045         static string linkify(const char *s);
00046 
00047     private:
00048         ~RamLog(); // want this private as we want to leak so we can use them till the very end
00049 
00050         enum {
00051             N = 128, // number of links
00052             C = 256 // max size of line
00053         };
00054         char lines[N][C];
00055         unsigned h; // current position
00056         unsigned n; // numer of lines stores 0 o N
00057         string _name;
00058 
00059         typedef map<string,RamLog*> RM;
00060         static mongo::mutex* _namedLock;
00061         static RM*  _named;
00062         time_t _lastWrite;
00063     };
00064 
00065 }