zoukankan      html  css  js  c++  java
  • 当年只会C# 所以写C++就成这样了! log4cplus -> log4net

    属实C++不会。 目前帮朋友弄个小项目需要小折腾一下。

    c# 一直采用 log4net ,c++的呢,找找有个log4cplus  知识有限,做个通用类吧。别把精力放在这里。

    动手创建个静态类。 为了保持一致性,由于好几年前还有一些BCL的动态库。 所以命名规则还采用原来的风格。

    BCLLogHelper 静态类。在写项目添加静态类。直接调用就可以 (*_*) 

    头文件:

     1 // BCLSerialPort.cpp: implementation of the BCLSerialPort class.
     2 // 作者:Mark liuyunsheng
     3 //////////////////////////////////////////////////////////////////////
     4 #pragma once
     5 #include <vector>
     6 #include <memory>
     7 #include <log4cplus/logger.h>  
     8 #include <log4cplus/fileappender.h>  
     9 #include <log4cplus/layout.h>  
    10 #include <log4cplus/ndc.h>  
    11 #include <log4cplus/helpers/loglog.h>  
    12 #include <log4cplus/loggingmacros.h>  
    13  
    14 using namespace log4cplus;
    15 
    16 using namespace std;
    17 
    18 class BCLLogHelper
    19 {
    20 public:
    21     static void Init();
    22     static void Info(char* msg);
    23     static void Error(char* msg);
    24 };

    下面为类库

     1 // BCLSerialPort.cpp: implementation of the BCLSerialPort class.
     2 // 作者:Mark liuyunsheng
     3 //////////////////////////////////////////////////////////////////////
     4 #include "stdafx.h" 
     5 #include "BCLLogHelper.h" 
     6 
     7 #ifndef _DEBUG 
     8 #pragma comment(lib,"./log/log4cplus/lib/log4cplus.lib") 
     9 #else 
    10 #pragma comment(lib,"./log/log4cplus/lib/log4cplusSD.lib") 
    11 #endif 
    12 
    13 void BCLLogHelper::Init()
    14 {
    15     helpers::LogLog::getLogLog()->setInternalDebugging(true);
    16     SharedAppenderPtr append(new RollingFileAppender(LOG4CPLUS_TEXT("syslog.log"), 3 * 1024 * 1024, 5));
    17  
    18     append->setName(LOG4CPLUS_TEXT("First")); 
    19  
    20     std::auto_ptr<Layout> _layout(new PatternLayout(_T("%D{%Y-%m-%d %H:%M:%S,%q} [%t] %-5p - %m%n")));
    21     append->setLayout(_layout); 
    22     Logger::getRoot().addAppender(append);  
    23 }
    24 
    25 void BCLLogHelper::Info(char* msg)
    26 {
    27     LOG4CPLUS_INFO(Logger::getInstance(LOG4CPLUS_TEXT("System")), msg);
    28 }
    29 
    30 void BCLLogHelper::Error(char* msg)
    31 {
    32     LOG4CPLUS_ERROR(Logger::getInstance(LOG4CPLUS_TEXT("System")), msg);
    33 }

    忽然发现C++又捡起来了。 了解的深度不够。 只是能写项目。

    学好一门语言你会发现所有的开发语言都是一样的。

    目前发现C#、C++、Vb、Java、ActionScript 貌似都能写项目,仅仅是写项目级别。深度的原来了解的还不够。

    本文仅作为开发思路。不提倡。还是要专精一门开发语言的好!

  • 相关阅读:
    【HDU】2461 Rectangles
    【POJ】2409 Let it Bead
    【HDU】3208 Integer’s Power
    【HDU】1812 Count the Tetris
    【POJ】2888 Magic Bracelet
    【HDU】2865 Birthday Toy
    黑白色的华为(6) 不是银弹的银弹
    黑白色的华为(10) 不是答案的答案
    ubuntu上升级cmake到3.16版本
    黑白色的华为(8) 从加法到减法
  • 原文地址:https://www.cnblogs.com/liuyunsheng/p/6151718.html
Copyright © 2011-2022 走看看