Skip to content
cloud-baristaPublic

About

cb-log is the logger library for the Cloud-Barista Multi-Cloud Framework.

Topics

Resources

Code of conduct

Stars

5 stars

Watchers

4 watching

Forks

Latest commit

ย 

History

117 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

cb-log

GitHub go.mod Go version GoDocย ย ย  Release Version License

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)

[๋ชฉ ์ฐจ]

  1. ์‹คํ–‰ ํ™˜๊ฒฝ
  2. ์„ค์น˜ ๋ฐฉ๋ฒ•
  3. ์„ค์ • ๋ฐฉ๋ฒ•
  4. ํ™œ์šฉ ์˜ˆ์‹œ

[์‹คํ–‰ ํ™˜๊ฒฝ]

  • ๋ฐฐํฌํ™˜๊ฒฝ: 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
    • ์†Œ์Šค ๋‹ค์šด๋กœ๋“œ ๋ฐฉ๋ฒ•(Old GOPATH mode):
      • ์†Œ์Šค ๋‹ค์šด๋กœ๋“œ: $ go get -u -v github.com/cloud-barista/cb-log
      • ๋‹ค์šด๋กœ๋“œ ์œ„์น˜ ์˜ˆ์‹œ: /home/ubuntu/go/src/github.com/cloud-barista/cb-log

[์„ค์ • ๋ฐฉ๋ฒ•]

  • ์„ค์ • ์ •๋ณด

    Configurations Descriptions Default
    loglevel ๋กœ๊ทธ ๋ ˆ๋ฒจ ์„ค์ •.
    ์„ค์ •๊ฐ’: trace, debug, info, warn, error, fatal, panic
    info
    logfile ๋กœ๊ทธ ํŒŒ์ผ ์ถœ๋ ฅ ์—ฌ๋ถ€ ์„ค์ •.
    ์„ค์ •๊ฐ’: true, false
    true
    logfileinfo: ----- ์ดํ•˜ logfile true ์ผ๋•Œ ์œ ํšจ -----
    filename ๋กœ๊ทธ๋ฅผ ์ €์žฅํ•  ํŒŒ์ผ path ๋ฐ ์ด๋ฆ„.
    ์„ค์ •๊ฐ’: {path}logfilename
    ./log/cblogs.log
    maxsize ๊ฐœ๋ณ„ ๋กœ๊ทธ ํŒŒ์ผ ํฌ๊ธฐ.
    ์„ค์ •๊ฐ’: integer #megabytes
    10
    maxbackups ๋กœ๊ทธ ํŒŒ์ผ ๊ฐœ์ˆ˜.
    ์„ค์ •๊ฐ’: integer #number
    50
    maxage ๋กœ๊ทธ ํŒŒ์ผ ์œ ์ง€ ๊ธฐ๊ฐ„.
    ์„ค์ •๊ฐ’: integer #days
    31
  • ์„ค์ • ํŒŒ์ผ ์˜ˆ์‹œ

    • $ 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
    • ์„ค์ •ํŒŒ์ผ ์ง€์ • ๋ฐฉ๋ฒ•:
      • ์„ค์ •ํŒŒ์ผ ์ƒ์„ฑ: (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!!
        

About

cb-log is the logger library for the Cloud-Barista Multi-Cloud Framework.

Topics

Resources

Code of conduct

Stars

5 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages