-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f56730d
commit 75e00de
Showing
16 changed files
with
288 additions
and
44 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
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
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
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,78 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. | ||
// | ||
// 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 logging | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/pulumi/pulumi/pkg/diag" | ||
"github.com/pulumi/pulumi/pkg/resource" | ||
"github.com/pulumi/pulumi/pkg/resource/provider" | ||
) | ||
|
||
// DedupLogger wraps a time-ordered log set to allow batched logging of unique messages. | ||
// Operations on DedupLogger are safe to use concurrently. | ||
type DedupLogger struct { | ||
messages *TimeOrderedLogSet | ||
index int | ||
ctx context.Context | ||
host *provider.HostClient | ||
urn resource.URN | ||
mux sync.Mutex | ||
} | ||
|
||
// NewLogger returns an initialized DedupLogger. | ||
func NewLogger(ctx context.Context, host *provider.HostClient, urn resource.URN) *DedupLogger { | ||
return &DedupLogger{ | ||
messages: &TimeOrderedLogSet{}, | ||
ctx: ctx, | ||
host: host, | ||
urn: urn, | ||
} | ||
} | ||
|
||
// LogMessage adds a message to the log set and flushes the queue to the host. | ||
func (l *DedupLogger) LogMessage(severity diag.Severity, s string) { | ||
l.EnqueueMessage(severity, s) | ||
l.LogNewMessages() | ||
} | ||
|
||
// EnqueueMessage adds a message to the log set but does not log it to the host. | ||
func (l *DedupLogger) EnqueueMessage(severity diag.Severity, s string) { | ||
l.mux.Lock() | ||
defer l.mux.Unlock() | ||
|
||
l.messages.Add(Message{s, severity}) | ||
} | ||
|
||
// GetNewMessages returns the list of new messages since last calling GetNewMessages. | ||
func (l *DedupLogger) GetNewMessages() []Message { | ||
l.mux.Lock() | ||
defer l.mux.Unlock() | ||
|
||
idx := l.index | ||
l.index = len(l.messages.Messages) | ||
return l.messages.Messages[idx:] | ||
} | ||
|
||
// LogNewMessages logs any new messages to the host. | ||
func (l *DedupLogger) LogNewMessages() { | ||
if l.host != nil { | ||
for _, msg := range l.GetNewMessages() { | ||
_ = l.host.LogStatus(l.ctx, msg.severity, l.urn, msg.s) | ||
} | ||
} | ||
} |
Oops, something went wrong.