Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miniflux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
miniflux
Commits
24a2f472
Commit
24a2f472
authored
7 years ago
by
Rogier Lommers
Committed by
fguillot
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add flag to enable debug logging
parent
40eb1b10
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cli/cli.go
+8
-0
8 additions, 0 deletions
cli/cli.go
logger/logger.go
+56
-7
56 additions, 7 deletions
logger/logger.go
with
64 additions
and
7 deletions
cli/cli.go
+
8
−
0
View file @
24a2f472
...
@@ -8,6 +8,8 @@ import (
...
@@ -8,6 +8,8 @@ import (
"flag"
"flag"
"fmt"
"fmt"
"github.com/miniflux/miniflux/logger"
"github.com/miniflux/miniflux/config"
"github.com/miniflux/miniflux/config"
"github.com/miniflux/miniflux/daemon"
"github.com/miniflux/miniflux/daemon"
"github.com/miniflux/miniflux/storage"
"github.com/miniflux/miniflux/storage"
...
@@ -22,6 +24,7 @@ func Parse() {
...
@@ -22,6 +24,7 @@ func Parse() {
flagFlushSessions
:=
flag
.
Bool
(
"flush-sessions"
,
false
,
"Flush all sessions (disconnect users)"
)
flagFlushSessions
:=
flag
.
Bool
(
"flush-sessions"
,
false
,
"Flush all sessions (disconnect users)"
)
flagCreateAdmin
:=
flag
.
Bool
(
"create-admin"
,
false
,
"Create admin user"
)
flagCreateAdmin
:=
flag
.
Bool
(
"create-admin"
,
false
,
"Create admin user"
)
flagResetPassword
:=
flag
.
Bool
(
"reset-password"
,
false
,
"Reset user password"
)
flagResetPassword
:=
flag
.
Bool
(
"reset-password"
,
false
,
"Reset user password"
)
flagDebugMode
:=
flag
.
Bool
(
"debug"
,
false
,
"Enable debug mode (more verbose output)"
)
flag
.
Parse
()
flag
.
Parse
()
cfg
:=
config
.
NewConfig
()
cfg
:=
config
.
NewConfig
()
...
@@ -60,5 +63,10 @@ func Parse() {
...
@@ -60,5 +63,10 @@ func Parse() {
return
return
}
}
if
*
flagDebugMode
{
logger
.
EnableDebug
()
}
// start daemon
daemon
.
Run
(
cfg
,
store
)
daemon
.
Run
(
cfg
,
store
)
}
}
This diff is collapsed.
Click to expand it.
logger/logger.go
+
56
−
7
View file @
24a2f472
...
@@ -10,28 +10,77 @@ import (
...
@@ -10,28 +10,77 @@ import (
"time"
"time"
)
)
var
requestedLevel
=
InfoLevel
// LogLevel type
type
LogLevel
uint32
const
(
// FatalLevel should be used in fatal situations, the app will exit
FatalLevel
LogLevel
=
iota
// ErrorLevel should be used when someone should really look at the error
ErrorLevel
// InfoLevel should be used during normal operations
InfoLevel
// DebugLevel should be used only during development
DebugLevel
)
// Convert the Level to a string.
func
(
level
LogLevel
)
String
()
string
{
switch
level
{
case
DebugLevel
:
return
"DEBUG"
case
InfoLevel
:
return
"INFO"
case
ErrorLevel
:
return
"ERROR"
case
FatalLevel
:
return
"FATAL"
}
return
"UNKNOWN"
}
// EnableDebug increases logging, more verbose (debug)
func
EnableDebug
()
{
requestedLevel
=
DebugLevel
formatMessage
(
InfoLevel
,
"Debug mode enabled"
)
}
// Debug sends a debug log message.
// Debug sends a debug log message.
func
Debug
(
format
string
,
v
...
interface
{})
{
func
Debug
(
format
string
,
v
...
interface
{})
{
formatMessage
(
"DEBUG"
,
format
,
v
...
)
if
requestedLevel
>=
DebugLevel
{
formatMessage
(
DebugLevel
,
format
,
v
...
)
}
}
}
// Info sends an info log message.
// Info sends an info log message.
func
Info
(
format
string
,
v
...
interface
{})
{
func
Info
(
format
string
,
v
...
interface
{})
{
formatMessage
(
"INFO"
,
format
,
v
...
)
if
requestedLevel
>=
InfoLevel
{
formatMessage
(
InfoLevel
,
format
,
v
...
)
}
}
}
// Error sends an error log message.
// Error sends an error log message.
func
Error
(
format
string
,
v
...
interface
{})
{
func
Error
(
format
string
,
v
...
interface
{})
{
formatMessage
(
"ERROR"
,
format
,
v
...
)
if
requestedLevel
>=
ErrorLevel
{
formatMessage
(
ErrorLevel
,
format
,
v
...
)
}
}
}
// Fatal sends a fatal log message and stop the execution of the program.
// Fatal sends a fatal log message and stop the execution of the program.
func
Fatal
(
format
string
,
v
...
interface
{})
{
func
Fatal
(
format
string
,
v
...
interface
{})
{
formatMessage
(
"FATAL"
,
format
,
v
...
)
if
requestedLevel
>=
FatalLevel
{
os
.
Exit
(
1
)
formatMessage
(
FatalLevel
,
format
,
v
...
)
os
.
Exit
(
1
)
}
}
}
func
formatMessage
(
level
,
format
string
,
v
...
interface
{})
{
func
formatMessage
(
level
LogLevel
,
format
string
,
v
...
interface
{})
{
prefix
:=
fmt
.
Sprintf
(
"[%s] [%s] "
,
time
.
Now
()
.
Format
(
"2006-01-02T15:04:05"
),
level
)
prefix
:=
fmt
.
Sprintf
(
"[%s] [%s] "
,
time
.
Now
()
.
Format
(
"2006-01-02T15:04:05"
),
level
.
String
()
)
fmt
.
Fprintf
(
os
.
Stderr
,
prefix
+
format
+
"
\n
"
,
v
...
)
fmt
.
Fprintf
(
os
.
Stderr
,
prefix
+
format
+
"
\n
"
,
v
...
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment