Blame view

trunk/src/app/srs_app_log.hpp 2.5 KB
winlin authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
The MIT License (MIT)

Copyright (c) 2013-2014 winlin

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
24 25
#ifndef SRS_APP_LOG_HPP
#define SRS_APP_LOG_HPP
winlin authored
26 27

/*
28
#include <srs_app_log.hpp>
winlin authored
29 30 31 32
*/

#include <srs_core.hpp>
33
#include <srs_app_st.hpp>
winlin authored
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <srs_kernel_log.hpp>

#include <string.h>

#include <string>
#include <map>

/**
* st thread context, get_id will get the st-thread id, 
* which identify the client.
*/
class SrsThreadContext : public ISrsThreadContext
{
private:
    std::map<st_thread_t, int> cache;
public:
    SrsThreadContext();
    virtual ~SrsThreadContext();
public:
    virtual void generate_id();
    virtual int get_id();
};

/**
* we use memory/disk cache and donot flush when write log.
*/
class SrsFastLog : public ISrsLog
{
private:
    // defined in SrsLogLevel.
64
    int _level;
winlin authored
65
    char* log_data;
66 67
    // log to file if specified srs_log_file
    int fd;
winlin authored
68 69 70 71
public:
    SrsFastLog();
    virtual ~SrsFastLog();
public:
72 73
    virtual int level();
    virtual void set_level(int level);
winlin authored
74 75 76 77 78 79 80
    virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
    virtual void info(const char* tag, int context_id, const char* fmt, ...);
    virtual void trace(const char* tag, int context_id, const char* fmt, ...);
    virtual void warn(const char* tag, int context_id, const char* fmt, ...);
    virtual void error(const char* tag, int context_id, const char* fmt, ...);
private:
    virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size);
81
    static void write_log(int& fd, char* str_log, int size, int level);
winlin authored
82 83 84
};

#endif