本文整理匯總了Golang中github.com/juju/loggo.RemoveWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang RemoveWriter函數的具體用法?Golang RemoveWriter怎麽用?Golang RemoveWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RemoveWriter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRemoveDefaultWriter
func (*writerBasicsSuite) TestRemoveDefaultWriter(c *gc.C) {
defaultWriter, level, err := loggo.RemoveWriter("default")
c.Assert(err, gc.IsNil)
c.Assert(level, gc.Equals, loggo.TRACE)
c.Assert(defaultWriter, gc.NotNil)
// Trying again fails.
defaultWriter, level, err = loggo.RemoveWriter("default")
c.Assert(err, gc.ErrorMatches, `Writer "default" is not registered`)
c.Assert(level, gc.Equals, loggo.UNSPECIFIED)
c.Assert(defaultWriter, gc.IsNil)
}
示例2: TestFindToolsFiltering
func (s *SimpleStreamsToolsSuite) TestFindToolsFiltering(c *gc.C) {
tw := &loggo.TestWriter{}
c.Assert(loggo.RegisterWriter("filter-tester", tw, loggo.DEBUG), gc.IsNil)
defer loggo.RemoveWriter("filter-tester")
_, err := envtools.FindTools(
s.env, 1, -1, coretools.Filter{Number: version.Number{Major: 1, Minor: 2, Patch: 3}}, envtools.DoNotAllowRetry)
c.Assert(err, jc.Satisfies, errors.IsNotFound)
// This is slightly overly prescriptive, but feel free to change or add
// messages. This still helps to ensure that all log messages are
// properly formed.
messages := []jc.SimpleMessage{
{loggo.INFO, "reading tools with major version 1"},
{loggo.INFO, "filtering tools by version: \\d+\\.\\d+\\.\\d+"},
{loggo.DEBUG, "no architecture specified when finding tools, looking for any"},
{loggo.DEBUG, "no series specified when finding tools, looking for any"},
}
sources, err := envtools.GetMetadataSources(s.env)
c.Assert(err, gc.IsNil)
for i := 0; i < 2*len(sources); i++ {
messages = append(messages,
jc.SimpleMessage{loggo.DEBUG, `fetchData failed for .*`},
jc.SimpleMessage{loggo.DEBUG, `cannot load index .*`})
}
c.Check(tw.Log, jc.LogMatches, messages)
}
示例3: TestSyncToolsCommandDeprecatedDestination
func (s *syncToolsSuite) TestSyncToolsCommandDeprecatedDestination(c *gc.C) {
called := false
dir := c.MkDir()
syncTools = func(sctx *sync.SyncContext) error {
c.Assert(sctx.AllVersions, jc.IsFalse)
c.Assert(sctx.DryRun, jc.IsFalse)
c.Assert(sctx.Stream, gc.Equals, "released")
c.Assert(sctx.Source, gc.Equals, "")
c.Assert(sctx.TargetToolsUploader, gc.FitsTypeOf, sync.StorageToolsUploader{})
uploader := sctx.TargetToolsUploader.(sync.StorageToolsUploader)
url, err := uploader.Storage.URL("")
c.Assert(err, jc.ErrorIsNil)
c.Assert(url, gc.Equals, utils.MakeFileURL(dir))
called = true
return nil
}
// Register writer.
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("deprecated-tester", &tw, loggo.DEBUG), gc.IsNil)
defer loggo.RemoveWriter("deprecated-tester")
// Add deprecated message to be checked.
messages := []jc.SimpleMessage{
{loggo.WARNING, "Use of the --destination flag is deprecated in 1.18. Please use --local-dir instead."},
}
// Run sync-tools command with --destination flag.
ctx, err := runSyncToolsCommand(c, "-m", "test-target", "--destination", dir, "--stream", "released")
c.Assert(err, jc.ErrorIsNil)
c.Assert(ctx, gc.NotNil)
c.Assert(called, jc.IsTrue)
// Check deprecated message was logged.
c.Check(tw.Log(), jc.LogMatches, messages)
}
示例4: TestFindToolsFiltering
func (s *SimpleStreamsToolsSuite) TestFindToolsFiltering(c *gc.C) {
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("filter-tester", &tw, loggo.TRACE), gc.IsNil)
defer loggo.RemoveWriter("filter-tester")
logger := loggo.GetLogger("juju.environs")
defer logger.SetLogLevel(logger.LogLevel())
logger.SetLogLevel(loggo.TRACE)
_, err := envtools.FindTools(
s.env, 1, -1, "released", coretools.Filter{Number: version.Number{Major: 1, Minor: 2, Patch: 3}})
c.Assert(err, jc.Satisfies, errors.IsNotFound)
// This is slightly overly prescriptive, but feel free to change or add
// messages. This still helps to ensure that all log messages are
// properly formed.
messages := []jc.SimpleMessage{
{loggo.INFO, "reading tools with major version 1"},
{loggo.INFO, "filtering tools by version: \\d+\\.\\d+\\.\\d+"},
{loggo.TRACE, "no architecture specified when finding tools, looking for "},
{loggo.TRACE, "no series specified when finding tools, looking for \\[.*\\]"},
}
sources, err := envtools.GetMetadataSources(s.env)
c.Assert(err, jc.ErrorIsNil)
for i := 0; i < 2*len(sources); i++ {
messages = append(messages,
jc.SimpleMessage{loggo.TRACE, `fetchData failed for .*`},
jc.SimpleMessage{loggo.TRACE, `cannot load index .*`})
}
c.Check(tw.Log(), jc.LogMatches, messages)
}
示例5: SetUpTest
func (s *writerSuite) SetUpTest(c *gc.C) {
loggo.ResetLoggers()
loggo.RemoveWriter("default")
s.logger = loggo.GetLogger("test.writer")
// Make it so the logger itself writes all messages.
s.logger.SetLogLevel(loggo.TRACE)
}
示例6: BenchmarkLoggingNoWriters
func (s *BenchmarksSuite) BenchmarkLoggingNoWriters(c *gc.C) {
// No writers
loggo.RemoveWriter("test")
for i := 0; i < c.N; i++ {
s.logger.Warningf("just a simple warning for %d", i)
}
}
示例7: TestSyncToolsCommandDeprecatedDestination
func (s *syncToolsSuite) TestSyncToolsCommandDeprecatedDestination(c *gc.C) {
called := false
dir := c.MkDir()
syncTools = func(sctx *sync.SyncContext) error {
c.Assert(sctx.AllVersions, gc.Equals, false)
c.Assert(sctx.DryRun, gc.Equals, false)
c.Assert(sctx.Dev, gc.Equals, false)
c.Assert(sctx.Source, gc.Equals, "")
url, err := sctx.Target.URL("")
c.Assert(err, gc.IsNil)
c.Assert(url, gc.Equals, "file://"+dir)
called = true
return nil
}
// Register writer.
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("deprecated-tester", &tw, loggo.DEBUG), gc.IsNil)
defer loggo.RemoveWriter("deprecated-tester")
// Add deprecated message to be checked.
messages := []jc.SimpleMessage{
{loggo.WARNING, "Use of the --destination flag is deprecated in 1.18. Please use --local-dir instead."},
}
// Run sync-tools command with --destination flag.
ctx, err := runSyncToolsCommand(c, "-e", "test-target", "--destination", dir)
c.Assert(err, gc.IsNil)
c.Assert(ctx, gc.NotNil)
c.Assert(called, jc.IsTrue)
// Check deprecated message was logged.
c.Check(tw.Log(), jc.LogMatches, messages)
s.Reset(c)
}
示例8: captureLogs
func (s *UpgradeSuite) captureLogs(c *gc.C) {
c.Assert(loggo.RegisterWriter("upgrade-tests", &s.logWriter, loggo.INFO), gc.IsNil)
s.AddCleanup(func(*gc.C) {
loggo.RemoveWriter("upgrade-tests")
s.logWriter.Clear()
})
}
示例9: BenchmarkLoggingNoWritersNoFormat
func (s *logwriterSuite) BenchmarkLoggingNoWritersNoFormat(c *gc.C) {
// No writers
loggo.RemoveWriter("test")
for i := 0; i < c.N; i++ {
s.logger.Warningf("just a simple warning")
}
}
示例10: Run
// Run runs a machine agent.
func (a *MachineAgent) Run(_ *cmd.Context) error {
// Due to changes in the logging, and needing to care about old
// environments that have been upgraded, we need to explicitly remove the
// file writer if one has been added, otherwise we will get duplicate
// lines of all logging in the log file.
loggo.RemoveWriter("logfile")
defer a.tomb.Done()
logger.Infof("machine agent %v start (%s [%s])", a.Tag(), version.Current, runtime.Compiler)
if err := a.ReadConfig(a.Tag()); err != nil {
return fmt.Errorf("cannot read agent configuration: %v", err)
}
a.configChangedVal.Set(struct{}{})
agentConfig := a.CurrentConfig()
charm.CacheDir = filepath.Join(agentConfig.DataDir(), "charmcache")
if err := a.createJujuRun(agentConfig.DataDir()); err != nil {
return fmt.Errorf("cannot create juju run symlink: %v", err)
}
a.runner.StartWorker("api", a.APIWorker)
a.runner.StartWorker("statestarter", a.newStateStarterWorker)
a.runner.StartWorker("termination", func() (worker.Worker, error) {
return terminationworker.NewWorker(), nil
})
// At this point, all workers will have been configured to start
close(a.workersStarted)
err := a.runner.Wait()
if err == worker.ErrTerminateAgent {
err = a.uninstallAgent(agentConfig)
}
err = agentDone(err)
a.tomb.Kill(err)
return err
}
示例11: Run
func (c *SyncToolsCommand) Run(ctx *cmd.Context) (resultErr error) {
// Register writer for output on screen.
loggo.RegisterWriter("synctools", cmd.NewCommandLogWriter("juju.environs.sync", ctx.Stdout, ctx.Stderr), loggo.INFO)
defer loggo.RemoveWriter("synctools")
environ, cleanup, err := environFromName(ctx, c.EnvName, &resultErr, "Sync-tools")
if err != nil {
return err
}
defer cleanup()
target := environ.Storage()
if c.localDir != "" {
target, err = filestorage.NewFileStorageWriter(c.localDir)
if err != nil {
return err
}
}
// Prepare syncing.
sctx := &sync.SyncContext{
Target: target,
AllVersions: c.allVersions,
MajorVersion: c.majorVersion,
MinorVersion: c.minorVersion,
DryRun: c.dryRun,
Dev: c.dev,
Public: c.public,
Source: c.source,
}
return syncTools(sctx)
}
示例12: assertSuccessWithInstallStepFailCentOS
func (s *MongoSuite) assertSuccessWithInstallStepFailCentOS(c *gc.C, exec []string, execNameFail string, returnCode int, expectedResult []jc.SimpleMessage) {
type installs struct {
series string
pkg string
}
test := installs{
"centos7", "mongodb*",
}
for _, e := range exec {
testing.PatchExecutableAsEchoArgs(c, s, e)
}
testing.PatchExecutableThrowError(c, s, execNameFail, returnCode)
dataDir := c.MkDir()
s.patchSeries(test.series)
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("mongosuite", &tw, loggo.INFO), jc.ErrorIsNil)
defer loggo.RemoveWriter("mongosuite")
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
c.Assert(err, jc.ErrorIsNil)
c.Assert(tw.Log(), jc.LogMatches, expectedResult)
}
示例13: assertTestMongoGetFails
func (s *MongoSuite) assertTestMongoGetFails(c *gc.C, series string, packageManager string) {
s.patchSeries(series)
// Any exit code from apt-get that isn't 0 or 100 will be treated
// as unexpected, skipping the normal retry loop. failCmd causes
// the command to exit with 1.
binDir := c.MkDir()
s.PatchEnvPathPrepend(binDir)
failCmd(filepath.Join(binDir, packageManager))
// Set the mongodb service as installed but not running.
s.data.SetStatus(mongo.ServiceName, "installed")
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("test-writer", &tw, loggo.ERROR), jc.ErrorIsNil)
defer loggo.RemoveWriter("test-writer")
dataDir := c.MkDir()
err := mongo.EnsureServer(makeEnsureServerParams(dataDir))
// Even though apt-get failed, EnsureServer should continue and
// not return the error - even though apt-get failed, the Juju
// mongodb package is most likely already installed.
// The error should be logged however.
c.Assert(err, jc.ErrorIsNil)
c.Check(tw.Log(), jc.LogMatches, []jc.SimpleMessage{
{loggo.ERROR, `packaging command failed: .+`},
{loggo.ERROR, `cannot install/upgrade mongod \(will proceed anyway\): packaging command failed`},
})
// Verify that EnsureServer continued and started the mongodb service.
c.Check(s.data.Installed(), gc.HasLen, 0)
s.data.CheckCallNames(c, "Installed", "Exists", "Running", "Start")
}
示例14: TestQuantalAptAddRepo
func (s *MongoSuite) TestQuantalAptAddRepo(c *gc.C) {
dir := c.MkDir()
// patch manager.RunCommandWithRetry for repository addition:
s.PatchValue(&manager.RunCommandWithRetry, func(string) (string, int, error) {
return "", 1, fmt.Errorf("packaging command failed: exit status 1")
})
s.PatchEnvPathPrepend(dir)
failCmd(filepath.Join(dir, "add-apt-repository"))
mockShellCommand(c, &s.CleanupSuite, "apt-get")
var tw loggo.TestWriter
c.Assert(loggo.RegisterWriter("test-writer", &tw, loggo.ERROR), jc.ErrorIsNil)
defer loggo.RemoveWriter("test-writer")
// test that we call add-apt-repository only for quantal
// (and that if it fails, we log the error)
s.PatchValue(&version.Current.Series, "quantal")
err := mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, jc.ErrorIsNil)
c.Assert(tw.Log(), jc.LogMatches, []jc.SimpleMessage{
{loggo.ERROR, `cannot install/upgrade mongod \(will proceed anyway\): packaging command failed`},
})
s.PatchValue(&manager.RunCommandWithRetry, func(string) (string, int, error) {
return "", 0, nil
})
s.PatchValue(&version.Current.Series, "trusty")
failCmd(filepath.Join(dir, "mongod"))
err = mongo.EnsureServer(makeEnsureServerParams(dir, ""))
c.Assert(err, jc.ErrorIsNil)
}
示例15: TestBootstrapJenvWarning
func (s *BootstrapSuite) TestBootstrapJenvWarning(c *gc.C) {
env, fake := makeEmptyFakeHome(c)
defer fake.Restore()
defaultSeriesVersion := version.Current
defaultSeriesVersion.Series = config.PreferredSeries(env.Config())
// Force a dev version by having an odd minor version number.
// This is because we have not uploaded any tools and auto
// upload is only enabled for dev versions.
defaultSeriesVersion.Minor = 11
s.PatchValue(&version.Current, defaultSeriesVersion)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
ctx := coretesting.Context(c)
environs.PrepareFromName("peckham", ctx, store)
logger := "jenv.warning.test"
testWriter := &loggo.TestWriter{}
loggo.RegisterWriter(logger, testWriter, loggo.WARNING)
defer loggo.RemoveWriter(logger)
_, errc := runCommand(ctx, new(BootstrapCommand), "-e", "peckham")
c.Assert(<-errc, gc.IsNil)
c.Assert(testWriter.Log, jc.LogMatches, []string{"ignoring environments.yaml: using bootstrap config in .*"})
}