forked from arunn/console_detective
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Receive logger as param * Fix tagger * Rename * Remove Pry
- Loading branch information
Showing
18 changed files
with
121 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
print Gem::Specification::load('pier_logging.gemspec').version.to_s | ||
print Gem::Specification::load('pier_console_detective.gemspec').version.to_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
require "pier_console_detective/version" | ||
require "pier_console_detective/mod_attr_accessor" | ||
require "logger" | ||
|
||
module ConsoleDetective | ||
extend ConsoleDetective::ModAttrAccessor | ||
module PierConsoleDetective | ||
extend PierConsoleDetective::ModAttrAccessor | ||
|
||
def self.setup | ||
yield self | ||
end | ||
|
||
# log_file_name is a string/file that mentions the location and name of the file where log will be written. | ||
# default value is log/console.log | ||
mod_attr_accessor :log_file_name, "log/console.log" | ||
# logger is a logger | ||
# default value is Logger.new(STDOUT) | ||
mod_attr_accessor :logger, Logger.new(STDOUT) | ||
|
||
# log_tags is a lambda outputting the tag to tag the log entry | ||
# log_tag is a lambda outputting the tag to tag the log entry | ||
# default value is the ENV['USER'] | ||
mod_attr_accessor :log_tags, -> { ENV['USER'] } | ||
mod_attr_accessor :log_tag, -> { ENV['USER'] } | ||
|
||
# log_format is a lambda which takes tag and command as input and outputs the format in which the log will be entered in the log file | ||
# default format is a hash of format { :tag => <tag>, :command => <command> } | ||
mod_attr_accessor :log_format, -> (tag, command) { { tag: tag, command: command } } | ||
|
||
# tag_memoization is a boolean to mention if the tag should be memoized or not. | ||
# default is true | ||
mod_attr_accessor :tag_memoization, true | ||
end | ||
|
||
require 'pier_console_detective/utils' | ||
require 'pier_console_detective/irb' | ||
require 'pier_console_detective/pry' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
module ConsoleDetective | ||
module PierConsoleDetective | ||
module IrbLogger | ||
def evaluate(*args, **kw) | ||
ConsoleDetective::Utils.log_command(args.first.chomp) | ||
super(*args, **kw) | ||
input = args.first.chomp | ||
PierConsoleDetective::Utils.log_command(input) | ||
output = super(*args, **kw) | ||
PierConsoleDetective::Utils.log_command_output(input, output) | ||
output | ||
end | ||
end | ||
end | ||
|
||
IRB::Context.prepend(ConsoleDetective::IrbLogger) if defined?(IRB::Context) | ||
IRB::Context.prepend(PierConsoleDetective::IrbLogger) if defined?(IRB::Context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
require 'logger' | ||
|
||
module ConsoleDetective | ||
module PierConsoleDetective | ||
module Utils | ||
LOGGER_PROC = ->(command) { ConsoleDetective::Utils.logger.info(ConsoleDetective.log_format.call(ConsoleDetective::Utils.get_tag, command)) } | ||
LOGGER_PROC = ->(message, data) do | ||
PierConsoleDetective::Utils.logger.info(message, { | ||
data: data, | ||
tag: PierConsoleDetective::Utils.get_tag, | ||
}) | ||
end | ||
|
||
def self.logger | ||
@logger ||= Logger.new(ConsoleDetective.log_file_name) | ||
@logger ||= PierConsoleDetective.logger | ||
end | ||
|
||
def self.get_tag | ||
return @tag if ConsoleDetective.tag_memoization && @tag | ||
@tag = ConsoleDetective.log_tags.call | ||
return @tag if PierConsoleDetective.tag_memoization && @tag | ||
@tag = PierConsoleDetective.log_tag.call | ||
end | ||
|
||
def self.log_command(command, immediately: false) | ||
return Thread.new { ConsoleDetective::Utils::LOGGER_PROC.call(command) } unless immediately | ||
ConsoleDetective::Utils::LOGGER_PROC.call(command) | ||
return Thread.new { | ||
PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", { | ||
command: command.inspect | ||
}) | ||
} unless immediately | ||
PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", { | ||
command: command.inspect | ||
}) | ||
end | ||
|
||
def self.log_command_output(command, output, immediately: false) | ||
return Thread.new { | ||
PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", { | ||
command: command.inspect, | ||
output: output.inspect, | ||
}) | ||
} unless immediately | ||
PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", { | ||
command: command.inspect, | ||
output: output.inspect, | ||
}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module ConsoleDetective | ||
VERSION = "0.2.0".freeze | ||
module PierConsoleDetective | ||
VERSION = "0.3.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ require_relative 'lib/pier_console_detective/version' | |
|
||
Gem::Specification.new do |spec| | ||
spec.name = "pier_console_detective" | ||
spec.version = ConsoleDetective::VERSION | ||
spec.version = PierConsoleDetective::VERSION | ||
spec.authors = ["ArunkumarN"] | ||
spec.email = ["[email protected]"] | ||
spec.licenses = ["MIT"] | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.