canvas_oss-event 0.1.0.pre.alpha.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +35 -0
- data/.travis.yml +28 -0
- data/Gemfile +6 -0
- data/LICENSE.CECILL-EN +518 -0
- data/LICENSE.CECILL-FR +548 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/canvas_oss-event.gemspec +44 -0
- data/lib/canvas_oss/event/version.rb +20 -0
- data/lib/canvas_oss/event.rb +98 -0
- metadata +120 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
# Copyright 2017-10-27
|
2
|
+
# Remy BOISSEZON boissezon.remy@gmail.com
|
3
|
+
# Valentin PRODHOMME valentin@prodhomme.me
|
4
|
+
# Dylan TROLES chill3d@protonmail.com
|
5
|
+
# Alexandre ZANNI alexandre.zanni@engineer.com
|
6
|
+
#
|
7
|
+
# This software is governed by the CeCILL license under French law and
|
8
|
+
# abiding by the rules of distribution of free software. You can use,
|
9
|
+
# modify and/ or redistribute the software under the terms of the CeCILL
|
10
|
+
# license as circulated by CEA, CNRS and INRIA at the following URL
|
11
|
+
# "http://www.cecill.info".
|
12
|
+
#
|
13
|
+
# The fact that you are presently reading this means that you have had
|
14
|
+
# knowledge of the CeCILL license and that you accept its terms.
|
15
|
+
|
16
|
+
require 'canvas_oss/event/version'
|
17
|
+
require 'syslog/logger'
|
18
|
+
|
19
|
+
module CanvasOss
|
20
|
+
module Event
|
21
|
+
# Class that log message using syslog
|
22
|
+
# @example Create connection, send warning log, and close connection
|
23
|
+
# example_log = CanvasOss::Event::Logger.new('canvas_web', 1)
|
24
|
+
# example_log.log('warn', 'This is a warning log text')
|
25
|
+
# example_log.close
|
26
|
+
# @author Dylan TROLES
|
27
|
+
class Logger
|
28
|
+
# Table of Syslog facilities constants
|
29
|
+
FACILITIES = [Syslog::LOG_LOCAL0, Syslog::LOG_LOCAL1, Syslog::LOG_LOCAL2,
|
30
|
+
Syslog::LOG_LOCAL3, Syslog::LOG_LOCAL4, Syslog::LOG_LOCAL5,
|
31
|
+
Syslog::LOG_LOCAL6, Syslog::LOG_LOCAL7].freeze
|
32
|
+
# Initialize Syslog::Logger class with a private call to {#connect}.
|
33
|
+
# @param program_name [String] This parameter is the name of the programname in syslog
|
34
|
+
# @param facility [Integer] Number of the Syslog facility local, where the integer is the postion of the facility in {CanvasOss::Event::Logger::FACILITIES} array
|
35
|
+
# @example
|
36
|
+
# example_log = CanvasOss::Event::Logger.new('canvas_web', 3) # 3 for Syslog::LOG_LOCAL3
|
37
|
+
def initialize(program_name, facility)
|
38
|
+
connect(program_name, facility)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Send logs thrue Syslog connection
|
42
|
+
# @param severity [String] Severity of the log (unknown, error, warn, info, debug)
|
43
|
+
# @param message [String] Content of the log
|
44
|
+
# @example
|
45
|
+
# example_log.log('warn', 'This is a warning log text')
|
46
|
+
# example_log.log('info', 'This is a info log text')
|
47
|
+
def log(severity, message)
|
48
|
+
raise ArgumentError, 'Message must be a String' unless message.is_a?(String)
|
49
|
+
begin
|
50
|
+
case severity
|
51
|
+
when 'alert'
|
52
|
+
@log.unknown '[Alert] : ' + message
|
53
|
+
when 'error'
|
54
|
+
@log.error '[Error] : ' + message
|
55
|
+
when 'warn'
|
56
|
+
@log.warn '[Warning] : ' + message
|
57
|
+
when 'info'
|
58
|
+
@log.info '[Info] : ' + message
|
59
|
+
when 'debug'
|
60
|
+
@log.debug '[Debug] : ' + message
|
61
|
+
else
|
62
|
+
raise "You've provided a false severity name. Choose between : alert,
|
63
|
+
error, warn, info, debug."
|
64
|
+
end
|
65
|
+
rescue RuntimeError => exception
|
66
|
+
raise "#{exception}. Syslog opened status : #{Syslog::Logger.syslog.opened?} "
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Close connection if there is one opened. If not, raise error.
|
71
|
+
def close
|
72
|
+
begin
|
73
|
+
Syslog::Logger.syslog.close
|
74
|
+
rescue RuntimeError => exception
|
75
|
+
raise "There is no Syslog connection to close : #{exception}"
|
76
|
+
end
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# Initialize Syslog::Logger class. Called by {#initialize}.
|
83
|
+
# @param program_name [String] This parameter is the name of the programname in syslog
|
84
|
+
# @param facility [Integer] Number of the Syslog facility local, where the integer is the postion of the facility in {CanvasOss::Event::Logger::FACILITIES} array
|
85
|
+
# @example
|
86
|
+
# example_log = CanvasOss::Event::Logger.new('canvas_web', 3) # 3 for Syslog::LOG_LOCAL3
|
87
|
+
def connect(program_name, facility)
|
88
|
+
raise ArgumentError, "You need to provide a number between 0 and #{FACILITIES.length - 1}" unless facility.is_a?(Integer) && facility.between?(0, FACILITIES.length - 1)
|
89
|
+
raise ArgumentError, 'Program name must be a String' unless program_name.is_a?(String)
|
90
|
+
begin
|
91
|
+
@log = Syslog::Logger.new(program_name, FACILITIES[facility])
|
92
|
+
rescue StandardError => exception
|
93
|
+
raise "Syslog connection has failed : #{exception}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: canvas_oss-event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre.alpha.pre.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Remy"
|
8
|
+
- BOISSEZON'
|
9
|
+
- "'Valentin"
|
10
|
+
- PRODHOMME'
|
11
|
+
- "'Dylan"
|
12
|
+
- TROLES'
|
13
|
+
- "'Alexandre"
|
14
|
+
- ZANNI'
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
type: :development
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: minitest
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: syslog-logger
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
type: :runtime
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
description: A little API to send logs to Syslog
|
77
|
+
email:
|
78
|
+
- boissezon.remy@gmail.com
|
79
|
+
- valentin@prodhomme.me
|
80
|
+
- chill3d@protonmail.com
|
81
|
+
- alexandre.zanni@engineer.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- ".rubocop.yml"
|
87
|
+
- ".travis.yml"
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.CECILL-EN
|
90
|
+
- LICENSE.CECILL-FR
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- canvas_oss-event.gemspec
|
94
|
+
- lib/canvas_oss/event.rb
|
95
|
+
- lib/canvas_oss/event/version.rb
|
96
|
+
homepage: https://github.com/canvas-oss/canvas-event
|
97
|
+
licenses:
|
98
|
+
- CECILL-2.1
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.4.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 1.3.1
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.7.6
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: API for CANVAS Log system
|
120
|
+
test_files: []
|