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");
$scope.status_search = "";
var api = '/api/com.daplie.rvpn/status'
var api = '/api/com.daplie.tunnel/status'
$scope.updateView = function() {
$http.get(api).then(function(response) {
@ -96,7 +96,7 @@ app.controller('serverController', function ($scope, $http) {
$scope.servers_trigger_details = [];
$scope.filtered
var api = '/api/com.daplie.rvpn/servers'
var api = '/api/com.daplie.tunnel/servers'
$scope.updateView = function() {
$http.get(api).then(function(response) {

40
main.go
View File

@ -5,19 +5,24 @@ import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"time"
"github.com/spf13/viper"
"io"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/genericlistener"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
var (
loginfo *log.Logger
logdebug *log.Logger
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
logfile = "stdout"
argWssClientListener string
argGenericBinding int
argServerBinding string
@ -35,11 +40,37 @@ var (
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
func main() {
flag.Parse()
loginfo = log.New(os.Stdout, "INFO: main: ", logFlags)
logdebug = log.New(os.Stdout, "DEBUG: main:", logFlags)
switch logfile {
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.AddConfigPath("./")
err := viper.ReadInConfig()
@ -61,11 +92,6 @@ func main() {
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")
if err != nil {
loginfo.Println(err)

View File

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