本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/logger.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLogger函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newSignalableFileLogger
func newSignalableFileLogger(logPath string, level boshlog.LogLevel) boshlog.Logger {
// Log file logger errors to the STDERR logger
logger := boshlog.NewLogger(boshlog.LevelError)
fileSystem := boshsys.NewOsFileSystem(logger)
// log file will be closed by process exit
// log file readable by all
logfileLogger, _, err := boshlogfile.New(level, logPath, boshlogfile.DefaultLogFileMode, fileSystem)
if err != nil {
logger := boshlog.NewLogger(boshlog.LevelError)
ui := biui.NewConsoleUI(logger)
fail(err, ui, logger, nil)
}
return newSignalableLogger(logfileLogger)
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:15,代码来源:main.go
示例2: buildFactory
func buildFactory() (factory Factory) {
config := davconf.Config{User: "some user"}
logger := boshlog.NewLogger(boshlog.LevelNone)
factory = NewFactory(logger)
factory.SetConfig(config)
return
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:7,代码来源:factory_test.go
示例3: main
func main() {
var cfg *config.Config
if configFile != "" {
log.Printf("Loading file: %s\n", configFile)
cfg = config.InitConfigFromFile(configFile)
} else {
log.Fatal("Config file not specified.")
}
level, err := logger.Levelify(cfg.Logging.Level)
if err != nil {
panic(err.Error())
}
logger := logger.NewLogger(level)
dnsUpdater := dns.NewDnsUpdater(*cfg, logger)
go dnsUpdater.Run()
// error chan not being used by anything, just to prevent main from exiting
errCh := make(chan error, 1)
select {
case <-errCh:
return
}
}
开发者ID:nimbus-cloud,项目名称:postgresql-boshrelease,代码行数:27,代码来源:main.go
示例4: buildSSHAction
func buildSSHAction(settingsService boshsettings.Service) (*fakeplatform.FakePlatform, SSHAction) {
platform := fakeplatform.NewFakePlatform()
dirProvider := boshdirs.NewProvider("/foo")
logger := boshlog.NewLogger(boshlog.LevelNone)
action := NewSSH(settingsService, platform, dirProvider, logger)
return platform, action
}
开发者ID:vinodpanicker,项目名称:bosh-agent,代码行数:7,代码来源:ssh_test.go
示例5: NewTestEnvironment
func NewTestEnvironment(
cmdRunner boshsys.CmdRunner,
) *TestEnvironment {
return &TestEnvironment{
cmdRunner: cmdRunner,
currentDeviceNum: 2,
logger: logger.NewLogger(logger.LevelDebug),
}
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:9,代码来源:test_environment.go
示例6: runGet
func runGet(config davconf.Config, args []string) error {
logger := boshlog.NewLogger(boshlog.LevelNone)
factory := NewFactory(logger)
factory.SetConfig(config)
cmd, err := factory.Create("get")
Expect(err).ToNot(HaveOccurred())
return cmd.Run(args)
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:10,代码来源:get_test.go
示例7: newLogger
func newLogger() boshlog.Logger {
logLevelString := os.Getenv("BOSH_INIT_LOG_LEVEL")
level := boshlog.LevelNone
if logLevelString != "" {
var err error
level, err = boshlog.Levelify(logLevelString)
if err != nil {
err = bosherr.WrapError(err, "Invalid BOSH_INIT_LOG_LEVEL value")
logger := boshlog.NewLogger(boshlog.LevelError)
ui := biui.NewConsoleUI(logger)
fail(err, ui, logger, nil)
}
}
logPath := os.Getenv("BOSH_INIT_LOG_PATH")
if logPath != "" {
return newSignalableFileLogger(logPath, level)
}
return newSignalableLogger(boshlog.NewLogger(level))
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:21,代码来源:main.go
示例8: newFakeClient
func newFakeClient(shortClient, longClient *fakehttp.FakeClient) Client {
logger := boshlog.NewLogger(boshlog.LevelNone)
return NewHTTPClient(
"agent.example.com",
"fake-user",
"fake-pass",
shortClient,
longClient,
logger,
)
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:12,代码来源:http_client_test.go
示例9: newRealClient
func newRealClient(url string) Client {
logger := boshlog.NewLogger(boshlog.LevelNone)
return NewHTTPClient(
url,
"fake-user",
"fake-pass",
http.DefaultClient,
http.DefaultClient,
logger,
)
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:12,代码来源:http_client_test.go
示例10: describeDummyPlatform
func describeDummyPlatform() {
var (
platform Platform
collector boshstats.Collector
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
dirProvider boshdirs.Provider
devicePathResolver boshdpresolv.DevicePathResolver
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/fake-dir")
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
platform = NewDummyPlatform(
collector,
fs,
cmdRunner,
dirProvider,
devicePathResolver,
logger,
)
})
Describe("GetDefaultNetwork", func() {
It("returns the contents of dummy-defaults-network-settings.json since that's what the dummy cpi writes", func() {
settingsFilePath := "/fake-dir/bosh/dummy-default-network-settings.json"
fs.WriteFileString(settingsFilePath, `{"IP": "1.2.3.4"}`)
network, err := platform.GetDefaultNetwork()
Expect(err).NotTo(HaveOccurred())
Expect(network.IP).To(Equal("1.2.3.4"))
})
})
Describe("GetCertManager", func() {
It("returs a dummy cert manager", func() {
certManager := platform.GetCertManager()
Expect(certManager.UpdateCertificates("")).Should(BeNil())
})
})
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:51,代码来源:dummy_platform_test.go
示例11: init
func init() {
Describe("Stop", func() {
var (
jobSupervisor *fakejobsuper.FakeJobSupervisor
platform *fakeplatform.FakePlatform
settingsService *fakesettings.FakeSettingsService
logger boshlog.Logger
specService *fakeas.FakeV1Service
dualDCSupport *nimbus.DualDCSupport
action StopAction
)
BeforeEach(func() {
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
specService = fakeas.NewFakeV1Service()
settingsService = &fakesettings.FakeSettingsService{}
dualDCSupport = nimbus.NewDualDCSupport(
platform.GetRunner(),
platform.GetFs(),
platform.GetDirProvider(),
specService,
settingsService,
logger,
)
action = NewStop(jobSupervisor, dualDCSupport, platform)
})
It("is asynchronous", func() {
Expect(action.IsAsynchronous()).To(BeTrue())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("returns stopped", func() {
stopped, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(stopped).To(Equal("stopped"))
})
It("stops job supervisor services", func() {
_, err := action.Run()
Expect(err).ToNot(HaveOccurred())
Expect(jobSupervisor.Stopped).To(BeTrue())
})
})
}
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:50,代码来源:stop_test.go
示例12: main
func main() {
logger := boshlog.NewLogger(boshlog.LevelNone)
cmdFactory := cmd.NewFactory(logger)
cmdRunner := cmd.NewRunner(cmdFactory)
cli := app.New(cmdRunner)
err := cli.Run(os.Args)
if err != nil {
fmt.Printf("Error running app - %s", err.Error())
os.Exit(1)
}
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:14,代码来源:dav.go
示例13: TestIntegration
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
BeforeSuite(func() {
logger := boshlog.NewLogger(boshlog.LevelDebug)
cmdRunner := boshsys.NewExecCmdRunner(logger)
testEnvironment = NewTestEnvironment(cmdRunner)
// Required for reverse-compatibility with older bosh-lite
// (remove once a new warden stemcell is built).
err := testEnvironment.ConfigureAgentForGenericInfrastructure()
Expect(err).ToNot(HaveOccurred())
})
RunSpecs(t, "Integration Suite")
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:16,代码来源:integration_suite_test.go
示例14: Create
//TODO: rename NewBlobstore
func (f blobstoreFactory) Create(blobstoreURL string, httpClient *http.Client) (Blobstore, error) {
logger := boshlog.NewLogger(boshlog.LevelNone)
blobstoreConfig, err := f.parseBlobstoreURL(blobstoreURL)
if err != nil {
return nil, bosherr.WrapError(err, "Creating blobstore config")
}
davClient := boshdavcli.NewClient(boshdavcliconf.Config{
Endpoint: fmt.Sprintf("%s/blobs", blobstoreConfig.Endpoint),
User: blobstoreConfig.Username,
Password: blobstoreConfig.Password,
}, httpClient, logger)
return NewBlobstore(davClient, f.uuidGenerator, f.fs, f.logger), nil
}
开发者ID:mattcui,项目名称:bosh-init,代码行数:18,代码来源:blobstore_factory.go
示例15: init
func init() {
Describe("ListDisk", func() {
var (
settingsService *fakesettings.FakeSettingsService
platform *fakeplatform.FakePlatform
logger boshlog.Logger
action ListDiskAction
)
BeforeEach(func() {
settingsService = &fakesettings.FakeSettingsService{}
platform = fakeplatform.NewFakePlatform()
logger = boshlog.NewLogger(boshlog.LevelNone)
action = NewListDisk(settingsService, platform, logger)
})
It("list disk should be synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("list disk run", func() {
platform.MountedDevicePaths = []string{"/dev/sdb", "/dev/sdc"}
settingsService.Settings.Disks = boshsettings.Disks{
Persistent: map[string]interface{}{
"volume-1": "/dev/sda",
"volume-2": "/dev/sdb",
"volume-3": "/dev/sdc",
},
}
value, err := action.Run()
Expect(err).ToNot(HaveOccurred())
values, ok := value.([]string)
Expect(ok).To(BeTrue())
Expect(values).To(ContainElement("volume-2"))
Expect(values).To(ContainElement("volume-3"))
Expect(len(values)).To(Equal(2))
})
})
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:45,代码来源:list_disk_test.go
示例16: main
func main() {
logger := newSignalableLogger(boshlog.NewLogger(boshlog.LevelDebug))
defer logger.HandlePanic("Main")
logger.Debug(mainLogTag, "Starting agent")
fs := boshsys.NewOsFileSystem(logger)
app := boshapp.New(logger, fs)
err := app.Setup(os.Args)
if err != nil {
logger.Error(mainLogTag, "App setup %s", err.Error())
os.Exit(1)
}
err = app.Run()
if err != nil {
logger.Error(mainLogTag, "App run %s", err.Error())
os.Exit(1)
}
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:22,代码来源:agent.go
示例17: main
func main() {
user := flag.String("user", "user", "User")
password := flag.String("password", "password", "Password")
host := flag.String("host", "127.0.0.1", "Host")
port := flag.Int("port", 8080, "Port")
instance := flag.String("instance", "", "Instance ID")
settings := flag.String("settings", "", "Instance Settings")
flag.Parse()
logger := boshlog.NewLogger(boshlog.LevelDebug)
serverManager := bmregistry.NewServerManager(logger)
_, err := serverManager.Start(*user, *password, *host, *port)
if err != nil {
panic("Error starting registry")
}
if *instance != "" && *settings != "" {
request, err := http.NewRequest(
"PUT",
fmt.Sprintf("http://%s:%[email protected]%s:%d/instances/%s/settings", *user, *password, *host, *port, *instance),
strings.NewReader(*settings),
)
if err != nil {
panic("Couldn't create request")
}
client := http.DefaultClient
_, err = client.Do(request)
if err != nil {
panic(fmt.Sprintf("Error sending request: %s", err.Error()))
}
}
select {}
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:38,代码来源:fake-registry.go
示例18: describeInterfaceConfigurationCreator
func describeInterfaceConfigurationCreator() {
var (
interfaceConfigurationCreator InterfaceConfigurationCreator
staticNetwork boshsettings.Network
staticNetworkWithoutMAC boshsettings.Network
dhcpNetwork boshsettings.Network
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
staticNetworkWithoutMAC = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
}
})
Describe("CreateInterfaceConfigurations", func() {
var networks boshsettings.Networks
var interfacesByMAC map[string]string
BeforeEach(func() {
networks = boshsettings.Networks{}
interfacesByMAC = map[string]string{}
})
Context("One network", func() {
Context("And the network has a MAC address", func() {
BeforeEach(func() {
networks["foo"] = staticNetwork
})
Context("And the MAC address matches an interface", func() {
BeforeEach(func() {
interfacesByMAC[staticNetwork.Mac] = "static-interface-name"
})
It("creates an interface configuration when matching interface exists", func() {
staticInterfaceConfigurations, dhcpInterfaceConfigurations, err := interfaceConfigurationCreator.CreateInterfaceConfigurations(networks, interfacesByMAC)
Expect(err).ToNot(HaveOccurred())
Expect(staticInterfaceConfigurations).To(Equal([]StaticInterfaceConfiguration{
StaticInterfaceConfiguration{
Name: "static-interface-name",
Address: "1.2.3.4",
Netmask: "255.255.255.0",
Network: "1.2.3.0",
Broadcast: "1.2.3.255",
Mac: "fake-static-mac-address",
Gateway: "3.4.5.6",
},
}))
Expect(len(dhcpInterfaceConfigurations)).To(Equal(0))
})
})
Context("And the MAC address has no matching an interface", func() {
BeforeEach(func() {
interfacesByMAC["some-other-mac"] = "static-interface-name"
})
It("retuns an error", func() {
_, _, err := interfaceConfigurationCreator.CreateInterfaceConfigurations(networks, interfacesByMAC)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("No device found"))
Expect(err.Error()).To(ContainSubstring(staticNetwork.Mac))
Expect(err.Error()).To(ContainSubstring("foo"))
})
})
})
Context("Does not have a MAC address", func() {
BeforeEach(func() {
networks["foo"] = staticNetworkWithoutMAC
})
Context("And at least one device is available", func() {
BeforeEach(func() {
interfacesByMAC["fake-any-mac-address"] = "any-interface-name"
})
It("creates an interface configuration even with the MAC address from first interface with device", func() {
staticInterfaceConfigurations, dhcpInterfaceConfigurations, err := interfaceConfigurationCreator.CreateInterfaceConfigurations(networks, interfacesByMAC)
Expect(err).ToNot(HaveOccurred())
//.........这里部分代码省略.........
开发者ID:vinodpanicker,项目名称:bosh-agent,代码行数:101,代码来源:interface_configuration_creator_test.go
示例19: init
func init() {
Describe("App", func() {
var (
baseDir string
agentConfPath string
agentConfJSON string
app App
)
BeforeEach(func() {
var err error
baseDir, err = ioutil.TempDir("", "go-agent-test")
Expect(err).ToNot(HaveOccurred())
err = os.Mkdir(filepath.Join(baseDir, "bosh"), os.ModePerm)
Expect(err).ToNot(HaveOccurred())
})
BeforeEach(func() {
agentConfPath = filepath.Join(baseDir, "bosh", "agent.json")
agentConfJSON = `{
"Infrastructure": { "Settings": { "Sources": [{ "Type": "CDROM", "FileName": "/fake-file-name" }] } }
}`
settingsPath := filepath.Join(baseDir, "bosh", "settings.json")
settingsJSON := `{
"agent_id": "my-agent-id",
"blobstore": {
"options": {
"bucket_name": "george",
"encryption_key": "optional encryption key",
"access_key_id": "optional access key id",
"secret_access_key": "optional secret access key"
},
"provider": "dummy"
},
"disks": {
"ephemeral": "/dev/sdb",
"persistent": {
"vol-xxxxxx": "/dev/sdf"
},
"system": "/dev/sda1"
},
"env": {
"bosh": {
"password": "some encrypted password"
}
},
"networks": {
"netA": {
"default": ["dns", "gateway"],
"ip": "ww.ww.ww.ww",
"dns": [
"xx.xx.xx.xx",
"yy.yy.yy.yy"
]
},
"netB": {
"dns": [
"zz.zz.zz.zz"
]
}
},
"Mbus": "https://vcap:[email protected]:6868",
"ntp": [
"0.north-america.pool.ntp.org",
"1.north-america.pool.ntp.org"
],
"vm": {
"name": "vm-abc-def"
}
}`
err := ioutil.WriteFile(settingsPath, []byte(settingsJSON), 0640)
Expect(err).ToNot(HaveOccurred())
})
JustBeforeEach(func() {
err := ioutil.WriteFile(agentConfPath, []byte(agentConfJSON), 0640)
Expect(err).ToNot(HaveOccurred())
logger := boshlog.NewLogger(boshlog.LevelNone)
fakefs := boshsys.NewOsFileSystem(logger)
app = New(logger, fakefs)
})
AfterEach(func() {
os.RemoveAll(baseDir)
})
It("Sets up device path resolver on platform specific to infrastructure", func() {
err := app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(err).ToNot(HaveOccurred())
Expect(app.GetPlatform().GetDevicePathResolver()).To(Equal(devicepathresolver.NewIdentityDevicePathResolver()))
})
//.........这里部分代码省略.........
开发者ID:mattcui,项目名称:bosh-agent,代码行数:101,代码来源:app_test.go
示例20: init
//.........这里部分代码省略.........
testTempDir string
)
BeforeEach(func() {
osFs, _ = createOsFs()
var err error
testTempDir, err = ioutil.TempDir("", "os_filesystem_test")
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
os.Remove(testTempDir)
})
Context("a temp root is set", func() {
BeforeEach(func() {
osFs.ChangeTempRoot(testTempDir)
})
It("creates temp files under that root", func() {
file, err := osFs.TempFile("some-file-prefix")
Expect(err).ToNot(HaveOccurred())
Expect(file.Name()).To(HavePrefix(filepath.Join(testTempDir, "some-file-prefix")))
})
It("creates temp directories under that root", func() {
dirName, err := osFs.TempDir("some-dir-prefix")
Expect(err).ToNot(HaveOccurred())
Expect(dirName).To(HavePrefix(filepath.Join(testTempDir, "some-dir-prefix")))
})
})
Context("no temp root is set and was initialized as a strict temp root", func() {
BeforeEach(func() {
osFs = NewOsFileSystemWithStrictTempRoot(boshlog.NewLogger(boshlog.LevelNone))
})
It("should eror", func() {
_, err := osFs.TempFile("some-prefix")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("ChangeTempRoot"))
_, err = osFs.TempDir("some-prefix")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("ChangeTempRoot"))
})
})
})
Describe("CopyFile", func() {
It("copies file", func() {
osFs, _ := createOsFs()
srcPath := "test_assets/test_copy_dir_entries/foo.txt"
dstFile, err := osFs.TempFile("CopyFileTestFile")
Expect(err).ToNot(HaveOccurred())
defer os.Remove(dstFile.Name())
err = osFs.CopyFile(srcPath, dstFile.Name())
fooContent, err := osFs.ReadFileString(dstFile.Name())
Expect(err).ToNot(HaveOccurred())
Expect(fooContent).To(Equal("foo\n"))
})
It("does not leak file descriptors", func() {
osFs, _ := createOsFs()
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:66,代码来源:os_file_system_test.go
注:本文中的github.com/cloudfoundry/bosh-utils/logger.NewLogger函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论