# ezdev-log

> 日志展示模块

Latest version **1.1.4** (published 2018-07-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install ezdev-log
pnpm add ezdev-log
yarn add ezdev-log
bun add ezdev-log
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2018-07-04 |
| First published | 2018-05-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 36.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | doukai@chrtc.cn |
| Maintainers | antbee |

## Links

- npm: https://www.npmjs.com/package/ezdev-log
- npm.io page: https://npm.io/package/ezdev-log

## Dependencies (2)

- [ezdev-pcview](https://npm.io/package/ezdev-pcview.md) ^3.3.84
- [json-formatter-js](https://npm.io/package/json-formatter-js.md) ^2.2.0

## Recent versions

- 1.1.4 (latest) — 2018-07-04
- 1.1.3 — 2018-07-03
- 1.1.2 — 2018-07-03
- 1.1.1 — 2018-07-02
- 1.1.0 — 2018-05-04

## README

## 日志管理 ##
**日志管理**模块主要通过elasticsearch作为储存，logstash作为传输媒介，实现了系统日志与访问日志的储存与查询

### 功能说明 ###

- 操作记录--对所有模块的操作记录进行查询追溯
- 日志采集--对系统的访问日志与系统日志进行采集


### 使用说明 ###

 安装elastaicsearch
 
版本要求:2.4.5

[下载地址](https://www.elastic.co/downloads/past-releases/elasticsearch-2-4-5)

1.打开\config\elasticsearch.yml

添加配置

````
network.host: 0.0.0.0
````

2.启动:\bin\elasticsearch.bat

------

 安装logstash

版本要求:5.4.33

[下载地址](https://www.elastic.co/downloads/past-releases/logstash-5-4-3)

1.修改工程ezdev-common\ezdev-common-log\src\main\resources\logstash\logstash.config

````
input {
 redis {
  codec => json
  host => "192.168.1.164"
  port => 6379
  key => "logstash"
  data_type => "list"
 }
}
output{
	elasticsearch{
		hosts => ["localhost:9200"]
		index => "logstash"
	}
}
````

input.redis.host => 实际redis地址

input.redis.port => 实际redis端口

output.elasticsearch.hosts => 实际es地址

2.把logstash.config拷贝到logstash\bin目录下

3.启动:\bin\logstash -f logstash.config

------

 安装kibana(如无系统日志查询需要，可略过)

版本要求:4.6.4

[下载地址](https://www.elastic.co/downloads/past-releases/kibana-4-6-4)

1.修改\config\kibana.yml

添加elasticsearch.url: 实际es地址

2.启动:\bin\kibana.bat

------

 安装sentinl监控插件(如无系统监控需要，可略过)

版本要求:4.6.4(必须与kibana版本对应)

[下载地址](https://github.com/sirensolutions/sentinl/releases/tag/tag-4.6.4-4)

1.安装命令:\bin\kibana plugin -i sentinl -u file:**D:\elk-stack\kibana-4.6.4-windows-x86\bin\sentinl.zip**

**粗体**部分替换为实际位置

2.修改kibana\config\kibana.yml

在最后添加如下内容


````
    sentinl:  
      settings:  
        email:  
          active: true  
          user: xxx@163.com  //邮箱账号  
          password: xxxxxxx  //邮箱密码（第三方登录密码）  
          host: smtp.server.com  // 邮箱smtp 服务器地址  
          ssl: true  
        report:  
          active: true  
          tmp_path: /tmp/  
````

------

 日志模块使用

1.在pom.xml引入

````
    <dependency>
        <groupId>com.chrtc.ezdev</groupId>
        <artifactId>ezdev-common-log</artifactId>
    </dependency>
````

前端模块安装展示模块

````
npm install ezdev-log
````

2.在\resources下添加文件logback.xml

````
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration debug="false">
    <include resource="org/springframework/boot/logging/logback/base.xml" />

    <appender name="LOGSTASH" class="com.cwbase.logback.RedisAppender">
        <!-- redis地址 -->
        <host>192.168.1.45</host>
        <!-- redis端口 -->
        <port>6379</port>
        <key>logstash</key>
        <password></password>
        <database>0</database>
        <timeout>2000</timeout>
        <type>@{type}</type>
        <mdc>true</mdc>
        <additionalField>
            <key>module</key>
            <value>@{module}</value>
        </additionalField>
        <additionalField>
            <key>operation</key>
            <value>@{operation}</value>
        </additionalField>
        <additionalField>
            <key>time</key>
            <value>@{time}</value>
        </additionalField>
        <additionalField>
            <key>user</key>
            <value>@{user}</value>
        </additionalField>
        <additionalField>
            <key>ip</key>
            <value>@{ip}</value>
        </additionalField>
        <additionalField>
            <key>uri</key>
            <value>@{uri}</value>
        </additionalField>
    </appender>
    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="LOGSTASH" />
    </appender>
    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
        <appender-ref ref="ASYNC" />
    </root>
    </configuration>
````

3.修改\resources\application.properties添加日志与es数据源配置如下

````
# logging config
logging.config=classpath:logback.xml

# elasticsearch config
spring.data.elasticsearch.cluster-nodes=192.168.10.112:9300
spring.data.elasticsearch.local=false
spring.data.elasticsearch.repositories.enabled=true
````

------

 nginx配置
 
1.在反向代理中如下配置解决nginx环境中tomcat无法获取真实访问IP的问题
 
````
        location /xxx {
            proxy_pass       http://localhost:8080;

            proxy_set_header  Host $http_host;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
````

备注:

````
proxy_set_header  Host                    $http_host;            # 将当前Host头域值填充成客户端地址
proxy_set_header  X-Real-IP               $remote_addr;                # 真实用户IP
proxy_set_header  X-Forwarded-For         $proxy_add_x_forwarded_for;    # 代理路由信息，此处取ip有安全隐患
````

### API文档 ###

注释 | 属性 | 说明
---|---|---
@EzdevModule | name|在类上使用，设置name属性作为日志中模块内容
@EzdevOperation | name |在方法上使用,设置name属性作为日志中操作内容
@EzdevParam | name|在方法参数中使用,设置name属性作为日志中参数的名称

---
_Source: https://npm.io/package/ezdev-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
