Wtx ~ Wt Extension Library
WtxLib
Log.cpp
1 
2 #include <iostream>
3 #include <fstream>
4 
5 #include <Wt/WApplication.h>
6 #include <Wt/WEnvironment.h>
7 
8 #include "Log.h"
9 
10 Wtx::Sys::Log::Item::Ptr Wtx::Sys::Log::add( const std::string & key, const std::string & cfy, bool sendEmail, Wtx::Dbo::Session & session )
11 {
12  Wt::Dbo::Transaction t( session );
13 
14  auto retVal =
15  session.addNew<Wtx::Sys::Log::Item>( key );
16 
17  retVal.modify()-> cfyField().setValue( cfy );
18 
19  auto value =
20  Wt::WString
21  (
22  "----------------------------------------------\n"
23  "{1}\n"
24  "key:{2}\n"
25  "cfy:{3}\n"
26  "clip:{4}"
27  )
28  .arg( Wt::WDateTime::currentDateTime().toString() )
29  .arg( key )
30  .arg( cfy )
31  .arg( wApp-> instance()-> environment().headerValue("X-Forwarded-For") )
32  .toUTF8()
33  ;
34 
35  std::cout << __FILE__ << ":" << __LINE__
36  << "\n" << value
37  << "\n----------------------------------------------"
38  << std::endl;
39 
40  if( sendEmail )
41  {
42  }
43 
44  auto fileName =
45  Wt::WString("sysLog-{1}.txt")
46  .arg( Wt::WDateTime::currentDateTime().toString("yyyyMMdd") )
47  .toUTF8()
48  ;
49 
50  std::ofstream myfile;
51  myfile.open( fileName.c_str(), std::ios::out | std::ios::app );
52  myfile << value << "\n";
53  myfile.close();
54 
55 
56  return retVal;
57 
58 } // endWt::Dbo::ptr< Wtx::Sys::Log::Item > Wtx::Sys::Log::add( const std::string & key, const std::string & cfy, bool sendEmail, Wtx::Dbo::Session & session )
59 
60 Wtx::Sys::Log::Item::Ptr Wtx::Sys::Log::add( const std::string & key, const std::string & cfy, Wtx::Dbo::Session & session )
61 {
62  return add( key, cfy, false, session );
63 }
64 
Wtx::Sys::Log::Item::Ptr add(const std::string &key, const std::string &cfy, Wtx::Dbo::Session &session)
Add an item by key/cfy.
Definition: Log.cpp:60