Skip to content

Commit 04f2acb

Browse files
committed
initial commit
1 parent 321d8d9 commit 04f2acb

File tree

16 files changed

+302
-35
lines changed

16 files changed

+302
-35
lines changed

.github/workflows/rubocop.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Rubocop
2+
on: [push, pull_request]
3+
jobs:
4+
rubocop:
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
os: [ubuntu-latest]
9+
ruby: [2.7]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: ruby/setup-ruby@v1
14+
with:
15+
ruby-version: ${{ matrix.ruby }}
16+
bundler-cache: true
17+
- name: Install Rubocop
18+
run: gem install rubocop code-scanning-rubocop
19+
- name: Rubocop run --no-doc
20+
run: |
21+
bash -c "
22+
rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
23+
[[ $? -ne 2 ]]
24+
"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Gemfile.lock
2+
.rspec_status

.rubocop.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Layout/LineLength:
2+
Max: 120
3+
Metrics/MethodLength:
4+
Max: 100
5+
Metrics/ClassLength:
6+
Max: 1500
7+
Metrics/BlockLength:
8+
Max: 100
9+
Metrics/CyclomaticComplexity:
10+
Max: 10
11+
Style/Documentation:
12+
Enabled: false
13+
AllCops:
14+
TargetRubyVersion: 2.5
15+
NewCops: enable
16+
SuggestExtensions: false
17+
Style/FrozenStringLiteralComment:
18+
Enabled: false

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Telemetry::Logger
2+
3+
## v0.1.0
4+
Initial release

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ We have some general guidelines towards contributing to this project.
1818

1919
### Languages
2020

21-
*Lua*
21+
*Ruby*
2222

2323
## Pull Requests
2424

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec
4+
group :test do
5+
gem 'rake'
6+
gem 'rspec'
7+
gem 'rspec_junit_formatter'
8+
gem 'rubocop'
9+
gem 'simplecov'
10+
end

NOTICE.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Insert Project Name Here>
1+
Telemetry::Logger
22
Copyright 2021 Optum
33

44
Project Description:
55
====================
6-
<Short description of your project>
6+
A generic gem to handle logging for all other telemetry gems
77

88
Author(s):
9-
<List the names and GitHub IDs of the original project authors>
9+
Esity

README.md

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
1-
# Welcome to your new OSS project
2-
3-
This project currently has the base documentation files required. Replace this
4-
file with your own README.md.
5-
6-
## Files included
7-
8-
**CODE_OF_CONDUCT.md**
9-
10-
Use without changes
11-
12-
**INDIVIDUAL_CONTRIBUTOR_LICENSE.md**
13-
14-
Use without changes
15-
16-
**CONTRIBUTING.md**
17-
18-
This file has some portions that are required and others that can be customized.
19-
Customize the Coding Standards section to mention the languages used by your project.
20-
Feel free to add any rules and requirements that you would like people to follow
21-
when contributing to your project.
22-
23-
**NOTICE.txt**
24-
25-
This file is needed if your project is licensed under the Apache 2.0 license.
26-
If you are using this license, fill it out according to the prompts. Otherwise,
27-
delete this file.
28-
29-
## Additional Repo Updates
30-
31-
Make sure that you have a project description and appropriate repository topics.
1+
# Telemetry::Logger
2+
A generic gem to handle logging for all other telemetry gems
3+
4+
Example
5+
```ruby
6+
Telemetry::Logger.setup(level: 'info')
7+
Telemetry::Logger.info 'test info'
8+
Telemetry::Logger.debug 'test debug'
9+
Telemetry::Logger.warn 'test warn'
10+
Telemetry::Logger.error 'test error'
11+
Telemetry::Logger.fatal 'test fatal'
12+
Telemetry::Logger.unknown 'test unknown'
13+
```

lib/telemetry/logger.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'telemetry/logger/version'
2+
require 'telemetry/logger/defaults'
3+
require 'telemetry/logger/builder'
4+
require 'telemetry/logger/methods'
5+
6+
module Telemetry
7+
module Logger
8+
class << self
9+
include Telemetry::Logger::Defaults
10+
include Telemetry::Logger::Methods
11+
include Telemetry::Logger::Builder
12+
13+
def setup(level: 'info', **opts)
14+
output(**opts)
15+
self.log_level = level
16+
log_format(**opts)
17+
end
18+
end
19+
end
20+
end

lib/telemetry/logger/builder.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module Telemetry
2+
module Logger
3+
module Builder
4+
def format(include_pid: false, **)
5+
log.formatter = proc do |severity, datetime, _progname, msg|
6+
string = "[#{datetime}]"
7+
string.concat("[#{::Process.pid}]") if include_pid
8+
string.concat(" #{severity} #{msg}\n")
9+
string
10+
end
11+
end
12+
13+
def log
14+
@log ||= output
15+
end
16+
17+
def output(**options)
18+
@log = ::Logger.new(options[:log_file] || $stdout)
19+
end
20+
21+
def level
22+
log.level
23+
end
24+
25+
def log_level=(level)
26+
log.level = case level
27+
when 'trace', 'debug'
28+
::Logger::DEBUG
29+
when 'info'
30+
::Logger::INFO
31+
when 'warn'
32+
::Logger::WARN
33+
when 'error'
34+
::Logger::ERROR
35+
when 'fatal'
36+
::Logger::FATAL
37+
when nil
38+
42
39+
else
40+
if level.is_a? Integer
41+
level
42+
else
43+
0
44+
end
45+
end
46+
@log = log
47+
end
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)