Commit e1e29920 by lichenggang

添加readme

parent 89eccf1d
# web_log
## 项目简介
####1. 开发人员
李成刚, 郑宗霖, 陈森彬
####2. 主要用途
- 实时监控特定目录下的日志目录和日志文件
- 登录后可在外网浏览器上进行浏览
####3. 使用方式
```code
go run main.go -p 9997 -d /data/logs
```
参数说明
-d 需要监听的日志目录目录 (必填)
-p 端口 (选填,默认为9997端口)
...@@ -2,6 +2,7 @@ package config ...@@ -2,6 +2,7 @@ package config
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"os" "os"
"strings" "strings"
...@@ -19,16 +20,20 @@ func GetCurrentPath() string { ...@@ -19,16 +20,20 @@ func GetCurrentPath() string {
return strings.Replace(dir, "\\", "/", -1) return strings.Replace(dir, "\\", "/", -1)
} }
func InitConfig() { func InitConfig() {
Directory = "E:\\test_logs" // directory of the log
flag.StringVar(&Directory, "d", "/data/inotify_logs", "监听目录") flag.StringVar(&Directory, "d", "/data/inotify_logs", "监听目录")
flag.StringVar(&Port, "port", "9997", "监听端口") flag.StringVar(&Port, "p", "9997", "监听端口")
flag.Parse() flag.Parse()
logenv := os.Getenv("GOLOGENV") _, err := os.Stat(Directory)
if logenv == "TEST" { if err != nil {
Directory = "/data/soft/bigdatav3.0/test_rsync_log" fmt.Printf("目录: [%s] 不存在, 请重新用[-d]参数指定目录", Directory)
} os.Exit(0)
if logenv == "PRODUCT" {
Directory = "/data/inotify_logs"
} }
//logenv := os.Getenv("GOLOGENV")
//if logenv == "TEST" {
// Directory = "/data/soft/bigdatav3.0/test_rsync_log"
//}
//if logenv == "PRODUCT" {
// Directory = "/data/inotify_logs"
//}
UserConfigPath = GetCurrentPath() + "/config/users.json" UserConfigPath = GetCurrentPath() + "/config/users.json"
} }
...@@ -13,7 +13,7 @@ func main() { ...@@ -13,7 +13,7 @@ func main() {
config.InitConfig() config.InitConfig()
addrs := "0.0.0.0:" + config.Port addrs := "0.0.0.0:" + config.Port
fmt.Printf("查看日志目录: %s \n用户配置文件: %s", config.Directory, config.UserConfigPath) fmt.Printf("查看日志目录: %s \n用户配置文件: %s\n", config.Directory, config.UserConfigPath)
app := code.GetApp(config.Directory) app := code.GetApp(config.Directory)
app.Run(iris.Addr(addrs), iris.WithCharset("UTF-8")) app.Run(iris.Addr(addrs), iris.WithCharset("UTF-8"))
......
package utils
import "os"
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
...@@ -142,7 +142,8 @@ ...@@ -142,7 +142,8 @@
<body> <body>
<header> <header>
<h2 id="title">实时查看日志信息 &nbsp;<button id="status" style="background-color: darkorange">正在连接...</button> <h2 id="title" style="margin: 1px">实时查看日志信息 &nbsp;<button id="status" style="background-color: darkorange">正在连接...</button>
<h5 style="margin: 1px">(默认显示最后500行)</h5>
</h2> </h2>
<div class="tool"> <div class="tool">
<button id="pause">暂停</button> <button id="pause">暂停</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment