timber 2.0.9 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77cca27158a28ec9275818a2efaba37229e2d121
4
- data.tar.gz: 5423ac901328f3c57811bfc1a7855970d798b55c
3
+ metadata.gz: d8f4370bada35338e39a28f00a5c1530175e285a
4
+ data.tar.gz: b15a814d3c4d6fdd557f7a509bc2452fd86a99ff
5
5
  SHA512:
6
- metadata.gz: b58fb47529e061305c0d178458bf2a5bc170610986492fd4a9573f1fae52ad85b5809f12ec2e2dea7b6553441d10a5d849c63cdfff0ae1cc573bf27e3a0f0d4b
7
- data.tar.gz: 7a9d4dcde4b68e23b15a62a2e607c76fb371dd313dd28a9d650607be12d3af3fb97e0f6e3ad273ae2ac46762025541d918c7ca065fd3ee045483b65ba75c5fb9
6
+ metadata.gz: eb512f1759ec51bcbeb28b3cfbbb193dc805cc55c403e48d1fa519fbed4012bebd00802d8467a8af2a0cc56dc5ba50bb27eb78109626d27b00e77e3f74994c58
7
+ data.tar.gz: b240d0b6062fc042676be8ab4e9fa89622efad45ccdee3514b102b53d83f0879a829617dbc9eac99372e22466030e088ef948a6bc80ad6dded4019cd031ecac8
data/lib/timber/config.rb CHANGED
@@ -29,6 +29,9 @@ module Timber
29
29
  # This is useful for debugging. This Sets a debug_logger to view internal Timber library
30
30
  # log messages. The default is `nil`. Meaning log to nothing.
31
31
  #
32
+ # See `debug_to_file` and `debug_to_stdout` for convenience methods that handle creating
33
+ # and setting the logger.
34
+ #
32
35
  # @example Rails
33
36
  # config.timber.debug_logger = ::Logger.new(STDOUT)
34
37
  # @example Everything else
@@ -37,6 +40,34 @@ module Timber
37
40
  @debug_logger
38
41
  end
39
42
 
43
+ # A convenience method for writing debug messages to a file.
44
+ #
45
+ # @example Rails
46
+ # config.timber.debug_to_file("#{Rails.root}/log/timber.log")
47
+ # @example Everything else
48
+ # Timber::Config.instance.debug_to_file("log/timber.log")
49
+ def debug_to_file(file_path)
50
+ unless File.exist? File.dirname path
51
+ FileUtils.mkdir_p File.dirname path
52
+ end
53
+ file = File.open file_path, "a"
54
+ file.binmode
55
+ file.sync = config.autoflush_log
56
+ file_logger = ::Logger.new(file)
57
+ self.debug_logger = file_logger
58
+ end
59
+
60
+ # A convenience method for writing debug messages to a file.
61
+ #
62
+ # @example Rails
63
+ # config.timber.debug_to_file("#{Rails.root}/log/timber.log")
64
+ # @example Everything else
65
+ # Timber::Config.instance.debug_to_file("log/timber.log")
66
+ def debug_to_stdout
67
+ stdout_logger = ::Logger.new(STDOUT)
68
+ self.debug_logger = stdout_logger
69
+ end
70
+
40
71
  # The environment your app is running in. Defaults to `RACK_ENV` and `RAILS_ENV`.
41
72
  # It should be rare that you have to set this. If the aforementioned env vars are not
42
73
  # set please do.
@@ -4,15 +4,16 @@ module Timber
4
4
  class System < Context
5
5
  @keyspace = :system
6
6
 
7
- attr_reader :pid
7
+ attr_reader :hostname, :pid
8
8
 
9
9
  def initialize(attributes)
10
- @pid = attributes[:pid] || raise(ArgumentError.new(":pid is required"))
10
+ @hostname = attributes[:hostname]
11
+ @pid = attributes[:pid]
11
12
  @pid = @pid.to_s
12
13
  end
13
14
 
14
15
  def as_json(_options = {})
15
- {pid: Timber::Util::Object.try(pid, :to_s)}
16
+ {hostname: hostname, pid: Timber::Util::Object.try(pid, :to_s)}
16
17
  end
17
18
  end
18
19
  end
@@ -1,3 +1,5 @@
1
+ require 'socket'
2
+
1
3
  module Timber
2
4
  # Represents a new log entry into the log. This is an intermediary class between
3
5
  # `Logger` and the log device that you set it up with.
@@ -26,7 +28,9 @@ module Timber
26
28
  @time_ms = options[:time_ms]
27
29
 
28
30
  context_snapshot = {} if context_snapshot.nil?
29
- system_context = Contexts::System.new(pid: Process.pid)
31
+ hostname = Socket.gethostname
32
+ pid = Process.pid
33
+ system_context = Contexts::System.new(hostname: hostname, pid: pid)
30
34
  context_snapshot[system_context.keyspace] = system_context.as_json
31
35
 
32
36
  @context_snapshot = context_snapshot
@@ -1,3 +1,3 @@
1
1
  module Timber
2
- VERSION = "2.0.9"
2
+ VERSION = "2.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.