video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-26 1f005df2f3ff78458f332f9bf1cf2e78b6a8e8e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "log.hpp"
 
#include <string>
#include <vector>
#include <memory>
#include <unistd.h>
#include <sys/stat.h>
 
#include <stdio.h>
#include <stdarg.h>
 
#include "../../thirdparty/spdlog/spdlog.h"
 
namespace logif{
 
    static bool log_run = false;
 
    static const char log_name[] = "business_log";
 
    const static int kRotateLogFileSize = 1048576 * 5;
    const static int kRotateLogFileCount = 3;
 
    static void rotateLog(const char *file_name, const int file_size, 
                const int file_count, const bool show_stdout){
 
        std::vector<spdlog::sink_ptr> sinks;  
        if(show_stdout){
            sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());  
        }
        sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(file_name, file_size, file_count));
        auto m_logger = std::make_shared<spdlog::logger>(log_name, begin(sinks), end(sinks));  
        m_logger->set_pattern("[%Y-%m-%d %H:%M:%S] %v");  
        spdlog::register_logger(m_logger);
    }
 
    static std::string makeTimeStamp(){
        time_t now;
        struct tm *now_time;
        time(&now);
        now_time = localtime(&now);
 
        char filename[64];
        snprintf(filename, 64, "%d%02d%02d%02d%02d%02d",
            now_time->tm_year+1900, now_time->tm_mon+1,
            now_time->tm_mday, now_time->tm_hour, 
            now_time->tm_min,now_time->tm_sec);
        return filename;
    }
 
    void CreateLogger(const char *dir, const char *name, 
                        const bool show_stdout){
 
        std::string str_dir(dir);
        std::string file_name(name);
 
 
        std::string logfile(str_dir + "/" + 
            file_name + "-" +
            makeTimeStamp() +
            ".tlog");
        
        CreateLogger(logfile.c_str(), show_stdout);
    }
 
    void CreateLogger(const char *name, const bool show_stdout){
 
        rotateLog(name, kRotateLogFileSize, kRotateLogFileCount, show_stdout);
 
        log_run = true;
    }
 
    void DestroyLogger(){
        if (log_run)
            spdlog::drop_all();
    }
 
    void logIt(const char *fmt, ...){
 
        char temp[512];
 
        va_list args;       //定义一个va_list类型的变量,用来储存单个参数  
        va_start(args,fmt); //使args指向可变参数的第一个参数  
        vsnprintf(temp, 512, fmt, args);  //必须用vprintf等带V的  
        va_end(args);       //结束可变参数的获取  
 
        if(log_run){
            std::string lc(temp);
            lc = "LIB-libcffmpeg.so-> " + lc;
            spdlog::get(log_name)->error(lc);
            spdlog::get(log_name)->flush();
        }else{
            printf("%s\n", temp);
        }
 
    }
 
}