Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
dCache
cta
Commits
e0620e0a
Commit
e0620e0a
authored
20 years ago
by
Sebastien Ponce
Browse files
Options
Downloads
Patches
Plain Diff
Implemented prefix with timestamp and thread number in the default logstream
parent
c7008dde
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
castor/Imakefile
+2
-1
2 additions, 1 deletion
castor/Imakefile
castor/logbuf.cpp
+54
-0
54 additions, 0 deletions
castor/logbuf.cpp
castor/logbuf.h
+86
-0
86 additions, 0 deletions
castor/logbuf.h
castor/logstream.h
+39
-11
39 additions, 11 deletions
castor/logstream.h
with
181 additions
and
12 deletions
castor/Imakefile
+
2
−
1
View file @
e0620e0a
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.1
0
$ $Release$ $Date: 2004/05/28 0
8:56:54
$ $Author: sponcec3 $
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.1
1
$ $Release$ $Date: 2004/05/28 0
9:40:26
$ $Author: sponcec3 $
#
#
# Make Castor libraries and executables
# Make Castor libraries and executables
#
#
...
@@ -92,6 +92,7 @@ STGLIB_SRCS = IAddressCInt.cpp \
...
@@ -92,6 +92,7 @@ STGLIB_SRCS = IAddressCInt.cpp \
Services.cpp \
Services.cpp \
ServicesCInt.cpp \
ServicesCInt.cpp \
logstream.cpp \
logstream.cpp \
logbuf.cpp \
client/BaseClient.cpp \
client/BaseClient.cpp \
io/Socket.cpp \
io/Socket.cpp \
io/StreamAddress.cpp \
io/StreamAddress.cpp \
...
...
This diff is collapsed.
Click to expand it.
castor/logbuf.cpp
0 → 100644
+
54
−
0
View file @
e0620e0a
/******************************************************************************
* logbuf.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: logbuf.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/28 09:40:26 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include
"castor/logbuf.h"
#include
<time.h>
#include
<sstream>
#include
<iomanip>
#include
<Cthread_api.h>
//-----------------------------------------------------------------------------
// getTimeStamp
//-----------------------------------------------------------------------------
std
::
string
castor
::
logbuf
::
getTimeStamp
()
{
struct
tm
tmstruc
,
*
tm
;
time_t
current_time
;
(
void
)
time
(
&
current_time
);
(
void
)
localtime_r
(
&
current_time
,
&
tmstruc
);
tm
=
&
tmstruc
;
std
::
ostringstream
buf
;
buf
<<
std
::
setw
(
2
)
<<
tm
->
tm_mon
+
1
<<
"/"
<<
tm
->
tm_mday
<<
" "
<<
tm
->
tm_hour
<<
":"
<<
tm
->
tm_min
<<
":"
<<
tm
->
tm_sec
<<
" "
<<
Cthread_self
()
<<
" "
;
return
buf
.
str
();
}
This diff is collapsed.
Click to expand it.
castor/logbuf.h
0 → 100644
+
86
−
0
View file @
e0620e0a
/******************************************************************************
* logbuf.h
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: logbuf.h,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/28 09:40:26 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_LOGBUF_H
#define CASTOR_LOGBUF_H 1
// Include Files
#include
<iostream>
#include
<fstream>
#include
<string>
namespace
castor
{
class
logbuf
:
public
std
::
filebuf
{
public:
/**
* Constructor
*/
logbuf
()
:
std
::
filebuf
(),
m_newline
(
true
)
{}
public
:
/**
* output of n characters in one go
*/
virtual
std
::
streamsize
xsputn
(
const
char
*
__s
,
std
::
streamsize
__n
)
{
if
(
m_newline
)
{
std
::
string
prefix
=
getTimeStamp
();
std
::
filebuf
::
xsputn
(
prefix
.
c_str
(),
prefix
.
size
());
}
m_newline
=
(
__s
[
__n
-
1
]
==
'\n'
);
std
::
filebuf
::
xsputn
(
__s
,
__n
);
}
/**
* set m_newline to true
*/
void
setNewLine
()
{
m_newline
=
true
;
}
private
:
/**
* Build a prefix for logs containing the date, time
* and thread number
*/
std
::
string
getTimeStamp
();
private
:
/**
* remember whether we are at a new line
*/
bool
m_newline
;
};
}
// End of namespace Castor
#endif // CASTOR_LOGBUF_H
This diff is collapsed.
Click to expand it.
castor/logstream.h
+
39
−
11
View file @
e0620e0a
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* @(#)$RCSfile: logstream.h,v $ $Revision: 1.
1.1.1
$ $Release$ $Date: 2004/05/
12 12:13:34
$ $Author: sponcec3 $
* @(#)$RCSfile: logstream.h,v $ $Revision: 1.
2
$ $Release$ $Date: 2004/05/
28 09:40:26
$ $Author: sponcec3 $
*
*
*
*
*
*
...
@@ -29,8 +29,9 @@
...
@@ -29,8 +29,9 @@
// Include Files
// Include Files
#include
<string>
#include
<string>
#include
<
f
stream>
#include
<
o
stream>
#include
"osdep.h"
#include
"osdep.h"
#include
"castor/logbuf.h"
#define OPERATOR(T) \
#define OPERATOR(T) \
logstream& operator<< (T var) { \
logstream& operator<< (T var) { \
...
@@ -47,7 +48,7 @@
...
@@ -47,7 +48,7 @@
m_isIP = false; \
m_isIP = false; \
printIP(var); \
printIP(var); \
} else { \
} else { \
this->std::o
f
stream::operator<<(var); \
this->std::ostream::operator<<(var);
\
} \
} \
} \
} \
return *this; \
return *this; \
...
@@ -56,11 +57,11 @@
...
@@ -56,11 +57,11 @@
#define MANIPULATOR(T) castor::logstream& T(castor::logstream& s);
#define MANIPULATOR(T) castor::logstream& T(castor::logstream& s);
namespace
castor
{
namespace
castor
{
class
logstream
:
virtual
public
std
::
o
f
stream
{
class
logstream
:
virtual
public
std
::
ostream
{
public:
public:
/**
/**
* The different possible level of output
* The different possible level of output
*/
*/
...
@@ -77,14 +78,33 @@ namespace castor {
...
@@ -77,14 +78,33 @@ namespace castor {
}
Level
;
}
Level
;
public
:
public
:
/**
/**
* constructor
* constructor
*/
*/
explicit
logstream
(
const
char
*
p
,
Level
l
=
INFO
)
:
explicit
logstream
(
const
char
*
p
,
Level
l
=
INFO
)
:
std
::
ofstream
(
p
,
std
::
ios
::
app
),
m_minLevel
(
l
),
std
::
ostream
(
0
),
m_curLevel
(
INFO
),
m_isIP
(
false
)
{
m_logbuf
(),
printf
(
"logstream name : %s
\n
"
,
p
);
m_minLevel
(
l
),
m_curLevel
(
INFO
),
m_isIP
(
false
)
{
// Deal with the buffer
this
->
init
(
&
m_logbuf
);
if
(
!
m_logbuf
.
open
(
p
,
std
::
ios
::
app
|
std
::
ios_base
::
out
))
{
this
->
setstate
(
ios_base
::
failbit
);
}
}
/**
* @brief Close the file.
*
* Calls @c std::basic_filebuf::close(). If that function
* fails, @c failbit is set in the stream's error state.
*/
void
close
()
{
if
(
!
m_logbuf
.
close
())
{
this
->
setstate
(
ios_base
::
failbit
);
}
}
}
public
:
public
:
...
@@ -120,6 +140,8 @@ namespace castor {
...
@@ -120,6 +140,8 @@ namespace castor {
* castor::logstream
* castor::logstream
*/
*/
logstream
&
operator
<<
(
std
::
ostream
&
(
&
f
)(
std
::
ostream
&
))
{
logstream
&
operator
<<
(
std
::
ostream
&
(
&
f
)(
std
::
ostream
&
))
{
if
(
&
f
==
(
std
::
ostream
&
(
&
)(
std
::
ostream
&
))
std
::
endl
)
m_logbuf
.
setNewLine
();
f
(
*
this
);
f
(
*
this
);
return
*
this
;
return
*
this
;
}
}
...
@@ -149,6 +171,12 @@ namespace castor {
...
@@ -149,6 +171,12 @@ namespace castor {
private
:
private
:
/**
* The log buffer used on top of the file buffer for
* prefixing the logs with timestamps
*/
castor
::
logbuf
m_logbuf
;
/**
/**
* The current minimum level of output for the stream
* The current minimum level of output for the stream
* everything under it will not be output
* everything under it will not be output
...
...
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