Blame view

trunk/src/app/srs_app_log.hpp 2.8 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
#include <srs_kernel_log.hpp>
35
#include <srs_app_reload.hpp>
winlin authored
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

#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.
*/
61
class SrsFastLog : public ISrsLog, public ISrsReloadHandler
winlin authored
62 63 64
{
private:
    // defined in SrsLogLevel.
65
    int _level;
winlin authored
66
    char* log_data;
67 68
    // log to file if specified srs_log_file
    int fd;
69 70
    // whether log to file tank
    bool log_to_file_tank;
winlin authored
71 72 73 74
public:
    SrsFastLog();
    virtual ~SrsFastLog();
public:
75
    virtual int initialize();
winlin authored
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, ...);
81 82 83 84 85
// interface ISrsThreadHandler.
public:
    virtual int on_reload_log_tank();
    virtual int on_reload_log_level();
    virtual int on_reload_log_file();
winlin authored
86 87
private:
    virtual bool generate_header(const char* tag, int context_id, const char* level_name, int* header_size);
88 89
    virtual void write_log(int& fd, char* str_log, int size, int level);
    virtual void open_log_file();
winlin authored
90 91 92
};

#endif