timber 2.0.9 → 2.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timber/config.rb +31 -0
- data/lib/timber/contexts/system.rb +4 -3
- data/lib/timber/log_entry.rb +5 -1
- data/lib/timber/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8f4370bada35338e39a28f00a5c1530175e285a
|
4
|
+
data.tar.gz: b15a814d3c4d6fdd557f7a509bc2452fd86a99ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
@
|
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
|
data/lib/timber/log_entry.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/timber/version.rb
CHANGED