Module: SgtnClient

Extended by:
Logging
Defined in:
lib/sgtn-client/api/t.rb,
lib/sgtn-client/api/source.rb,
lib/sgtn-client/core/config.rb,
lib/sgtn-client/sgtn-client.rb,
lib/sgtn-client/core/logging.rb,
lib/sgtn-client/util/file-util.rb,
lib/sgtn-client/api/translation.rb,
lib/sgtn-client/core/exceptions.rb,
lib/sgtn-client/util/cache-util.rb,
lib/sgtn-client/util/locale-util.rb,
lib/sgtn-client/util/validate-util.rb,
lib/sgtn-client/formatters/plurals/plural_formatter.rb

Overview

Copyright 2022 VMware, Inc. SPDX-License-Identifier: EPL-2.0

Defined Under Namespace

Modules: Configuration, Core, Exceptions, Formatters, Logging Classes: CacheUtil, Config, FileUtil, LocaleUtil, Source, T, Translation, ValidateUtil

Constant Summary collapse

LOGFILE_SHIFT_AGE =
4
DEFAULT_LOCALES =
['en', 'de', 'es', 'fr', 'ko', 'ja', 'zh-Hans', 'zh-Hant']
MAP_LOCALES =
{
  "zh-CN" =>"zh-Hans",
  "zh-TW" =>"zh-Hant",
  "zh-Hans-CN" =>"zh-Hans",
  "zh-Hant-TW" =>"zh-Hant",
}

Class Method Summary collapse

Methods included from Logging

log_event, logger

Class Method Details

.configure(options = {}, &block) ⇒ Object



27
28
29
# File 'lib/sgtn-client/sgtn-client.rb', line 27

def configure(options = {}, &block)
SgtnClient::Config.configure(options, &block)
end

.load(*args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sgtn-client/sgtn-client.rb', line 32

def load(*args)
      # load configuration file
      begin
        SgtnClient::Config.load(args[0], args[1])
        SgtnClient::ValidateUtil.validate_config()
      rescue => exception
        file = File.open('./error.log', 'a')
        file.sync = true
        log = Logger.new(file)
        log.error exception.message
      end

      # create log file
      file = './sgtnclient_d.log'
      SgtnClient.logger.debug "[Client][load]create log file=#{file}"
      if args[2] != nil
            file = args[2]
      end
      file = File.open(file, 'a')
      file.sync = true
      SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)

      # Set log level for sandbox mode
      env = SgtnClient::Config.default_environment
      mode = SgtnClient::Config.configurations[env]["mode"]
      SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
      if mode == 'sandbox'
            SgtnClient.logger.level = Logger::DEBUG
      else 
            SgtnClient.logger.level = Logger::INFO
      end

      # initialize cache
      disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
      SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
      if disable_cache != nil
            SgtnClient::Core::Cache.initialize(disable_cache)
      else
            SgtnClient::Core::Cache.initialize()
      end
end

.loggerObject



74
75
76
# File 'lib/sgtn-client/sgtn-client.rb', line 74

def logger
      SgtnClient::Config.logger
end

.logger=(log) ⇒ Object



78
79
80
# File 'lib/sgtn-client/sgtn-client.rb', line 78

def logger=(log)
      SgtnClient::Config.logger = log
end