Skip to content

Commit

Permalink
Logging configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiamarchi committed Jun 24, 2014
1 parent 2a77c10 commit 6e44ced
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ that uses it, and uses bundler to execute Vagrant:
```
$ bundle exec vagrant up --provider=openstack
```

## Logging

To enable all Vagrant logs set environment variable `VAGRANT_LOG` to the desire
log level (for instance `VAGRANT_LOG=debug`). If you want only Openstack provider
logs use the variable `VAGRANT_OPENSTACK_LOG`. if both variables are set, `VAGRANT_LOG`
takes precedence.
12 changes: 9 additions & 3 deletions source/lib/vagrant-openstack-provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ def self.init_logging
# This means that the logging constant wasn't found,
# which is fine. We just keep `level` as `nil`. But
# we tell the user.
level = nil
begin
level = Log4r.const_get(ENV['VAGRANT_OPENSTACK_LOG'].upcase)
rescue NameError
level = nil
end
end

# Some constants, such as "true" resolve to booleans, so the
# above error checking doesn't catch it. This will check to make
# sure that the log level is an integer, as Log4r requires.
level = nil unless level.is_a?(Integer)

# Set the logging level on all "vagrant" namespaced
# Set the logging level
# logs as long as we have a valid level.
if level
logger = Log4r::Logger.new('vagrant_openstack')
logger.outputters = Log4r::Outputter.stderr
out = Log4r::Outputter.stdout
out.formatter = Log4r::PatternFormatter.new(pattern: '%d | %5l | %m', date_pattern: '%Y-%m-%d %H:%M')
logger.outputters = out
logger.level = level
end
end
Expand Down

0 comments on commit 6e44ced

Please sign in to comment.