-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated to zerolog for logging and output, fixing #46
- Loading branch information
1 parent
98f18e8
commit 6832631
Showing
8 changed files
with
125 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
"os" | ||
"site-usage-statistics/internal/api" | ||
"site-usage-statistics/internal/domain" | ||
"strings" | ||
) | ||
|
||
const AppVersion = "0.3.3" | ||
const AppVersion = "0.3.4" | ||
|
||
// version history | ||
// 0.3.4 removed all fmt.print*, migrated to zerolog | ||
// 0.3.3 fixed issue #46 | ||
// 0.3.1 slight refactoring | ||
// 0.2.0 integrated GitHub issues | ||
// 0.1.0 made it work | ||
|
||
// init is called AFTER all imported packages have been initialized. | ||
func init() { | ||
// Configure the global logger to write to console/stdout and add file and line number | ||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: zerolog.TimeFormatUnix} | ||
log.Logger = zerolog.New(output).With().Timestamp().Caller().Logger() | ||
|
||
} | ||
|
||
func main() { | ||
|
||
// log levels for zerolog: | ||
|
||
// zerolog allows for logging at the following levels (from highest to lowest): | ||
|
||
// panic (zerolog.PanicLevel, 5) | ||
// fatal (zerolog.FatalLevel, 4) | ||
// error (zerolog.ErrorLevel, 3) | ||
// warn (zerolog.WarnLevel, 2) | ||
// info (zerolog.InfoLevel, 1) | ||
// debug (zerolog.DebugLevel, 0) | ||
// trace (zerolog.TraceLevel, -1) | ||
|
||
// find out runtime environment: | ||
// PROD or PRODUCTION -> fly.io, running in the cloud | ||
// DEV or DEVELOPMENT -> localhost, running on local machine | ||
environment := strings.ToUpper(os.Getenv("ENVIRONMENT")) | ||
if strings.HasPrefix(environment, "PROD") { | ||
log.Info().Msg("Running on fly.io") | ||
// Set the minimum level to WarnLevel to log only warnings and errors | ||
zerolog.SetGlobalLevel(zerolog.WarnLevel) | ||
|
||
} else { | ||
log.Info().Msg("Running on localhost") | ||
} | ||
|
||
// as the main package cannot be imported, constants defined here | ||
// cannot directly be used in internal/* packages, therefore we | ||
// set the AppVersion via a func. | ||
domain.SetAppVersion(AppVersion) | ||
|
||
// Start a server which runs in background and waits for http requests to arrive | ||
// on predefined routes. | ||
// THIS IS A BLOCKING CALL! | ||
api.PrintServerDetails(AppVersion) | ||
// THIS IS A BLOCKING CALL, therefore server details are printed prior to starting the server | ||
api.LogServerDetails(AppVersion) | ||
api.StartAPIServer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# site-usage statistics | ||
|
||
|
||
This is the repo for the statistics and status backend service | ||
for the https://status.arc42.org website. | ||
|
||
The documentation is contained in the [status-repository](https://github.com/arc42/status.arc42.org-site) repository. | ||
|