Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
83dc0b82
Commit
83dc0b82
authored
9 years ago
by
Rodrigo Nascimento
Browse files
Options
Downloads
Patches
Plain Diff
Init the class Logger for server logging
parent
483b95bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/rocketchat-logger/package.js
+6
-1
6 additions, 1 deletion
packages/rocketchat-logger/package.js
packages/rocketchat-logger/server.coffee
+114
-0
114 additions, 0 deletions
packages/rocketchat-logger/server.coffee
with
120 additions
and
1 deletion
packages/rocketchat-logger/package.js
+
6
−
1
View file @
83dc0b82
...
...
@@ -8,8 +8,13 @@ Package.describe({
Package
.
onUse
(
function
(
api
)
{
api
.
versionsFrom
(
'
1.0
'
);
api
.
use
(
'
coffeescript
'
,
'
client
'
);
api
.
use
(
'
coffeescript
'
);
api
.
use
(
'
logging
'
);
api
.
use
(
'
nooitaf:colors
'
);
api
.
use
(
'
templating
'
,
'
client
'
,
{
weak
:
true
});
api
.
addFiles
(
'
logger.coffee
'
,
'
client
'
);
api
.
addFiles
(
'
server.coffee
'
,
'
server
'
);
api
.
export
(
'
Logger
'
);
});
This diff is collapsed.
Click to expand it.
packages/rocketchat-logger/server.coffee
0 → 100644
+
114
−
0
View file @
83dc0b82
LoggerManager
=
new
class
loggers
:
{}
@
Logger
=
class
Logger
defaultTypes
:
log
:
'blue'
warn
:
'magenta'
error
:
'red'
constructor
:
(
@
name
,
@
config
=
{})
->
if
LoggerManager
.
loggers
[
@
name
]
?
LoggerManager
.
loggers
[
@
name
].
warn
'Duplicated instance'
return
LoggerManager
.
loggers
[
@
name
]
for
type
,
color
of
@
defaultTypes
do
(
type
,
color
)
=>
@
[
type
]
=
(
args
...)
=>
@
_log
type
:
type
arguments
:
args
if
@
config
.
methods
?
for
method
,
type
of
@
config
.
methods
do
(
method
,
type
)
=>
if
@
[
method
]
?
@
warn
"Method"
,
method
,
"already exists"
if
not
@
defaultTypes
[
type
]
?
@
warn
"Method type"
,
type
,
"doest not exists"
@
[
method
]
=
(
args
...)
=>
@
_log
type
:
type
method
:
method
arguments
:
args
return
@
getPrefix
:
(
options
)
->
prefix
=
""
if
options
.
method
?
prefix
=
"[
#{
@
name
}
->
#{
options
.
method
}
]"
else
prefix
=
"[
#{
@
name
}
]"
details
=
@
_getCallerDetails
()
detailParts
=
[]
if
details
.
package
?
then
detailParts
.
push
details
.
package
if
details
.
file
?
then
detailParts
.
push
details
.
file
if
details
.
line
?
then
detailParts
.
push
details
.
line
if
detailParts
.
length
>
0
prefix
=
"(
#{
detailParts
.
join
(
':'
)
}
)
#{
prefix
}
"
if
@
defaultTypes
[
options
.
type
]
?
return
prefix
[
@
defaultTypes
[
options
.
type
]]
return
prefix
# @returns {Object: { line: Number, file: String }}
_getCallerDetails
:
->
getStack
=
()
->
# We do NOT use Error.prepareStackTrace here (a V8 extension that gets us a
# pre-parsed stack) since it's impossible to compose it with the use of
# Error.prepareStackTrace used on the server for source maps.
err
=
new
Error
stack
=
err
.
stack
return
stack
stack
=
getStack
()
if
not
stack
return
{}
lines
=
stack
.
split
(
'
\n
'
)
# looking for the first line outside the logging package (or an
# eval if we find that first)
line
=
undefined
for
item
,
index
in
lines
when
index
>
0
line
=
item
if
line
.
match
(
/^\s*at eval \(eval/
)
return
{
file
:
"eval"
}
if
not
line
.
match
(
/packages\/rocketchat_logger(?:\/|\.js)/
)
break
details
=
{}
# The format for FF is 'functionName@filePath:lineNumber'
# The format for V8 is 'functionName (packages/logging/logging.js:81)' or
# 'packages/logging/logging.js:81'
match
=
/(?:[@(]| at )([^(]+?):([0-9:]+)(?:\)|$)/
.
exec
(
line
)
if
not
match
return
details
# in case the matched block here is line:column
details
.
line
=
match
[
2
].
split
(
':'
)[
0
]
# Possible format: https://foo.bar.com/scripts/file.js?random=foobar
# XXX: if you can write the following in better way, please do it
# XXX: what about evals?
details
.
file
=
match
[
1
].
split
(
'/'
).
slice
(
-
1
)[
0
].
split
(
'?'
)[
0
]
packageMatch
=
match
[
1
].
match
(
/packages\/([^\.\/]+)(?:\/|\.)/
)
if
packageMatch
?
details
.
package
=
packageMatch
[
1
]
return
details
_log
:
(
options
)
->
options
.
arguments
.
unshift
@
getPrefix
(
options
)
console
.
log
.
apply
console
,
options
.
arguments
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment