Skip to content

Commit c10dfd1

Browse files
authored
Merge pull request #685 from jfontan/fix/set-log-level
Set log level
2 parents deef759 + e81c2aa commit c10dfd1

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

cmd/gitbase/command/server.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Server struct {
6262
DisableGit bool `long:"no-git" description:"disable the load of git standard repositories."`
6363
DisableSiva bool `long:"no-siva" description:"disable the load of siva files."`
6464
Verbose bool `short:"v" description:"Activates the verbose mode"`
65+
LogLevel string `long:"log-level" env:"GITBASE_LOG_LEVEL" choice:"info" choice:"debug" choice:"warning" choice:"error" choice:"fatal" default:"info" description:"logging level"`
6566
}
6667

6768
type jaegerLogrus struct {
@@ -109,6 +110,15 @@ func (c *Server) Execute(args []string) error {
109110
logrus.SetLevel(logrus.DebugLevel)
110111
}
111112

113+
// info is the default log level
114+
if c.LogLevel != "info" {
115+
level, err := logrus.ParseLevel(c.LogLevel)
116+
if err != nil {
117+
return fmt.Errorf("cannot parse log level: %s", err.Error())
118+
}
119+
logrus.SetLevel(level)
120+
}
121+
112122
var err error
113123
if c.UserFile != "" {
114124
if c.ReadOnly {
@@ -127,7 +137,7 @@ func (c *Server) Execute(args []string) error {
127137
c.userAuth = auth.NewNativeSingle(c.User, c.Password, permissions)
128138
}
129139

130-
c.userAuth = auth.NewAudit(c.userAuth, auth.NewAuditLog(logrus.New()))
140+
c.userAuth = auth.NewAudit(c.userAuth, auth.NewAuditLog(logrus.StandardLogger()))
131141
if err := c.buildDatabase(); err != nil {
132142
logrus.WithField("error", err).Fatal("unable to initialize database engine")
133143
return err

docs/using-gitbase/configuration.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| `GITBASE_CONNECTION_TIMEOUT` | timeout in seconds used for client connections on write and reads. No timeout by default. |
1818
| `GITBASE_USER_FILE` | JSON file with user credentials |
1919
| `GITBASE_MAX_UAST_BLOB_SIZE` | Max size of blobs to send to be parsed by bblfsh. Default: 5242880 (5MB) |
20+
| `GITBASE_LOG_LEVEL` | minimum logging level to show, use `fatal` to suppress most messages. Default: `info` |
2021

2122
### Jaeger tracing variables
2223

@@ -67,31 +68,43 @@ stops the query. With GITBASE_SKIP_GIT_ERRORS variable it won't
6768
complain and just skip those rows or repositories.
6869
6970
Help Options:
70-
-h, --help Show this help message
71+
-h, --help Show this help message
7172
7273
[server command options]
73-
-d, --directories= Path where the git repositories are located (standard and siva), multiple directories can be
74-
defined. Accepts globs.
75-
--depth= load repositories looking at less than <depth> nested subdirectories. (default: 1000)
76-
--host= Host where the server is going to listen (default: localhost)
77-
-p, --port= Port where the server is going to listen (default: 3306)
78-
-u, --user= User name used for connection (default: root)
79-
-P, --password= Password used for connection
80-
-U, --user-file= JSON file with credentials list [$GITBASE_USER_FILE]
81-
-t, --timeout= Timeout in seconds used for connections [$GITBASE_CONNECTION_TIMEOUT]
82-
-i, --index= Directory where the gitbase indexes information will be persisted. (default:
83-
/var/lib/gitbase/index) [$GITBASE_INDEX_DIR]
84-
--cache= Object cache size in megabytes (default: 512) [$GITBASE_CACHESIZE_MB]
85-
--parallelism= Maximum number of parallel threads per table. By default, it's the number of CPU cores. 0
86-
means default, 1 means disabled.
87-
--no-squash Disables the table squashing.
88-
--trace Enables jaeger tracing [$GITBASE_TRACE]
89-
-r, --readonly Only allow read queries. This disables creating and deleting indexes as well. Cannot be used
90-
with --user-file. [$GITBASE_READONLY]
91-
--no-git disable the load of git standard repositories.
92-
--no-siva disable the load of siva files.
93-
-v Activates the verbose mode
94-
74+
--db= Database name (default: gitbase)
75+
-d, --directories= Path where the git repositories are located
76+
(standard and siva), multiple directories can
77+
be defined. Accepts globs.
78+
--depth= load repositories looking at less than
79+
<depth> nested subdirectories. (default: 1000)
80+
--host= Host where the server is going to listen
81+
(default: localhost)
82+
-p, --port= Port where the server is going to listen
83+
(default: 3306)
84+
-u, --user= User name used for connection (default: root)
85+
-P, --password= Password used for connection
86+
-U, --user-file= JSON file with credentials list
87+
[$GITBASE_USER_FILE]
88+
-t, --timeout= Timeout in seconds used for connections
89+
[$GITBASE_CONNECTION_TIMEOUT]
90+
-i, --index= Directory where the gitbase indexes
91+
information will be persisted. (default:
92+
/var/lib/gitbase/index) [$GITBASE_INDEX_DIR]
93+
--cache= Object cache size in megabytes (default: 512)
94+
[$GITBASE_CACHESIZE_MB]
95+
--parallelism= Maximum number of parallel threads per table.
96+
By default, it's the number of CPU cores. 0
97+
means default, 1 means disabled.
98+
--no-squash Disables the table squashing.
99+
--trace Enables jaeger tracing [$GITBASE_TRACE]
100+
-r, --readonly Only allow read queries. This disables
101+
creating and deleting indexes as well. Cannot
102+
be used with --user-file. [$GITBASE_READONLY]
103+
--no-git disable the load of git standard repositories.
104+
--no-siva disable the load of siva files.
105+
-v Activates the verbose mode
106+
--log-level=[info|debug|warning|error|fatal] logging level (default: info)
107+
[$GITBASE_LOG_LEVEL]
95108
```
96109
## User credentials
97110

0 commit comments

Comments
 (0)