X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsserver%2Fxdsserver.go;h=bb8f75596d2fa7304f6f6826ea4bc0066da0fdf9;hb=2a7a112bbffcd41a3436c086f1910ea7a9c94744;hp=dcdedc44adb60154157f38a48e1c560f805bea58;hpb=2f7828d01f4c4ca2909f95f098627cd5475ed225;p=src%2Fxds%2Fxds-server.git diff --git a/lib/xdsserver/xdsserver.go b/lib/xdsserver/xdsserver.go index dcdedc4..bb8f755 100644 --- a/lib/xdsserver/xdsserver.go +++ b/lib/xdsserver/xdsserver.go @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package xdsserver import ( @@ -9,12 +26,11 @@ import ( "syscall" "time" + st "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/syncthing" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xdsconfig" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" - "github.com/iotbzh/xds-server/lib/xsapiv1" - - "github.com/iotbzh/xds-server/lib/syncthing" - "github.com/iotbzh/xds-server/lib/xdsconfig" ) const cookieMaxAge = "3600" @@ -26,6 +42,7 @@ type Context struct { Config *xdsconfig.Config Log *logrus.Logger LogLevelSilly bool + LogSillyf func(format string, args ...interface{}) SThg *st.SyncThing SThgCmd *exec.Cmd SThgInotCmd *exec.Cmd @@ -33,6 +50,7 @@ type Context struct { sdks *SDKs WWWServer *WebServer sessions *Sessions + events *Events Exit chan os.Signal } @@ -53,14 +71,22 @@ func NewXdsServer(cliCtx *cli.Context) *Context { } log.Formatter = &logrus.TextFormatter{} + // Support silly logging (printed on log.debug) sillyVal, sillyLog := os.LookupEnv("XDS_LOG_SILLY") + logSilly := sillyLog && sillyVal == "1" + sillyFunc := func(format string, args ...interface{}) { + if logSilly { + log.Debugf("SILLY: "+format, args...) + } + } // Define default configuration ctx := Context{ ProgName: cliCtx.App.Name, Cli: cliCtx, Log: log, - LogLevelSilly: (sillyLog && sillyVal == "1"), + LogLevelSilly: logSilly, + LogSillyf: sillyFunc, Exit: make(chan os.Signal, 1), } @@ -102,7 +128,10 @@ func (ctx *Context) Run() (int, error) { ctx._logPrint("Logging file for HTTP requests: %s\n", logFileHTTPReq) } - // Create syncthing instance when section "syncthing" is present in config.json + // Create events management + ctx.events = NewEvents(ctx) + + // Create syncthing instance when section "syncthing" is present in server-config.json if ctx.Config.FileConf.SThgConf != nil { ctx.SThg = st.NewSyncThing(ctx.Config, ctx.Log) }