Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
4b0b1704
Commit
4b0b1704
authored
Apr 14, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
创建日志文件
parent
eae6494c
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
45 additions
and
5 deletions
+45
-5
ip.c.o
build/CMakeFiles/main.dir/src/ip.c.o
+0
-0
log.c.o
build/CMakeFiles/main.dir/src/log.c.o
+0
-0
mqtt.c.o
build/CMakeFiles/main.dir/src/mqtt.c.o
+0
-0
main.c.o
build/CMakeFiles/main.dir/usr/main.c.o
+0
-0
version.h
build/include/version.h
+2
-2
main
build/main
+0
-0
log.h
include/log.h
+2
-0
ip.c
src/ip.c
+1
-1
log.c
src/log.c
+34
-0
mqtt.c
src/mqtt.c
+2
-2
main.c
usr/main.c
+4
-0
zlog.conf
zlog.conf
+0
-0
No files found.
build/CMakeFiles/main.dir/src/ip.c.o
View file @
4b0b1704
No preview for this file type
build/CMakeFiles/main.dir/src/log.c.o
View file @
4b0b1704
No preview for this file type
build/CMakeFiles/main.dir/src/mqtt.c.o
View file @
4b0b1704
No preview for this file type
build/CMakeFiles/main.dir/usr/main.c.o
View file @
4b0b1704
No preview for this file type
build/include/version.h
View file @
4b0b1704
#define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MAJOR 1
#define PROJECT_VERSION_MINOR 0
#define PROJECT_VERSION_MINOR 0
#define PROJECT_VERSION_PATCH 1
#define PROJECT_VERSION_PATCH 1
#define GIT_HASH "
2d4b24d
"
#define GIT_HASH "
eae6494
"
#define BUILD_TIMESTAMP "2025-04-14T1
0:22:21
"
#define BUILD_TIMESTAMP "2025-04-14T1
1:06:17
"
#define BUILD_USER "orangepi"
#define BUILD_USER "orangepi"
build/main
View file @
4b0b1704
No preview for this file type
include/log.h
View file @
4b0b1704
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
int
logprject_Init
();
int
logprject_Init
();
void
my_log_close
();
void
my_log_close
();
int
logconf_create
();
// 封装 zlog_debug
// 封装 zlog_debug
void
my_zlog_debug
(
const
char
*
format
,
...)
;
void
my_zlog_debug
(
const
char
*
format
,
...)
;
// 封装 zlog_info
// 封装 zlog_info
...
...
src/ip.c
View file @
4b0b1704
...
@@ -24,7 +24,7 @@ int ipaddr() {//获取ip
...
@@ -24,7 +24,7 @@ int ipaddr() {//获取ip
}
}
//printf("ip:%s\n",ip_address);
//printf("ip:%s\n",ip_address);
my_zlog_debug
(
"ip:%s
\n
"
,
ip_address
);
my_zlog_debug
(
"ip:%s"
,
ip_address
);
freeifaddrs
(
ifap
);
freeifaddrs
(
ifap
);
...
...
src/log.c
View file @
4b0b1704
...
@@ -5,10 +5,44 @@
...
@@ -5,10 +5,44 @@
#include<zlog.h>
#include<zlog.h>
#include "log.h"
#include "log.h"
const
char
*
config_content
=
"[global]
\n
"
"strict init = true
\n
"
"buffer min = 1024
\n
"
"buffer max = 2MB
\n
"
"default format =
\"
%d(%Y-%m-%d %H:%M:%S.%ms) %-6V (%c:%F:%L) - %m%n
\"\n
"
"file perms = 600 # 设置文件权限
\n
"
"
\n
"
"[formats]
\n
"
"millisecond =
\"
%d(%Y-%m-%d %H:%M:%S.%ms) [%V] %m%n
\"\n
"
"
\n
"
"[rules]
\n
"
"# 日志文件路径,30天轮询,自动创建目录
\n
"
"my_log.*
\"
/home/orangepi/car/master/log/log.log
\"
, 30D; millisecond
\n
"
;
const
char
*
LOG_FILE
=
"/home/orangepi/car/master/log/log.log"
;
//日志文件
const
char
*
LOG_FILE
=
"/home/orangepi/car/master/log/log.log"
;
//日志文件
static
zlog_category_t
*
zlog_c
=
NULL
;
static
zlog_category_t
*
zlog_c
=
NULL
;
int
logconf_create
()
{
const
char
*
config_file
=
"/home/orangepi/car/master/zlog.conf"
;
// 检查文件是否存在
if
(
access
(
config_file
,
F_OK
)
!=
0
)
{
// 文件不存在,创建并写入内容
FILE
*
fp
=
fopen
(
config_file
,
"w"
);
if
(
fp
==
NULL
)
{
perror
(
"Failed to create zlog.conf"
);
return
1
;
}
// 写入配置内容
fwrite
(
config_content
,
strlen
(
config_content
),
1
,
fp
);
fclose
(
fp
);
printf
(
"zlog.conf has been created.
\n
"
);
}
else
{
printf
(
"zlog.conf already exists.
\n
"
);
}
return
0
;
}
// 检查并创建日志目录
// 检查并创建日志目录
static
int
create_log_dir_if_not_exist
(
const
char
*
path
)
{
static
int
create_log_dir_if_not_exist
(
const
char
*
path
)
{
char
dir_path
[
256
]
=
{
0
};
char
dir_path
[
256
]
=
{
0
};
...
...
src/mqtt.c
View file @
4b0b1704
...
@@ -43,7 +43,7 @@ int mqtt_init() {
...
@@ -43,7 +43,7 @@ int mqtt_init() {
mosq
=
mosquitto_new
(
NULL
,
true
,
NULL
);
mosq
=
mosquitto_new
(
NULL
,
true
,
NULL
);
if
(
!
mosq
)
{
if
(
!
mosq
)
{
fprintf
(
stderr
,
"Failed to create Mosquitto client
\n
"
);
//
fprintf(stderr, "Failed to create Mosquitto client\n");
my_zlog_fatal
(
"Failed to create Mosquitto client"
);
my_zlog_fatal
(
"Failed to create Mosquitto client"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -266,7 +266,7 @@ void mqtt_create(struct mosquitto *mosq) {//创建mqtt客服端
...
@@ -266,7 +266,7 @@ void mqtt_create(struct mosquitto *mosq) {//创建mqtt客服端
rc
=
mosquitto_connect
(
mosq
,
BROKER_ADDRESS
,
BROKER_PORT
,
60
);
rc
=
mosquitto_connect
(
mosq
,
BROKER_ADDRESS
,
BROKER_PORT
,
60
);
if
(
rc
!=
MOSQ_ERR_SUCCESS
)
{
if
(
rc
!=
MOSQ_ERR_SUCCESS
)
{
//fprintf(stderr, "Failed to connect to broker: %s\n", mosquitto_strerror(rc));
//fprintf(stderr, "Failed to connect to broker: %s\n", mosquitto_strerror(rc));
my_zlog_warn
(
"Failed to connect to broker: %s
\n
"
,
mosquitto_strerror
(
rc
));
my_zlog_warn
(
"Failed to connect to broker: %s"
,
mosquitto_strerror
(
rc
));
mosquitto_destroy
(
mosq
);
mosquitto_destroy
(
mosq
);
//return EXIT_FAILURE;
//return EXIT_FAILURE;
}
}
...
...
usr/main.c
View file @
4b0b1704
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
logconf_create
()
!=
0
)
{
return
6
;
}
if
(
logprject_Init
()
!=
0
)
{
if
(
logprject_Init
()
!=
0
)
{
my_zlog_fatal
(
"日志初始化失败"
);
my_zlog_fatal
(
"日志初始化失败"
);
//printf("日志初始化失败");
//printf("日志初始化失败");
...
...
zlog.conf
View file @
4b0b1704
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment