# # Fluentd # # Copyright (C) 2011 FURUHASHI Sadayuki # # 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. # require 'optparse' require 'fluent/log' require 'fluent/env' require 'fluent/version' op = OptionParser.new op.version = Fluent::VERSION # default values config_path = Fluent::DEFAULT_CONFIG_PATH plugin_dirs = [Fluent::DEFAULT_PLUGIN_DIR] log_level = Fluent::Log::LEVEL_INFO log_file = nil daemonize = false libs = [] setup_path = nil chuser = nil chgroup = nil op.on('-s', "--setup [DIR=#{File.dirname(Fluent::DEFAULT_CONFIG_PATH)}]", "install sample configuration file to the directory") {|s| setup_path = s || File.dirname(Fluent::DEFAULT_CONFIG_PATH) } op.on('-c', '--config PATH', "config flie path (default: #{config_path})") {|s| config_path = s } op.on('-p', '--plugin DIR', "add plugin directory") {|s| plugin_dirs << s } op.on('-I PATH', "add library path") {|s| $LOAD_PATH << s } op.on('-r NAME', "load library") {|s| libs << s } op.on('-d', '--daemon PIDFILE', "daemonize fluent process") {|s| daemonize = s } op.on('--user USER', "change user") {|s| chuser = s } op.on('--group GROUP', "change group") {|s| chgroup = s } op.on('-o', '--log PATH', "log file path") {|s| log_file = s } op.on('-v', '--verbose', "increment verbose level (-v: debug, -vv: trace)", TrueClass) {|b| if b case log_level when Fluent::Log::LEVEL_INFO log_level = Fluent::Log::LEVEL_DEBUG when Fluent::Log::LEVEL_DEBUG log_level = Fluent::Log::LEVEL_TRACE end end } (class<config_path, :error=>$!.to_s $log.debug_backtrace # also STDOUT if log_out != STDOUT console = Fluent::Log.new(STDOUT, log_level).enable_debug console.error "config error", :file=>config_path, :error=>$!.to_s console.debug_backtrace end exit 1 rescue $log.error "unexpected error", :error=>$!.to_s $log.error_backtrace # also STDOUT if log_out != STDOUT console = Fluent::Log.new(STDOUT, log_level).enable_debug console.error "unexpected error", :error=>$!.to_s console.error_backtrace end exit 1 end