Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Thu Jun 29, 2017 9:24 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Date format in Cacti log
PostPosted: Tue Sep 07, 2004 5:35 am 
Offline

Joined: Thu Aug 19, 2004 3:18 pm
Posts: 27
Hi

Is there any chance we could have an option to change the date format in the cacti logfile? Not a major priority but it would be nice for us Europeans. :D

_________________
Regards


Bill


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 6:40 am 
Offline
Cacti User

Joined: Tue Nov 11, 2003 10:57 am
Posts: 195
Location: Luxembourg
I second that. As far as I know the U.S. is the only country to use that particular format. Every other country that I've been to uses day month year. Actually, even the U.S. Military uses the day month year format, though they like to string it all together into one big number.


Mike


Top
 Profile  
 
 Post subject: here here
PostPosted: Thu Oct 19, 2006 12:22 am 
Offline
Cacti User

Joined: Mon Oct 16, 2006 11:50 pm
Posts: 56
I'll third this request. I was actually looking to see if someone had requested it already, and they had !!!

this is not a great fix, but it will do until i can find out the command to get the date environment from the o/s, or setup a proper config entry in the database where you can specify you own format.

functions.php
Code:
   /* fill in the current date for printing in the log */
   $date = date("m/d/Y h:i:s A");


becomes

Code:
$date = date("d/m/Y h:i:s A");

H


Top
 Profile  
 
 Post subject: OK, this is a start ...
PostPosted: Thu Oct 19, 2006 1:04 am 
Offline
Cacti User

Joined: Mon Oct 16, 2006 11:50 pm
Posts: 56
http://au2.php.net/date for date format options

in functions.php change
Code:
$date = date("m/d/Y h:i:s A");
to
Code:
$date = date(read_config_option("date_format") . " " . read_config_option("time_format"));


in utilites.php change
Code:
$timestamp = date("m/d/Y h:i:s A");
to
Code:
$timestamp = date(read_config_option("date_format") . " " . read_config_option("time_format"));


in config_settings.php change

Code:
      "remove_verification" => array(
         "friendly_name" => "Remove Verification",
         "description" => "Prompt user before item deletion.",
         "default" => "on",
         "method" => "checkbox"
         )

to (watch the comma at the end of the remove_verification section)
Code:
      "remove_verification" => array(
         "friendly_name" => "Remove Verification",
         "description" => "Prompt user before item deletion.",
         "default" => "on",
         "method" => "checkbox"
         ),
      "date_format" => array(
         "friendly_name" => "Date Format",
         "description" => "Default format for some things, like the log.",
         "method" => "textbox",
         "default" => "m/d/Y",
         "max_length" => "100",
         ),
      "time_format" => array(
         "friendly_name" => "Time Format",
         "description" => "Default format for some things, like the log.",
         "method" => "textbox",
         "default" => "h:i:s A",
         "max_length" => "100",
         )

this is not all of them, but it is a start.

I set my date to `Ymd` (international format) and time to `H:i:s` (24 hour time)

H


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 9:08 am 
Offline
Developer/Forum Admin
User avatar

Joined: Mon Nov 17, 2003 6:35 pm
Posts: 5948
Location: Michigan, USA
We are moving logging to the database and syslog in 0.9.0. So this issue is going away.

_________________
Tony Roman
Experience is what causes a person to make new mistakes instead of old ones.
There are only 3 way to complete a project: Good, Fast or Cheap, pick two.
With age comes wisdom, what you choose to do with it determines whether or not you are wise.


Top
 Profile  
 
 Post subject: cactid
PostPosted: Thu Oct 19, 2006 6:40 pm 
Offline
Cacti User

Joined: Mon Oct 16, 2006 11:50 pm
Posts: 56
Tony, thanks. I've spent the last few hours learning C, so i'll post what i've done anyway.

Cactid use's a different date and time format string (to php's) so putting it in the .conf file is more logical than putting another entry in the main system. I didn't twig to this obvious bit of info at first, so i wrote it to use the DB's format entries first. surprising it didn't work.

anyway here it is. this was done on cactid 0.8.6, put it should work on most of the other versions (it's why i didn't supply a diff/patch file).


cactid.h. Add formats to configure structure.
change
Code:
   int php_current_server;
} config_t;

to
Code:
   int php_current_server;
   char date_format[100]; //matches the definition in config_settings.php
   char time_format[100]; //matches the definition in config_settings.php
} config_t;


util.c. Set the default format in case there are no entries in the .conf file.
change
Code:
if ((fp = fopen(file, "rb")) == NULL) {

to
Code:
  //set time defaults. Can't use any printf function here as it contains at least one '%'
   strncpy(set.date_format, "%m/%d/%Y", sizeof(set.date_format)-1);
   strncpy(set.time_format, "%I:%M:%S %p", sizeof(set.time_format)-1);

   if ((fp = fopen(file, "rb")) == NULL) {


util.c. Read the variables from the config file.
change
Code:
            else if (STRIMATCH(p1, "DB_Port")) set.dbport = atoi(p2);
            else {
               printf("WARNING: Unrecongized directive: %s=%s in %s\n", p1, p2, file);

to
Code:
            else if (STRIMATCH(p1, "DB_Port")) set.dbport = atoi(p2);
              //can't use any printf function here as it contains at least one '%'
            else if (STRIMATCH(p1, "date_format")) strncpy(set.date_format, p2, sizeof(set.date_format)-1);
              //can't use any printf function here as it contains at least one '%'
            else if (STRIMATCH(p1, "time_format")) strncpy(set.time_format, p2, sizeof(set.time_format)-1);
            else {
               printf("WARNING: Unrecognized directive: %s=%s in %s\n", p1, p2, file);


util.c. Change hard coded entry to use the new format variables.
change
Code:
   if (strftime(flogmessage, 50, "%m/%d/%Y %I:%M:%S %p - ", now_ptr) == (size_t) 0) { */
      fprintf(stderr, "ERROR: Could not get string from strftime()\n");
   }

to
Code:
     //can't use any printf function here as it contains at least one '%'
   strncpy(datetime_format, set.date_format, sizeof(datetime_format)-1);
   strncat(datetime_format, " ", 1);
   strncat(datetime_format, set.time_format, strlen(set.time_format));
   strncat(datetime_format, " - ", 3);

   CACTID_LOG_DEBUG(("DEBUG: The datetime_format is %s\n", datetime_format));

   if (strftime(flogmessage, 50, datetime_format, now_ptr) == (size_t) 0) {
      fprintf(stderr, "ERROR: Could not get string from strftime()\n");
   }


cactid.conf
add your format to the file
Quote:
date_format %Y%m%d
time_format %H:%M:%S


Last edited by Hiney on Thu Oct 19, 2006 11:53 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: monitor.php
PostPosted: Thu Oct 19, 2006 6:41 pm 
Offline
Cacti User

Joined: Mon Oct 16, 2006 11:50 pm
Posts: 56
change
Code:
print "<center>Last Refresh : " . date("g:i:s a", time()) . '</center><br>';
to
Code:
print "<center>Last Refresh : " . date(read_config_option("time_format"), time()) . '</center><br>';


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 10:04 pm 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14863
Location: MI, USA
looks good enough.

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Date format in Cacti log
PostPosted: Sat Apr 06, 2013 5:14 pm 
Offline

Joined: Tue Nov 22, 2011 11:04 am
Posts: 29
Is this still the way to do it, or is there a better way ?


Top
 Profile  
 
 Post subject: Re: Date format in Cacti log
PostPosted: Sat Apr 27, 2013 4:24 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
You've hit a quite old thread. To be honest, I don't know the current status. To get things moving, please (again) phrase what you really need and what stilll is missing
R.

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Date format in Cacti log
PostPosted: Thu Jun 26, 2014 10:25 am 
Offline

Joined: Fri Aug 31, 2012 5:36 pm
Posts: 9
And still no movement...
So currently it's impossible to configure the date format and on top of that it's US style.
Option for date format in the console setting would be much appreciated...


Top
 Profile  
 
 Post subject: Re: Date format in Cacti log
PostPosted: Thu May 21, 2015 12:02 am 
Offline

Joined: Mon Apr 13, 2015 5:53 pm
Posts: 43
Really old post as 0.9 was talked about in 2006 and while we did move to a database, syslog never happened (yet). Anyways since a couple other folk have commented over the years looking for a solution and I just stumbled across this myself wondering the same thing (as I wanted 24 hour clock) the answer is:

1: Open lib/functions.php
2: Find the $date line, copy it, and comment out the old one.
3: Modify the new uncommented $date line to suit your taste using appropriate PHP date() parameters ( https://php.net/manual/en/function.date.php )
4: Win?

Example:

[email protected]:/usr/local/share/cacti/lib # diff -ruN functions.php.orig functions.php
--- functions.php.orig 2015-05-20 18:55:42.126062957 -1000
+++ functions.php 2015-05-20 18:49:13.880731397 -1000
@@ -479,7 +479,8 @@
global $config;

/* fill in the current date for printing in the log */
- $date = date("m/d/Y h:i:s A");
+/* $date = date("m/d/Y h:i:s A"); */
+ $date = date("dMy H:i:s");


Yes that is the exact same thing Hiney said but follow up commentors seemed to have missed it; it's a one line three second fix once you know where to look.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group