Skip to content

Commit

Permalink
Merge pull request #51 from asalkeld/logging-on-windows
Browse files Browse the repository at this point in the history
fix: Syslog is not available on windows
  • Loading branch information
tjholm authored Jan 25, 2022
2 parents 27ef686 + 9714f4a commit 5a147ff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/containerengine/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (

type docker struct {
cli *client.Client
syslog *localSyslog
logger ContainerLogger
}

var _ ContainerEngine = &docker{}
Expand Down Expand Up @@ -287,10 +287,9 @@ func (d *docker) ContainerExec(containerName string, cmd []string, workingDir st
}

func (d *docker) Logger(stackPath string) ContainerLogger {
if d.syslog == nil {
d.syslog = &localSyslog{
logPath: path.Join(utils.NitricLogDir(stackPath), "run.log"),
}
if d.logger != nil {
return d.logger
}
return d.syslog
d.logger = newSyslog(path.Join(utils.NitricLogDir(stackPath), "run.log"))
return d.logger
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows

package containerengine

import (
Expand All @@ -38,6 +40,10 @@ type localSyslog struct {
server *syslog.Server
}

func newSyslog(logPath string) ContainerLogger {
return &localSyslog{logPath: logPath}
}

func (s *localSyslog) Stop() error {
errList := utils.NewErrorList()

Expand Down
37 changes: 37 additions & 0 deletions pkg/containerengine/syslog_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright Nitric Pty Ltd.
//
// SPDX-License-Identifier: Apache-2.0
//
// 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.

// +build windows

package containerengine

import (
"github.com/docker/docker/api/types/container"
)

type nullLogger struct {
}

func newSyslog(logPath string) ContainerLogger {
return &nullLogger{}
}

func (n *nullLogger) Config() *container.LogConfig {
return &container.LogConfig{}
}

func (n *nullLogger) Stop() error { return nil }
func (n *nullLogger) Start() error { return nil }

0 comments on commit 5a147ff

Please sign in to comment.