Skip to content

Commit

Permalink
feat(logger): add logs messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasalexandre9 committed May 2, 2024
1 parent 6eb29b1 commit a64418d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ def send_schema(force: false)
@container.resolve(:schema_file_hash).get('value') == schema[:meta][:schemaFileHash]

if !schema_is_know || force
# Logger::log('Info', 'schema was updated, sending new version');
client = ForestAdminAgent::Http::ForestAdminApiRequester.new
client.post('/forest/apimaps', schema.to_json)
schema_file_hash_cache = FileCache.new('app', @options[:cache_dir].to_s, TTL_SCHEMA)
schema_file_hash_cache.get_or_set 'value' do
schema[:meta][:schemaFileHash]
end
@container.register(:schema_file_hash, schema_file_hash_cache)
ForestAdminAgent::Facades::Container.logger.log('Info', 'schema was updated, sending new version')
else
@container.resolve(:logger)
# TODO: Logger::log('Info', 'Schema was not updated since last run');
ForestAdminAgent::Facades::Container.logger.log('Info', 'Schema was not updated since last run')
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def self.invalidate_cache(id_cache = nil)

cache.delete(id_cache) unless cache.get(id_cache).nil?

# TODO: HANDLE LOGGER
# logger.debug("Invalidating #{id_cache} cache..")
ForestAdminAgent::Facades::Container.logger.log('Info', "Invalidating #{id_cache} cache..")
end

def can?(action, collection, allow_fetch: false)
Expand Down Expand Up @@ -66,13 +65,17 @@ def can_chart?(parameters)

# still not allowed - throw forbidden message
unless is_allowed
# TODO: HANDLE LOGGER
# logger.debug("User #{caller.id} cannot retrieve chart on rendering #{caller.rendering_id}")
ForestAdminAgent::Facades::Container.logger.log(
'Debug',
"User #{caller.id} cannot retrieve chart on rendering #{caller.rendering_id}"
)
raise ForbiddenError, "You don't have permission to access this collection."
end

# TODO: HANDLE LOGGER
# logger.debug("User #{caller.id} can retrieve chart on rendering #{caller.rendering_id}")
ForestAdminAgent::Facades::Container.logger.log(
'Debug',
"User #{caller.id} can retrieve chart on rendering #{caller.rendering_id}"
)

is_allowed
end
Expand All @@ -93,8 +96,10 @@ def can_smart_action?(request, collection, filter, allow_fetch: true)
)

smart_action_approval.can_execute?
# TODO: HANDLE LOGGER
# logger.debug("User #{user_data[:roleId]} is #{is_allowed ? '' : 'not'} allowed to perform #{action['name']}")
ForestAdminAgent::Facades::Container.logger.log(
'Debug',
"User #{user_data[:roleId]} is #{is_allowed ? "" : "not"} allowed to perform #{action["name"]}"
)
end

def get_scope(collection)
Expand All @@ -120,8 +125,7 @@ def get_user_data(user_id)
users[user[:id].to_s] = user
end

# TODO: HANDLE LOGGER
# logger.debug('Refreshing user permissions cache')
ForestAdminAgent::Facades::Container.logger.log('Debug', 'Refreshing user permissions cache')

users
end[user_id.to_s]
Expand All @@ -146,8 +150,7 @@ def get_collections_permissions_data(force_fetch: false)
collections[name] = decode_crud_permissions(collection).merge(decode_action_permissions(collection))
end

# TODO: HANDLE LOGGER
# logger.debug('Fetching environment permissions')
ForestAdminAgent::Facades::Container.logger.log('Debug', 'Fetching environment permissions')

collections
end
Expand All @@ -164,8 +167,10 @@ def get_chart_data(rendering_id, force_fetch: false)
stat_hash << "#{stat[:type]}:#{array_hash(stat)}"
end

# TODO: HANDLE LOGGER
# logger.debug("Loading rendering permissions for rendering #{rendering_id}")
ForestAdminAgent::Facades::Container.logger.log(
'Debug',
"Loading rendering permissions for rendering #{rendering_id}"
)

stat_hash
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def self.get_serialized_schema(datasource)
schema = if schema_path && File.exist?(schema_path)
JSON.parse(File.read(schema_path), { symbolize_names: true })
else
# TODO: Logger::log('Warn', 'The .forestadmin-schema.json file doesn\'t exist')
ForestAdminAgent::Facades::Container.logger.log(
'Warn',
'The .forestadmin-schema.json file doesn\'t exist'
)

{
meta: meta(Digest::SHA1.hexdigest('')),
collections: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def exception_handler(exception)
}

data[:errors][0][:data] = exception.try(:data)
end

# TODO: IMPLEMENT LOGGING
# if Facades::Container.cache(:is_production)
# end
unless Facades::Container.cache(:is_production)
ForestAdminAgent::Facades::Container.logger.log('Debug', exception.full_message)
end

render json: data, status: exception.try(:status)
Expand Down

0 comments on commit a64418d

Please sign in to comment.