Skip to content

Commit c0f39f1

Browse files
committed
Pull request #84: Write log messages to file
Merge in COSMOSEE/base from log-messages-file to master * commit '997ad7a48b2f9b64f3d7402c95bc06283ec8cbc5': Write log messages to file Fix text log filenames
2 parents 1a3d4c7 + 997ad7a commit c0f39f1

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

cosmos/lib/cosmos/logs/log_writer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def initialize(
6060
cycle_minute = nil,
6161
redis_topic: nil
6262
)
63-
6463
@remote_log_directory = remote_log_directory
6564
@logging_enabled = ConfigParser.handle_true_false(logging_enabled)
6665
@cycle_time = ConfigParser.handle_nil(cycle_time)

cosmos/lib/cosmos/logs/packet_log_writer.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ def initialize(
5252
cycle_minute = nil,
5353
redis_topic: nil
5454
)
55-
super(
56-
remote_log_directory,
57-
logging_enabled,
58-
cycle_time,
59-
cycle_size,
60-
cycle_hour,
61-
cycle_minute,
62-
redis_topic: redis_topic
63-
)
55+
super(
56+
remote_log_directory,
57+
logging_enabled,
58+
cycle_time,
59+
cycle_size,
60+
cycle_hour,
61+
cycle_minute,
62+
redis_topic: redis_topic
63+
)
6464
@label = label
6565
@index_file = nil
6666
@index_filename = nil

cosmos/lib/cosmos/logs/text_log_writer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def write_entry(time_nsec_since_epoch, data)
5454
end
5555

5656
def s3_filename
57-
"#{first_timestamp}__#{last_timestamp}__notifications" + extension
57+
# Put the name of the redis topic in the filename, but remove the scope
58+
# because we're already in a directory with the scope name
59+
split_index = @redis_topic.index("__") + 2
60+
topic_name = @redis_topic[split_index, @redis_topic.length - split_index]
61+
"#{first_timestamp}__#{last_timestamp}__#{topic_name}" + extension
5862
end
5963

6064
def extension

cosmos/lib/cosmos/models/scope_model.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ def deploy(gem_path, variables)
6666
microservice.deploy(gem_path, variables)
6767
Logger.info "Configured microservice #{microservice_name}"
6868

69+
# COSMOS Log Microservice
70+
microservice_name = "#{@scope}__COSMOS__LOG"
71+
microservice = MicroserviceModel.new(
72+
name: microservice_name,
73+
cmd: ["ruby", "text_log_microservice.rb", microservice_name],
74+
work_dir: '/cosmos/lib/cosmos/microservices',
75+
options: [
76+
# The following options are optional (600 and 50_000_000 are the defaults)
77+
# ["CYCLE_TIME", "600"], # Keep at most 10 minutes per log
78+
# ["CYCLE_SIZE", "50_000_000"] # Keep at most ~50MB per log
79+
],
80+
topics: ["#{@scope}__cosmos_log_messages"],
81+
scope: @scope)
82+
microservice.create
83+
microservice.deploy(gem_path, variables)
84+
Logger.info "Configured microservice #{microservice_name}"
85+
6986
# Notification Log Microservice
7087
microservice_name = "#{@scope}__NOTIFICATION__LOG"
7188
microservice = MicroserviceModel.new(

cosmos/lib/cosmos/utilities/logger.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def self.instance
184184
protected
185185
def log_metric(data, scope:, &block)
186186
@mutex.synchronize do
187+
data[:time] = Time.now.to_nsec_from_epoch
187188
data[:@timestamp] = Time.now.xmlschema(3)
188189
data[:microservice_name] = @microservice_name if @microservice_name
189190
data[:detail] = @detail_string if @detail_string
@@ -204,7 +205,7 @@ def log_metric(data, scope:, &block)
204205

205206
def log_message(severity_string, message, scope:, &block)
206207
@mutex.synchronize do
207-
data = { '@timestamp' => Time.now.xmlschema(3), severity: severity_string }
208+
data = { time: Time.now.to_nsec_from_epoch, '@timestamp' => Time.now.xmlschema(3), severity: severity_string }
208209
data[:microservice_name] = @microservice_name if @microservice_name
209210
data[:detail] = @detail_string if @detail_string
210211
if block_given?

0 commit comments

Comments
 (0)