cb-log is a logger library for the Cloud-Barista Multi-Cloud Framework.
[NOTE]
cb-log is currently under development.
So, we do not recommend using the current release in production.
Please note that the functionalities of cb-log are not stable and secure yet.
If you have any difficulties in using cb-log, please let us know.
(Open an issue or Join the cloud-barista Slack)
- ๋ฐฐํฌํ๊ฒฝ: Ubuntu 18.04, Docker 19.03, Go 1.15
- ๊ฐ๋ฐํ๊ฒฝ: Ubuntu 20.04, Ubuntu 18.04, Debian 10.6, macOS Catalina 10.15, Android 8.1
- latest Docker, latest Go
- Go ์ค์น
$ sudo apt update $ sudo apt install -y make gcc $ sudo snap install go --classic - cb-log ์ค์น ๋ฐฉ๋ฒ
- ๋ชจ๋ ๋ค์ด๋ก๋ ๋ฐฉ๋ฒ(Go Module mode, default)
- cb-log ์์ฉ ๊ฐ๋ฐ
- ์์ฉ ์์:
$ wget https://raw.githubusercontent.com/cloud-barista/cb-log/master/test/test.go
- ์์ฉ ์์:
- ๋ชจ๋ ์ด๊ธฐํ:
$ go mod init test.go - ๋ชจ๋ ๋ค์ด๋ก๋:
$ go mod tidy - ๋ค์ด๋ก๋ ์์น ์์:
/home/ubuntu/go/pkg/mod/github.com/cloud-barista/cb-log@v0.3.1
- cb-log ์์ฉ ๊ฐ๋ฐ
- ์์ค ๋ค์ด๋ก๋ ๋ฐฉ๋ฒ(Old GOPATH mode):
- ์์ค ๋ค์ด๋ก๋:
$ go get -u -v github.com/cloud-barista/cb-log - ๋ค์ด๋ก๋ ์์น ์์:
/home/ubuntu/go/src/github.com/cloud-barista/cb-log
- ์์ค ๋ค์ด๋ก๋:
- ๋ชจ๋ ๋ค์ด๋ก๋ ๋ฐฉ๋ฒ(Go Module mode, default)
-
์ค์ ์ ๋ณด
Configurations Descriptions Default loglevel ๋ก๊ทธ ๋ ๋ฒจ ์ค์ .
์ค์ ๊ฐ: trace, debug, info, warn, error, fatal, panicinfo logfile ๋ก๊ทธ ํ์ผ ์ถ๋ ฅ ์ฌ๋ถ ์ค์ .
์ค์ ๊ฐ: true, falsetrue logfileinfo: ----- ์ดํ logfile true ์ผ๋ ์ ํจ ----- filename ๋ก๊ทธ๋ฅผ ์ ์ฅํ ํ์ผ path ๋ฐ ์ด๋ฆ.
์ค์ ๊ฐ: {path}logfilename./log/cblogs.log maxsize ๊ฐ๋ณ ๋ก๊ทธ ํ์ผ ํฌ๊ธฐ.
์ค์ ๊ฐ: integer #megabytes10 maxbackups ๋ก๊ทธ ํ์ผ ๊ฐ์.
์ค์ ๊ฐ: integer #number50 maxage ๋ก๊ทธ ํ์ผ ์ ์ง ๊ธฐ๊ฐ.
์ค์ ๊ฐ: integer #days31 -
์ค์ ํ์ผ ์์
$ wget -r -nH --cut-dirs=3 https://raw.githubusercontent.com/cloud-barista/cb-log/master/conf/log_conf.yaml$ vi ./conf/log_conf.yaml#### Config for CB-Log Lib. #### cblog: ## trace | debug | info | warn/warning | error | fatal | panic loglevel: error # The log level can be changed dynamically by editing this file. ## true | false logfile: true ## Config for File Output ## logfileinfo: filename: ./log/cblogs.log maxsize: 10 # megabytes maxbackups: 50 maxage: 31 # days
-
์ค์ ์ ์ฉ ๋ฐฉ๋ฒ
- ์๋ ๋ฐ์: ์ค์ ํ์ผ ์์ ์ ์ฆ์ ๋ฐ์ (ํ์ผ ๋ณ๊ฒฝ ์ด๋ฒคํธ ๊ฐ์ง)
-
์ค์ ํ์ผ ์์น ์ง์ ๋ฐฉ๋ฒ
- ํ๊ฒฝ๋ณ์ ์ฌ์ฉ ๋ฐฉ๋ฒ:
- ํ๊ฒฝ๋ณ์ CBLOG_ROOT ์ค์ :
(ex) export CBLOG_ROOT=$HOME/go/src/github.com/cloud-barista/cb-log - ์ค์ ํ์ผ ์์น: $CBLOG_ROOT/conf/log_conf.yaml
- ํ๊ฒฝ๋ณ์ CBLOG_ROOT ์ค์ :
- ์ค์ ํ์ผ ์ง์ ๋ฐฉ๋ฒ:
-
์ค์ ํ์ผ ์์ฑ:
(ex) /etc/my_conf.yaml -
์ฝ๋ ๋ด ์ค์ ํ์ผ ์์น ์ค์ : GetLoggerWithConfigPath() ์ด์ฉ
import ( "github.com/cloud-barista/cb-log" "github.com/sirupsen/logrus" ) var cblogger *logrus.Logger func init() { // cblog is a global variable. cblogger = cblog.GetLoggerWithConfigPath("MY_PROJ", "/etc/my_conf.yaml") }
-
- ํ๊ฒฝ๋ณ์ ์ฌ์ฉ ๋ฐฉ๋ฒ:
- ๊ธฐ๋ณธ ์ฌ์ฉ ์์: GetLogger(), SetLevel(), GetLevel(), WithFields()
- ๋์ ์์ค: https://github.com/cloud-barista/cb-log/blob/master/test/test.go
- ์คํ ๋ฐ ๊ฒฐ๊ณผ:
$ export CBLOG_ROOT=$HOME/go/src/github.com/cloud-barista/cb-log $ cd $CBLOG_ROOT/test $ go run test.go # setup cb-log with $CBLOG_ROOT/conf/log_conf.yaml ####LogLevel: info [CB-SPIDER].[INFO]: 2021-02-14 11:16:49 test.go:24, main.main() - Log Info message [CB-SPIDER].[WARNING]: 2021-02-14 11:16:49 test.go:25, main.main() - Log Waring message [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:26, main.main() - Log Error message [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:27, main.main() - Log Error message:internal error message ####LogLevel: warning [CB-SPIDER].[WARNING]: 2021-02-14 11:16:49 test.go:32, main.main() - Log Waring message [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:33, main.main() - Log Error message [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:34, main.main() - Log Error message:internal error message ####LogLevel: error [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:40, main.main() - Log Error message [CB-SPIDER].[ERROR]: 2021-02-14 11:16:49 test.go:41, main.main() - Log Error message:internal error message ####LogLevel: debug [CB-SPIDER].[DEBUG]: 2021-02-14 11:16:49 test.go:46, main.main() - WithField ํ ์คํธ [TestField=test] [CB-SPIDER].[DEBUG]: 2021-02-14 11:16:49 test.go:48, main.main() - WithFields ํ ์คํธ [Field2=value2,Field3=value3,Field1=value1] [CB-SPIDER].[DEBUG]: 2021-02-14 11:16:49 test.go:50, main.main() - WithError ํ ์คํธ [error=ํ ์คํธ ์ค๋ฅ]
- ํ์ฉ ์์: DBMS ์์ฉ ๋ก๊ทธ ์์
-
์ค์ ํ์ผ ํ๊ฒฝ๋ณ์ ์ง์ ๋ฐฉ๋ฒ
-
ํ๊ฒฝ๋ณ์ ์ค์ :
export CBLOG_ROOT=$HOME/go/src/github.com/cloud-barista/cb-log -
๋์ ์์ค: https://github.com/cloud-barista/cb-log/blob/master/test/sample.go
-
์คํ ๋ฐ ๊ฒฐ๊ณผ
$ export CBLOG_ROOT=$HOME/go/src/github.com/cloud-barista/cb-log $ cd $CBLOG_ROOT/test $ go run sample.go # setup cb-log with $CBLOG_ROOT/conf/log_conf.yaml [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:25, main.main() - start......... [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:45, main.createUser1() - start creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:59, main.createUser1() - finish creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:64, main.createUser2() - start creating user. [CB-SPIDER].[ERROR]: 2019-08-16 23:22:51 sample.go:69, main.createUser2() - DBMS Session is closed!! [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:78, main.createUser2() - finish creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:51 sample.go:37, main.main() - end......... [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:25, main.main() - start......... [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:45, main.createUser1() - start creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:59, main.createUser1() - finish creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:64, main.createUser2() - start creating user. [CB-SPIDER].[ERROR]: 2019-08-16 23:22:53 sample.go:69, main.createUser2() - DBMS Session is closed!! [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:78, main.createUser2() - finish creating user. [CB-SPIDER].[INFO]: 2019-08-16 23:22:53 sample.go:37, main.main() - end......... -
Log Level ๋ณ๊ฒฝ ๋ฐ ์คํ ๊ฒฐ๊ณผ:
debug=>error$ cd $CBLOG_ROOT/test $ vi $CBLOG_ROOT/conf/log_conf.yaml ## debug => error $ go run sample.go # setup cb-log with a user defined configuration file in code [CB-SPIDER].[ERROR]: 2019-08-16 23:22:57 sample.go:69, main.createUser2() - DBMS Session is closed!! [CB-SPIDER].[ERROR]: 2019-08-16 23:22:59 sample.go:69, main.createUser2() - DBMS Session is closed!!
-
-
์ค์ ํ์ผ ์ง์ ๋ฐฉ๋ฒ: GetLoggerWithConfigPath()
-
๋์ ์์ค: https://github.com/cloud-barista/cb-log/blob/master/test/sample-with-config-path.go
-
์คํ ๋ฐ ๊ฒฐ๊ณผ
$ cd ./test $ go run sample-with-config-path.go # setup cb-log with a user defined configuration file in code [CB-SPIDER ..\conf\log_conf.yaml] [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:27, main.main() - start......... [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:48, main.createUser3() - start creating user. [CB-SPIDER].[DEBUG]: 2020-12-23 17:46:09 sample-with-config-path.go:58, main.createUser3() - msg for debugging msg!! [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:63, main.createUser3() - finish creating user. [CB-SPIDER].[DEBUG]: 2020-12-23 17:46:09 sample-with-config-path.go:30, main.main() - msg for debugging msg!! [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:68, main.createUser4() - start creating user. [CB-SPIDER].[ERROR]: 2020-12-23 17:46:09 sample-with-config-path.go:73, main.createUser4() - DBMS Session is closed!! [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:82, main.createUser4() - finish creating user. [CB-SPIDER].[INFO]: 2020-12-23 17:46:09 sample-with-config-path.go:40, main.main() - end......... -
Log Level ๋ณ๊ฒฝ ๋ฐ ์คํ ๊ฒฐ๊ณผ:
debug=>error$ cd ./test $ vi ../conf/log_conf.yaml ## debug => error $ go run sample-with-config-path.go # setup cb-log with a user defined configuration file in code [CB-SPIDER].[ERROR]: 2020-12-23 18:08:12 sample-with-config-path.go:73, main.createUser4() - DBMS Session is closed!! [CB-SPIDER].[ERROR]: 2020-12-23 18:08:14 sample-with-config-path.go:73, main.createUser4() - DBMS Session is closed!!
-
-