forked from aliyun/aliyun-log-c-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Ic7dfdc8e70ba34fc277dfda3dd97043520095db6
- Loading branch information
北洲
committed
May 31, 2016
1 parent
3b93a20
commit 40b492f
Showing
36 changed files
with
6,125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
PROJECT(log_c_sdk) | ||
|
||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | ||
|
||
set(CMAKE_VERSION 2.0.0) | ||
|
||
# default C / CXX flags | ||
set(CMAKE_C_FLAGS " -g -ggdb -O0 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
set(CMAKE_CXX_FLAGS " -g -ggdb -O0 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
|
||
set(CMAKE_C_FLAGS_DEBUG " -g -ggdb -O0 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
set(CMAKE_CXX_FLAGS_DEBUG " -g -ggdb -O0 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
|
||
set(CMAKE_C_FLAGS_RELEASE " -O3 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
set(CMAKE_CXX_FLAGS_RELEASE " -O3 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
|
||
set(CMAKE_C_FLAGS_MINSIZEREF " -Os -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
set(CMAKE_CXX_FLAGS_MINSIZEREF " -Os -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
|
||
set(CMAKE_C_FLAGS_RELWITHDEBINFO " -O2 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -Wall -Werror -fpic -fPIC -D_LARGEFILE64_SOURCE") | ||
|
||
set(CMAKE_C_FLAGS_COVERAGE " ${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") | ||
set(CMAKE_CXX_FLAGS_COVERAGE " ${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverag") | ||
|
||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/${CMAKE_BUILD_TYPE}/lib) | ||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/${CMAKE_BUILD_TYPE}/bin) | ||
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1) | ||
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1) | ||
|
||
FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/) | ||
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/) | ||
|
||
IF (APR_CONFIG_BIN) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APR_CONFIG_BIN} --includedir | ||
OUTPUT_VARIABLE APR_INCLUDE_DIR | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APR_CONFIG_BIN} --cflags | ||
OUTPUT_VARIABLE APR_C_FLAGS | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APR_CONFIG_BIN} --link-ld | ||
OUTPUT_VARIABLE APR_LIBRARIES | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
ELSE() | ||
MESSAGE(FATAL_ERROR "Could not find apr-config/apr-1-config") | ||
ENDIF() | ||
|
||
IF (APU_CONFIG_BIN) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APU_CONFIG_BIN} --includedir | ||
OUTPUT_VARIABLE APR_UTIL_INCLUDE_DIR | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APU_CONFIG_BIN} --cflags | ||
OUTPUT_VARIABLE APU_C_FLAGS | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
EXECUTE_PROCESS( | ||
COMMAND ${APU_CONFIG_BIN} --link-ld | ||
OUTPUT_VARIABLE APU_LIBRARIES | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
ELSE() | ||
MESSAGE(FATAL_ERROR "Could not find apu-config/apu-1-config") | ||
ENDIF() | ||
|
||
#curl-config | ||
FIND_PROGRAM(CURL_CONFIG_BIN NAMES curl-config) | ||
|
||
IF (CURL_CONFIG_BIN) | ||
EXECUTE_PROCESS( | ||
COMMAND ${CURL_CONFIG_BIN} --libs | ||
OUTPUT_VARIABLE CURL_LIBRARIES | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
ELSE() | ||
MESSAGE(FATAL_ERROR "Could not find curl-config") | ||
ENDIF() | ||
|
||
# Compile and link lib_log_c_sdk | ||
include_directories(${APR_INCLUDE_DIR}) | ||
include_directories(${APR_UTIL_INCLUDE_DIR}) | ||
include_directories(${CURL_INCLUDE_DIR}) | ||
|
||
aux_source_directory(src SRC_LIST) | ||
|
||
add_library(${CMAKE_PROJECT_NAME} SHARED ${SRC_LIST}) | ||
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRC_LIST}) | ||
|
||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${CMAKE_VERSION} SOVERSION ${CMAKE_VERSION}) | ||
|
||
INSTALL(TARGETS ${CMAKE_PROJECT_NAME} LIBRARY DESTINATION lib) | ||
|
||
INSTALL(TARGETS ${CMAKE_PROJECT_NAME}_static ARCHIVE DESTINATION lib) | ||
|
||
INSTALL(FILES | ||
src/cJSON.h | ||
src/lz4.h | ||
src/aos_buf.h | ||
src/aos_define.h | ||
src/aos_fstack.h | ||
src/aos_http_io.h | ||
src/aos_list.h | ||
src/aos_log.h | ||
src/aos_status.h | ||
src/aos_string.h | ||
src/aos_transport.h | ||
src/aos_util.h | ||
src/log_define.h | ||
src/log_util.h | ||
src/log_api.h | ||
DESTINATION include/log_c_sdk) | ||
|
||
add_subdirectory(sample) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Aliyun LOG SDK for C | ||
|
||
## 安装方法 | ||
### 环境依赖 | ||
LOG C SDK使用curl进行网络操作,无论是作为客户端还是服务器端,都需要依赖curl。 | ||
另外,LOG C SDK使用apr/apr-util库解决内存管理以及跨平台问题。 | ||
LOG C SDK并没有带上这几个外部库,您需要确认这些库已经安装,并且将它们的头文件目录和库文件目录都加入到了项目中。 | ||
|
||
#### 第三方库下载以及安装 | ||
|
||
##### libcurl (建议 7.32.0 及以上版本) | ||
|
||
请从[这里](http://curl.haxx.se/download.html)下载,并参考[libcurl 安装指南](http://curl.haxx.se/docs/install.html)安装。典型的安装方式如下: | ||
```shell | ||
./configure | ||
make | ||
make install | ||
``` | ||
|
||
注意: | ||
- 执行./configure时默认是配置安装目录为/usr/local/,如果需要指定安装目录,请使用 ./configure --prefix=/your/install/path/ | ||
|
||
##### apr (建议 1.5.2 及以上版本) | ||
|
||
请从[这里](https://apr.apache.org/download.cgi)下载,典型的安装方式如下: | ||
```shell | ||
./configure | ||
make | ||
make install | ||
``` | ||
|
||
注意: | ||
- 执行./configure时默认是配置安装目录为/usr/local/,如果需要指定安装目录,请使用 ./configure --prefix=/your/install/path/ | ||
|
||
##### apr-util (建议 1.5.4 及以上版本) | ||
|
||
请从[这里](https://apr.apache.org/download.cgi)下载,安装时需要注意指定--with-apr选项,典型的安装方式如下: | ||
```shell | ||
./configure --with-apr=/your/apr/install/path | ||
make | ||
make install | ||
``` | ||
|
||
注意: | ||
- 执行./configure时默认是配置安装目录为/usr/local/,如果需要指定安装目录,请使用 ./configure --prefix=/your/install/path/ | ||
- 需要通过--with-apr指定apr安装目录,如果apr安装到系统目录下需要指定--with-apr=/usr/local/apr/ | ||
|
||
|
||
##### CMake (建议2.6.0及以上版本) | ||
|
||
请从[这里](https://cmake.org/download)下载,典型的安装方式如下: | ||
```shell | ||
./configure | ||
make | ||
make install | ||
``` | ||
|
||
注意: | ||
- 执行./configure时默认是配置安装目录为/usr/local/,如果需要指定安装目录,请使用 ./configure --prefix=/your/install/path/ | ||
|
||
#### LOG C SDK的安装 | ||
|
||
安装时请在cmake命令中指定第三方库头文件以及库文件的路径,典型的编译命令如下: | ||
```shell | ||
cmake . | ||
make | ||
make install | ||
``` | ||
|
||
注意: | ||
- 执行cmake . 时默认会到/usr/local/下面去寻找curl,apr,apr-util的头文件和库文件。 | ||
- 默认编译是Debug类型,可以指定以下几种编译类型: Debug, Release, RelWithDebInfo和MinSizeRel,如果要使用release类型编译,则执行cmake . -DCMAKE_BUILD_TYPE=Release | ||
- 如果您在安装curl,apr,apr-util时指定了安装目录,则需要在执行cmake时指定这些库的路径,比如: | ||
```shell | ||
cmake . -DCURL_INCLUDE_DIR=/usr/local/include/curl/ -DCURL_LIBRARY=/usr/local/lib/libcurl.a -DAPR_INCLUDE_DIR=/usr/local/include/apr-1/ -DAPR_LIBRARY=/usr/local/lib/libapr-1.a -DAPR_UTIL_INCLUDE_DIR=/usr/local/apr/include/apr-1 -DAPR_UTIL_LIBRARY=/usr/local/apr/lib/libaprutil-1.a | ||
``` | ||
- 如果要指定安装目录,则需要在cmake时增加: -DCMAKE_INSTALL_PREFIX=/your/install/path/usr/local/ | ||
|
||
## 联系我们 | ||
- [阿里云LOG官方网站](https://www.aliyun.com/product/sls/) | ||
- [阿里云LOG官方论坛](https://yq.aliyun.com/groups/50) | ||
- 阿里云官方技术支持:[提交工单](https://workorder.console.aliyun.com/#/ticket/createIndex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
project (log_c_sdk_sample) | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}) | ||
|
||
set(POST_LOGS_SOURCE_FILES log_config.c | ||
log_post_logs_sample.c) | ||
|
||
include_directories (${APR_INCLUDE_DIR}) | ||
include_directories (${APR_UTIL_INCLUDE_DIR}) | ||
include_directories (${CURL_INCLUDE_DIR}) | ||
include_directories ("${CMAKE_SOURCE_DIR}/src") | ||
|
||
find_library(APR_LIBRARY apr-1 PATHS /usr/local/apr/lib/) | ||
find_library(APR_UTIL_LIBRARY aprutil-1 PATHS /usr/local/apr/lib/) | ||
find_library(CURL_LIBRARY curl) | ||
find_library(PTHREAD_LIBRARY pthread) | ||
find_library(RT_LIBRARY rt) | ||
find_library(M_LIBRARY m) | ||
|
||
function(_TARGET_SAMPLE_LIBRARIES SAMPLE_BIN_NAME SOURCE_FILES) | ||
add_executable(${SAMPLE_BIN_NAME} ${SOURCE_FILES}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} log_c_sdk) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${APR_UTIL_LIBRARY}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${APR_LIBRARY}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${CURL_LIBRARY}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${PTHREAD_LIBRARY}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${RT_LIBRARY}) | ||
target_link_libraries(${SAMPLE_BIN_NAME} ${M_LIBRARY}) | ||
endfunction() | ||
|
||
_TARGET_SAMPLE_LIBRARIES(log_post_logs_sample "${POST_LOGS_SOURCE_FILES}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "log_config.h" | ||
|
||
const char LOG_ENDPOINT[] = "https://xxxx"; | ||
const char ACCESS_KEY_ID[] = "your accesskey id"; | ||
const char ACCESS_KEY_SECRET[] = "your accesskey"; | ||
const char PROJECT_NAME[] = "ali-test-tracking"; | ||
const char LOGSTORE_NAME[] = "weee"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef LOG_TEST_CONFIG_H | ||
#define LOG_TEST_CONFIG_H | ||
|
||
#include "log_define.h" | ||
|
||
LOG_CPP_START | ||
|
||
extern const char LOG_ENDPOINT[]; | ||
extern const char ACCESS_KEY_ID[]; | ||
extern const char ACCESS_KEY_SECRET[]; | ||
extern const char PROJECT_NAME[]; | ||
extern const char LOGSTORE_NAME[]; | ||
|
||
LOG_CPP_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "aos_log.h" | ||
#include "aos_util.h" | ||
#include "aos_string.h" | ||
#include "aos_status.h" | ||
#include "log_auth.h" | ||
#include "log_util.h" | ||
#include "log_api.h" | ||
#include "log_config.h" | ||
|
||
void log_post_logs_sample() | ||
{ | ||
aos_pool_t *p = NULL; | ||
aos_status_t *s = NULL; | ||
aos_pool_create(&p, NULL); | ||
|
||
cJSON *root = cJSON_CreateObject(); | ||
cJSON_AddStringToObject(root, "__source__", "127.0.0.1"); | ||
cJSON_AddStringToObject(root, "__topic__", "topic"); | ||
cJSON *tags = cJSON_CreateObject(); | ||
cJSON_AddItemToObject(root, "__tags__", tags); | ||
cJSON_AddStringToObject(tags, "tag1", "tag1"); | ||
cJSON_AddStringToObject(tags, "tag2", "tag2"); | ||
cJSON *logs = cJSON_CreateArray(); | ||
cJSON_AddItemToObject(root, "__logs__", logs); | ||
cJSON *log1 = cJSON_CreateObject(); | ||
cJSON_AddStringToObject(log1, "level", "error1"); | ||
cJSON_AddStringToObject(log1, "message", "c sdk test message1"); | ||
cJSON_AddNumberToObject(log1, "__time__", apr_time_now()/1000000); | ||
cJSON *log2 = cJSON_CreateObject(); | ||
cJSON_AddStringToObject(log2, "level", "error2"); | ||
cJSON_AddStringToObject(log2, "message", "c sdk test message2"); | ||
cJSON_AddNumberToObject(log2, "__time__", apr_time_now()/1000000); | ||
cJSON_AddItemToArray(logs, log1); | ||
cJSON_AddItemToArray(logs, log2); | ||
s = log_post_logs(p, LOG_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, PROJECT_NAME, LOGSTORE_NAME, root); | ||
if (aos_status_is_ok(s)) { | ||
printf("post logs succeeded\n"); | ||
} else { | ||
printf("put logs failed\n"); | ||
} | ||
cJSON_Delete(root); | ||
aos_pool_destroy(p); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
if (aos_http_io_initialize("linux-x86_64", 0) != AOSE_OK) { | ||
exit(1); | ||
} | ||
log_post_logs_sample(); | ||
aos_http_io_deinitialize(); | ||
return 0; | ||
} |
Oops, something went wrong.