Skip to content

Commit

Permalink
support for COA logger config with private-config.yml
Browse files Browse the repository at this point in the history
```
# Log configuration is only available in private-config.yml
log:
  output: STDOUT # Use stdout to have log displayed in concourse, instead of a file. Default: File
  level: Debug # We don't need to customize this value, as it is set to debug by default. Valid values: Debug, Info, Warn and Error
  date-format: "-" # Disable date as we already have a timestamp in concourse. Default: "%Y-%m-%dT%H:%M:%S.%6N"
  ```
  • Loading branch information
o-orand committed May 4, 2023
1 parent 0e134b3 commit e8335ee
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/reference_dataset/config_repository/private-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---
# Log configuration is only available in private-config.yml
log:
output: STDOUT # Use stdout to have log displayed in concourse, instead of a file. Default: File
# level: Debug # We don't need to customize this value, as it is set to debug by default. Valid values: Debug, Info, Warn and Error
date-format: "-" # Disable date as we already have a timestamp in concourse. Default: "%Y-%m-%dT%H:%M:%S.%6N"
# you can override values from template_repository/shared-config.yml
#offline-mode:
# boshreleases: false # Default: false
Expand Down
8 changes: 6 additions & 2 deletions lib/coa_run_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ def self.included(base)
module ClassMethods
def logger
current_dir = File.dirname(__FILE__)
default_path = '..' #File.join('..', '..', '..', 'log')
default_path = '..' # File.join('..', '..', '..', 'log')
log_output = ENV.fetch('COA_LOG_OUTPUT', 'File')
log_filename = File.join(current_dir, ENV.fetch('COA_LOG_PATH', default_path), "coa_run_stdout.log")
Logger.new(log_filename)
log_filename = $stdout if log_output == 'STDOUT'
log_level = ENV.fetch('COA_LOG_LEVEL', 'Debug')
log_dateformat = ENV.fetch('COA_LOG_DATEFORMAT', Logger::Formatter.new.datetime_format)
Logger.new(log_filename, level: log_level, datetime_format: log_dateformat)
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/template_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
require 'fileutils'
require_relative 'pipeline_helpers'
require_relative 'active_support_deep_dup'
require_relative 'coa_run_logger'

class TemplateProcessor
attr_reader :root_deployment_name, :config, :context

include CoaRunLogger
def initialize(root_deployment_name, config = { dump_output: true, output_path: '/tmp' }, context = {})
@root_deployment_name = root_deployment_name
@context = context
Expand Down Expand Up @@ -50,11 +52,11 @@ def generate_pipeline_content(filename)
# raise NameError, "#{filename}: #{name_error}"
end

def write_pipeline_content_in_file(output, pipeline_name)
puts "Pipeline name #{pipeline_name}"
def write_pipeline_content_in_file(output, pipeline_filename)
puts "Generating pipeline. Filename: #{pipeline_filename}"
target_dir = File.join(config[:output_path], 'pipelines')
FileUtils.mkdir_p target_dir unless Dir.exist?(target_dir)
pipeline = File.new(File.join(target_dir, pipeline_name), 'w')
pipeline = File.new(File.join(target_dir, pipeline_filename), 'w')
pipeline << output
pipeline.close
pipeline
Expand Down Expand Up @@ -87,7 +89,7 @@ def load_context_into_a_binding
@context&.deep_dup&.each do |k, v|
new_binding.local_variable_set k.to_sym, v
end
puts "Local var: #{new_binding.local_variables}"
logger.debug { "Local var: #{new_binding.local_variables}" }
new_binding
end
end
15 changes: 15 additions & 0 deletions scripts/generate-depls.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#!/usr/bin/env ruby

require_relative '../lib/shared_pipeline_generator'
require 'yaml'

def configure_logging(options)
secrets_path = options[:secrets_path]
private_config_file = File.join(secrets_path, 'private-config.yml')
private_config = {}
YAML.load_file(private_config_file) || {} if File.exist? private_config_file
log_level = private_config.dig('log', 'level')
ENV["COA_LOG_LEVEL"] = log_level unless log_level.to_s.empty?
log_output = private_config.dig('log', 'output')
ENV["COA_LOG_OUTPUT"] = log_output unless log_output.to_s.empty?
log_date_format = private_config.dig('log', 'date-format')
ENV["COA_LOG_DATEFORMAT"] = log_date_format unless log_date_format.to_s.empty?
end

options = SharedPipelineGenerator::Parser.parse(ARGV)
puts "Parsed options: #{options}"
configure_logging(options)
pipeline_generator = SharedPipelineGenerator.new(options)
success = pipeline_generator.execute
exit 1 unless success
Expand Down
15 changes: 15 additions & 0 deletions scripts/generate-root-deployments.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#!/usr/bin/env ruby

require_relative '../lib/shared_pipeline_generator'
require 'yaml'

def configure_logging(options)
secrets_path = options[:secrets_path]
private_config_file = File.join(secrets_path, 'private-config.yml')
private_config = {}
YAML.load_file(private_config_file) || {} if File.exist? private_config_file
log_level = private_config.dig('log', 'level')
ENV["COA_LOG_LEVEL"] = log_level unless log_level.to_s.empty?
log_output = private_config.dig('log', 'output')
ENV["COA_LOG_OUTPUT"] = log_output unless log_output.to_s.empty?
log_date_format = private_config.dig('log', 'date-format')
ENV["COA_LOG_DATEFORMAT"] = log_date_format unless log_date_format.to_s.empty?
end

options = SharedPipelineGenerator::Parser.parse(ARGV)
puts "Parsed options: #{options}"
configure_logging(options)
pipeline_generator = SharedPipelineGenerator.new(options)
success = pipeline_generator.execute
exit 1 unless success
Expand Down

0 comments on commit e8335ee

Please sign in to comment.