惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - Lil-K

VM-16-pro 安装Centos Stream 9 spring-cloud-alibaba-整合spring-cloud-gateway-3.1.4 基于CentOS7.x安装Nginx-1.18.0 Nginx在Windows下的基本介绍安装以及基本使用 window7下 cmd命令行 Mysql导出表结构 + 表数据 【一】Spark基础 【二】Spark 核心 【七】ab压测 【六】tf和cgi进行联合试验,完成日志服务器 - Lil-K - 博客园 【五】安装fcig - Lil-K - 博客园 【四】搭建Nginx服务器 - Lil-K - 博客园 【三】多语言互通 - Lil-K - 博客园 【二】调通单机版的thrift-C++版本 - Lil-K - 博客园 【一】调通单机版的thrift-python版本 - Lil-K - 博客园 Spark在实际项目中分配更多资源 - Lil-K - 博客园 Spark实际项目中调节并行度 - Lil-K - 博客园 IDEA中大小写转换快捷键 使用maven下载cdh版本的大数据jar包 【Hive六】Hive调优小结 - Lil-K - 博客园
【八】将日志写入log(glog) - Lil-K - 博客园
Lil-K · 2018-08-15 · via 博客园 - Lil-K

【任务8】将日志写入log(glog)

glog简介

glog是google开源的一个日志系统,相比较log4系列的日志系统,它更加轻巧灵活,而且功能也比较完善

glog配置使用资料

下载glog

  • 命令:git clone https://github.com/google/glog.git

  • 如果没有git命令:yum -y install git

编译glog

  • 进入glog目录,打开README文件,按照其中的提示步骤进行编译:./autogen.sh && ./configure && make && make install

  • 完成后,会在/usr/local/lib路径下看到libglog*一系列库

Makefile文件和RecSys_server.skeleton.cpp文件

  • 修改之前在gen-cpp目录中的Makefile文件,在LIBS变量的末尾加上-lglog:LIBS = -L/usr/local/lib/*.so -lthrift -lfcgi -lglog

  • 修改gen-cpp目录中RecSys_server.skeleton.cpp文件:

      #include "RecSys.h"
      #include <thrift/protocol/TBinaryProtocol.h>
      #include <thrift/server/TSimpleServer.h>
      #include <thrift/transport/TServerSocket.h>
      #include <thrift/transport/TBufferTransports.h>
    
      //添加头文件
      #include <glog/logging.h>
    
      using namespace ::apache::thrift;
      using namespace ::apache::thrift::protocol;
      using namespace ::apache::thrift::transport;
      using namespace ::apache::thrift::server;
    
      using boost::shared_ptr;
    
      class RecSysHandler : virtual public RecSysIf {
      public:
          RecSysHandler() {
              // Your initialization goes here
          }
    
          void rec_data(std::string& _return, const std::string& data) {
              // Your implementation goes here
              printf("=======================\n");
              std::cout << "receive client data:" << data << std::endl;
              
              std::string ack = "yeah,I love you too!!";
              
              //log输出,使用时按情况选择
              LOG(INFO) << data;
              LOG(ERROR) << data;
              LOG(WARNING) << data;
    
              _return = ack;
          }
    
          };
    
          int main(int argc, char **argv) {
          
          google::InitGoogleLogging(argv[0]);	
    
          int port = 9090;
          shared_ptr<RecSysHandler> handler(new RecSysHandler());
          shared_ptr<TProcessor> processor(new RecSysProcessor(handler));
          shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
          shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
          shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
    
          TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
          server.serve();
          return 0;
      }
    

重新编译client端和server端

  • kill掉之前的client和server,在make相应的client和server

  • 再次启动server端和client,命令:./server,/usr/local/src/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 8088 -f /test/thrift_test/python_thrift_demo/gen-cpp/client

  • 同上操作,用浏览器的方式访问,server端会打印出log,并产生log日志文件,默认路径:/tmp/下的server.ERROR,server.INFO,server.WARNING

  • 更改glog产生log日志文件的路径,在gen-cpp目录下的RecSys_server.skeleton.cpp文件中的int main()方法中添加代码,添加glog输出地址:

int main(int argc, char **argv) {

//glog地址
FLAGS_log_dir = "/test/thrift_test/python_thrift_demo/gen-cpp/logs"
google::InitGoogleLogging(argv[0]);	

int port = 9090;
shared_ptr<RecSysHandler> handler(new RecSysHandler());
shared_ptr<TProcessor> processor(new RecSysProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}

其中logs目录需要自行创建

  • 然后执行make命令,重新生成client端和server