---
title: "simple_log 一个轻量的c++日志组件"
author: "finallygo"
date: "2014-10-25T16:13:36Z"
tags: []
categories: ["开源软件"]
slug: "simple-log-c"
draft: false
lastmod: "2014-10-29T11:25:47Z"
id: 2147885
url: "https://finallygo.iteye.com/blog/2147885"
---

## 特点

- 简洁但是功能实用
- 只支持linux
- 线程不安全

## [](https://github.com/hongliuliao/simple_log#%E5%8A%9F%E8%83%BD%E5%88%97%E8%A1%A8)功能列表

- 支持动态加载配置文件,修改日志等级
- 支持使用脚本进行日志文件的切分

## [](https://github.com/hongliuliao/simple_log#%E6%80%A7%E8%83%BD)性能

- 10万/s 日志写入

## [](https://github.com/hongliuliao/simple_log#%E6%9E%84%E5%BB%BA--%E6%B5%8B%E8%AF%95)构建 && 测试

```
  make && make test
```

## [](https://github.com/hongliuliao/simple_log#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%8F%AF%E9%80%89)配置文件(可选)

- 默认会找conf/simple\_log.conf,如果没有找到,会将日志以debug级别输出到控制台
- 如果配置了log\_file,需要保证log目录已经存在

```
 log_level=INFO
 log_file=log/simple.log
```

## [](https://github.com/hongliuliao/simple_log#%E4%BE%8B%E5%AD%90)例子:

```
#include "simple_log.h"

int main() {
  // init_log_config("conf/simple_log.conf"); 
  LOG_INFO("%s", "this is a info log");
  return 0;
}
```

## [](https://github.com/hongliuliao/simple_log#%E7%BC%96%E8%AF%91)编译

```
 g++ -I bin/include test/simple_log_test.cpp bin/lib/libsimplelog.a -o bin/simple_log_test
```

## [](https://github.com/hongliuliao/simple_log#%E8%BE%93%E5%87%BA)输出

```
 2014-10-25 15:43:29.216 INFO test/simple_log_test.cpp(5): this is a info log
```

 

 项目地址: [https://github.com/hongliuliao/simple\_log](https://github.com/hongliuliao/simple_log "https://github.com/hongliuliao/simple_log")