Date format in Cacti log
Moderators: Developers, Moderators
Date format in Cacti log
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.
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.
Regards
Bill
Bill
here here
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
becomes
H
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: Select all
/* fill in the current date for printing in the log */
$date = date("m/d/Y h:i:s A");
Code: Select all
$date = date("d/m/Y h:i:s A");
OK, this is a start ...
http://au2.php.net/date for date format options
in functions.php change to
in utilites.php change to
in config_settings.php change
to (watch the comma at the end of the remove_verification section)
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
in functions.php change
Code: Select all
$date = date("m/d/Y h:i:s A");
Code: Select all
$date = date(read_config_option("date_format") . " " . read_config_option("time_format"));
Code: Select all
$timestamp = date("m/d/Y h:i:s A");
Code: Select all
$timestamp = date(read_config_option("date_format") . " " . read_config_option("time_format"));
Code: Select all
"remove_verification" => array(
"friendly_name" => "Remove Verification",
"description" => "Prompt user before item deletion.",
"default" => "on",
"method" => "checkbox"
)
Code: Select all
"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",
)
I set my date to `Ymd` (international format) and time to `H:i:s` (24 hour time)
H
- rony
- Developer/Forum Admin
- Posts: 6022
- Joined: Mon Nov 17, 2003 6:35 pm
- Location: Michigan, USA
- Contact:
We are moving logging to the database and syslog in 0.9.0. So this issue is going away.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
cactid
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
to
util.c. Set the default format in case there are no entries in the .conf file.
change
to
util.c. Read the variables from the config file.
change
to
util.c. Change hard coded entry to use the new format variables.
change
to
cactid.conf
add your format to the file
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: Select all
int php_current_server;
} config_t;
Code: Select all
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;
change
Code: Select all
if ((fp = fopen(file, "rb")) == NULL) {
Code: Select all
//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) {
change
Code: Select all
else if (STRIMATCH(p1, "DB_Port")) set.dbport = atoi(p2);
else {
printf("WARNING: Unrecongized directive: %s=%s in %s\n", p1, p2, file);
Code: Select all
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);
change
Code: Select all
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");
}
Code: Select all
//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");
}
add your format to the file
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.
monitor.php
change
to
Code: Select all
print "<center>Last Refresh : " . date("g:i:s a", time()) . '</center><br>';
Code: Select all
print "<center>Last Refresh : " . date(read_config_option("time_format"), time()) . '</center><br>';
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
looks good enough.
TheWitness
TheWitness
True understanding begins only when we realize how little we truly understand...
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Re: Date format in Cacti log
Is this still the way to do it, or is there a better way ?
- gandalf
- Developer
- Posts: 22383
- Joined: Thu Dec 02, 2004 2:46 am
- Location: Muenster, Germany
- Contact:
Re: Date format in Cacti log
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.
R.
Re: Date format in Cacti log
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...
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...
Re: Date format in Cacti log
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:
me@a.b.c.d:/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.
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:
me@a.b.c.d:/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.
Who is online
Users browsing this forum: No registered users and 0 guests