Added support for LumberJack logging and —log argument like caddy

- I don’t think the way I am doing logging is correct, however it was the only way I could figure to get the package level customizations and flags I wanted while leveraging lumberjack.
- altered tunnel end point interface to AJ’s specification in issue #18
- added an InitLogging function package level, that is called by main to init.
This commit is contained in:
Henry Camacho 2017-03-26 17:33:40 -05:00
parent 2623741ef2
commit a528352e28
3 changed files with 36 additions and 10 deletions

View File

@ -74,7 +74,7 @@ app.controller('statusController', function ($scope, $http) {
console.log("statusController"); console.log("statusController");
$scope.status_search = ""; $scope.status_search = "";
var api = '/api/com.daplie.rvpn/status' var api = '/api/com.daplie.tunnel/status'
$scope.updateView = function() { $scope.updateView = function() {
$http.get(api).then(function(response) { $http.get(api).then(function(response) {
@ -96,7 +96,7 @@ app.controller('serverController', function ($scope, $http) {
$scope.servers_trigger_details = []; $scope.servers_trigger_details = [];
$scope.filtered $scope.filtered
var api = '/api/com.daplie.rvpn/servers' var api = '/api/com.daplie.tunnel/servers'
$scope.updateView = function() { $scope.updateView = function() {
$http.get(api).then(function(response) { $http.get(api).then(function(response) {

40
main.go
View File

@ -5,19 +5,24 @@ import (
"crypto/tls" "crypto/tls"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"time" "time"
"github.com/spf13/viper" "github.com/spf13/viper"
"io"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/genericlistener" "git.daplie.com/Daplie/go-rvpn-server/rvpn/genericlistener"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
) )
var ( var (
loginfo *log.Logger loginfo *log.Logger
logdebug *log.Logger logdebug *log.Logger
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
logfile = "stdout"
argWssClientListener string argWssClientListener string
argGenericBinding int argGenericBinding int
argServerBinding string argServerBinding string
@ -35,11 +40,37 @@ var (
serverName string serverName string
) )
func init() {
flag.StringVar(&logfile, "log", logfile, "Log file (or stdout/stderr; empty for none)")
}
var logoutput io.Writer
//Main -- main entry point //Main -- main entry point
func main() { func main() {
flag.Parse() flag.Parse()
loginfo = log.New(os.Stdout, "INFO: main: ", logFlags) switch logfile {
logdebug = log.New(os.Stdout, "DEBUG: main:", logFlags) case "stdout":
logoutput = os.Stdout
case "stderr":
logoutput = os.Stderr
case "":
logoutput = ioutil.Discard
default:
logoutput = &lumberjack.Logger{
Filename: logfile,
MaxSize: 100,
MaxAge: 120,
MaxBackups: 10,
}
}
// send the output io.Writing to the other packages
genericlistener.InitLogging(logoutput)
loginfo = log.New(logoutput, "INFO: main: ", logFlags)
logdebug = log.New(logoutput, "DEBUG: main:", logFlags)
viper.SetConfigName("go-rvpn-server") viper.SetConfigName("go-rvpn-server")
viper.AddConfigPath("./") viper.AddConfigPath("./")
err := viper.ReadInConfig() err := viper.ReadInConfig()
@ -61,11 +92,6 @@ func main() {
loginfo.Println("startup") loginfo.Println("startup")
loginfo.Println(viper.Get("rvpn.genericlisteners"))
loginfo.Println(viper.Get("rvpn.domains"))
fmt.Println("-=-=-=-=-=-=-=-=-=-=")
certbundle, err := tls.LoadX509KeyPair("certs/fullchain.pem", "certs/privkey.pem") certbundle, err := tls.LoadX509KeyPair("certs/fullchain.pem", "certs/privkey.pem")
if err != nil { if err != nil {
loginfo.Println(err) loginfo.Println(err)

View File

@ -13,7 +13,7 @@ import (
) )
const ( const (
endPointPrefix = "/api/com.daplie.rvpn/" endPointPrefix = "/api/com.daplie.tunnel/"
) )
var connectionTable *Table var connectionTable *Table