-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Correct logging functionality * Consume ServiceLoggers such that go-java-launcher can retain it's expected behavior of always logging to standard out * Adds clarity to go-init intentionally only truncating log files once, and also correctly truncates all processes being restarted, not just the primary * remove unused const file * make file flags public * go-java-launcher integration test * fail immediately if cannot log, update README
- Loading branch information
1 parent
e1b80fa
commit 3a80009
Showing
14 changed files
with
333 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2016 Palantir Technologies, Inc. | ||
// | ||
// 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 cli | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/palantir/go-java-launcher/launchlib" | ||
) | ||
|
||
type FileFlags interface { | ||
Get(path string) int | ||
} | ||
|
||
type truncatingFirst struct { | ||
created map[string]struct{} | ||
} | ||
|
||
func (t *truncatingFirst) Get(name string) int { | ||
if _, ok := t.created[name]; ok { | ||
return appendOutputFileFlag | ||
} | ||
t.created[name] = struct{}{} | ||
return truncOutputFileFlag | ||
} | ||
|
||
func NewTruncatingFirst() FileFlags { | ||
return &truncatingFirst{ | ||
make(map[string]struct{}), | ||
} | ||
} | ||
|
||
type alwaysAppending struct{} | ||
|
||
func (a *alwaysAppending) Get(path string) int { | ||
return appendOutputFileFlag | ||
} | ||
|
||
func NewAlwaysAppending() FileFlags { | ||
return &alwaysAppending{} | ||
} | ||
|
||
type FileLoggers struct { | ||
flags FileFlags | ||
mode os.FileMode | ||
} | ||
|
||
func (f *FileLoggers) PrimaryLogger() (io.WriteCloser, error) { | ||
return f.OpenFile(PrimaryOutputFile) | ||
} | ||
|
||
func (f *FileLoggers) SubProcessLogger(name string) launchlib.CreateLogger { | ||
return func() (io.WriteCloser, error) { | ||
return f.OpenFile(fmt.Sprintf(SubProcessOutputFileFormat, name)) | ||
} | ||
} | ||
|
||
func (f *FileLoggers) OpenFile(path string) (*os.File, error) { | ||
file, err := os.OpenFile(path, f.flags.Get(path), f.mode) | ||
if err != nil { | ||
return file, errors.Wrapf(err, "could not open logging file '%s'", path) | ||
} | ||
return file, nil | ||
} |
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
Oops, something went wrong.