Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-10-16 08:01:29


Author: jtorjo
Date: 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
New Revision: 40081
URL: http://svn.boost.org/trac/boost/changeset/40081

Log:
[logging]
added some formatters and destinations - not tested yet
Added:
   sandbox/logging/boost/logging/format/destination/convert_destination.hpp (contents, props changed)
   sandbox/logging/boost/logging/format/destination/rolling_file.hpp (contents, props changed)
Properties modified:
   sandbox/logging/lib/logging/samples/gcc/ (props changed)
Text files modified:
   sandbox/logging/boost/logging/format/destination/defaults.hpp | 34 +++++++++++++++++++-
   sandbox/logging/boost/logging/format/destination/file.hpp | 67 ++++++++++++++++++++++++++++++++++++++++
   sandbox/logging/boost/logging/format/formatter/convert_format.hpp | 8 ++--
   sandbox/logging/boost/logging/writer/ts_write.hpp | 6 +-
   sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj | 8 ++++
   5 files changed, 114 insertions(+), 9 deletions(-)

Added: sandbox/logging/boost/logging/format/destination/convert_destination.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/destination/convert_destination.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -0,0 +1,66 @@
+// Template.hpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#ifndef JT28092007_TEMPLATE_HPP_DEFINED
+#define JT28092007_TEMPLATE_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+
+namespace boost { namespace logging { namespace destination {
+
+template<class t> struct into {};
+
+/**
+@brief Allows writing messages to destinations
+
+It has 2 function overloads:
+- write(message, output) - writes the given message, to the given output
+- do_convert(message, into<other_type>() );
+
+FIXME
+*/
+namespace convert {
+ template<class obj, class char_traits, class char_type> void write(const obj & m, std::basic_iostream<char_type, char_traits> & out) {
+ out << m;
+ }
+
+ template<class char_traits, class char_type> void write(const char_type* m, std::basic_iostream<char_type, char_traits> & out) {
+ out << m;
+ }
+
+ inline const char_type * do_convert(const char_type * c, const into<const char_type*> &) { return c; }
+ inline const char_type * do_convert(const std::basic_string<char_type> & s, const into<const char_type* > &) { return s.c_str(); }
+}
+
+struct do_convert_destination {
+ template<class msg, class dest> void write(const msg & m, dest & d) {
+ convert::write(msg, dest);
+ }
+
+ template<class msg, class dest> dest do_convert(const msg & m, const into<dest> &) {
+ convert::do_convert(msg, into<dest>() );
+ }
+
+};
+
+}}}
+
+#endif
+

Modified: sandbox/logging/boost/logging/format/destination/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/destination/defaults.hpp (original)
+++ sandbox/logging/boost/logging/format/destination/defaults.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -22,14 +22,44 @@
 #endif
 
 #include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/destination/convert_destination.hpp>
+#include <boost/logging/format/destination/file.hpp>
+#include <iostream>
 
 namespace boost { namespace logging { namespace destination {
 
-// console, file, debug window
+
+/**
+ @brief Writes the string to console
+*/
+template<class convert_dest = do_convert_destination > struct cout {
+ template<class msg_type> void operator()(const msg_type & msg) const {
+#ifndef UNICODE
+ convert_dest::write(msg, std::cout);
+#else
+ convert_dest::write(msg, std::wcout);
+#endif
+ }
+};
+
+
+template<class convert_dest = do_convert_destination > struct dbg_window {
+ template<class msg_type> void operator()(const msg_type & msg) const {
+#ifdef BOOST_WINDOWS
+#ifndef UNICODE
+ ::OutputDebugWindowA( convert_dest::do_convert(msg, into<const char*>() ) );
+#else
+ ::OutputDebugWindowW( convert_dest::do_convert(msg, into<const wchar_t*>() ) );
+#endif
+#endif
+ }
+};
+
 
 
 
-rolling files/sharing memory
+sharing memory
 
 }}}
 

Modified: sandbox/logging/boost/logging/format/destination/file.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/destination/file.hpp (original)
+++ sandbox/logging/boost/logging/format/destination/file.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -22,9 +22,76 @@
 #endif
 
 #include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/destination/convert_destination.hpp>
+#include <fstream>
 
 namespace boost { namespace logging { namespace destination {
 
+/**
+ @brief settings for when constructing a file class
+*/
+struct file_settings {
+ file_settings() : m_flush_each_time(true), m_initial_overwrite(false), m_do_append(true) {}
+
+ file_settings & flush_each_time() { m_flush_each_time = true; return *this; }
+ file_settings & initial_overwrite() { m_initial_overwrite = true; return *this; }
+ file_settings & no_append() { m_do_append = false; return *this; }
+
+ file_settings & no_flush_each_time() { m_flush_each_time = false; return *this; }
+ file_settings & no_initial_overwrite() { m_initial_overwrite = false; return *this; }
+ file_settings & append() { m_do_append = true; return *this; }
+
+ file_settings & extra_open_flags(std::ios_base::open_mode extra_flags) { m_extra_flags = extra_flags; return *this; }
+
+ /// if true (default), flushes after each write
+ bool m_flush_each_time;
+ // if true it initially overwrites the file; default = false
+ bool m_initial_overwrite;
+ // if true (default), opens the file for appending
+ bool m_do_append;
+
+ /// just in case you have some extra flags to pass, when opening the file
+ std::ios_base::open_mode m_extra_flags;
+};
+
+namespace detail {
+ std::ios_base::open_mode open_flags(file_settings fs) {
+ std::ios_base::open_mode flags = std::ios_base::out | fs.m_extra_flags ;
+ if ( m_do_append)
+ flags |= std::ios_base::app;
+ if ( !m_initial_overwrite)
+ flags |= std::ios_base::in;
+
+ return flags;
+ }
+
+ struct file_info {
+ file_info(const char_type * name, file_settings settings) : out(name, open_flags(settings) ), settings(settings) {}
+ std::basic_ofstream<char_type> out;
+ file_settings settings;
+ }
+}
+
+/**
+ @brief Writes the string to a file
+*/
+template<class convert_dest = do_convert_destination > struct file : non_const_context<detail::file_info> {
+ /**
+ @brief constructs the file destination
+
+ @param file_name name of the file
+ @param set [optional] file settings - see file_settings class
+ */
+ file(const std::string & file_name, file_settings set = file_settings() ) : non_const_context_base(file_name) {}
+ template<class msg_type> void operator()(const msg_type & msg) const {
+ convert_dest::write(msg, non_const_context_base::context() );
+ }
+};
+
+
+
+
 
 
 }}}

Added: sandbox/logging/boost/logging/format/destination/rolling_file.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/destination/rolling_file.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -0,0 +1,50 @@
+// destination_rolling_file.hpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#ifndef JT28092007_destination_rolling_file_HPP_DEFINED
+#define JT28092007_destination_rolling_file_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/destination/convert_destination.hpp>
+#include <fstream>
+#include <string>
+
+namespace boost { namespace logging { namespace destination {
+
+namespace detail {
+ struct rolling_file_info {
+ rolling_file_info (const std::string& name_prefix, file_settings settings) : out(name, open_flags(settings) ), settings(settings) {}
+ std::basic_ofstream<char_type> out;
+ file_settings settings;
+ }
+}
+
+template<class convert_dest = do_convert_destination > struct rolling_file : non_const_context<detail::file_info> {
+};
+
+
+
+
+
+}}}
+
+#endif
+

Modified: sandbox/logging/boost/logging/format/formatter/convert_format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/convert_format.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/convert_format.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -42,7 +42,7 @@
     so that you can "inject" your own write function in the convert_format::prepend/orwhatever namespace, and
     then it'll be automatically used!
 */
-namespace convert_format {
+namespace convert {
     typedef boost::logging::char_type char_type;
     typedef std::basic_string<char_type> string_type;
 
@@ -86,19 +86,19 @@
 struct do_convert_format {
     struct prepend {
         template<class string> void write(const string_type & src, string & dest) {
- convert_format::prepend::write(src, dest);
+ convert::prepend::write(src, dest);
         }
     };
 
     struct append {
         template<class string> void write(const string_type & src, string & dest) {
- convert_format::append::write(src, dest);
+ convert::append::write(src, dest);
         }
     };
 
     struct modify {
         template<class string> void write(const string_type & src, string & dest) {
- convert_format::modify::write(src, dest);
+ convert::modify::write(src, dest);
         }
     };
 };

Modified: sandbox/logging/boost/logging/writer/ts_write.hpp
==============================================================================
--- sandbox/logging/boost/logging/writer/ts_write.hpp (original)
+++ sandbox/logging/boost/logging/writer/ts_write.hpp 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -28,7 +28,7 @@
 
     namespace detail {
         struct ts_write_context {
- boost::logging::threading::mutex cs;
+ mutable boost::logging::threading::mutex cs;
         };
     }
 
@@ -70,9 +70,9 @@
 @sa on_dedicated_thread
 */
     template<class base_type> struct ts_write : base_type {
- BOOST_LOOGING_FORWARD_CONSTRUCTOR(ts_write,base_type)
+ BOOST_LOGGING_FORWARD_CONSTRUCTOR(ts_write,base_type)
 
- template<class msg_type> void operator()(msg_type msg) {
+ template<class msg_type> void operator()(msg_type msg) const {
             typedef boost::logging::threading::mutex::scoped_lock lock;
             lock lk(context().cs);
 

Modified: sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj
==============================================================================
--- sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj (original)
+++ sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj 2007-10-16 08:01:28 EDT (Tue, 16 Oct 2007)
@@ -647,6 +647,10 @@
                                         Name="destination"
>
                                         <File
+ RelativePath="..\..\..\..\..\boost\logging\format\destination\convert_destination.hpp"
+ >
+ </File>
+ <File
                                                 RelativePath="..\..\..\..\..\boost\logging\format\destination\defaults.hpp"
>
                                         </File>
@@ -654,6 +658,10 @@
                                                 RelativePath="..\..\..\..\..\boost\logging\format\destination\file.hpp"
>
                                         </File>
+ <File
+ RelativePath="..\..\..\..\..\boost\logging\format\destination\rolling_file.hpp"
+ >
+ </File>
                                 </Filter>
                         </Filter>
                         <Filter


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk